diff --git a/plugins/input/raster/raster_datasource.cpp b/plugins/input/raster/raster_datasource.cpp index a5fb079e5..48036830d 100644 --- a/plugins/input/raster/raster_datasource.cpp +++ b/plugins/input/raster/raster_datasource.cpp @@ -51,8 +51,12 @@ raster_datasource::raster_datasource(const parameters& params) { boost::optional file=params.get("file"); + boost::optional base=params.get("base"); if (!file) throw datasource_exception("missing parameter "); - filename_ = *file; + if (base) + filename_ = *base + "/" + *file; + else + filename_ = *file; format_=*params.get("format","tiff"); boost::optional lox = params.get("lox"); boost::optional loy = params.get("loy"); diff --git a/plugins/input/shape/shape.cpp b/plugins/input/shape/shape.cpp index 295da9821..ff218b568 100644 --- a/plugins/input/shape/shape.cpp +++ b/plugins/input/shape/shape.cpp @@ -41,11 +41,15 @@ using mapnik::attribute_descriptor; shape_datasource::shape_datasource(const parameters ¶ms) : datasource (params), type_(datasource::Vector), - shape_name_(*params_.get("file","")), file_length_(0), indexed_(false), desc_(*params.get("type"), *params.get("encoding","utf-8")) { + boost::optional base = params.get("base"); + if (base) + shape_name_ = *base + "/" + *params_.get("file",""); + else + shape_name_ = *params_.get("file",""); try { shape_io shape(shape_name_); diff --git a/src/load_map.cpp b/src/load_map.cpp index 3b8f049db..161248911 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -82,8 +82,10 @@ namespace mapnik void ensure_font_face( const text_symbolizer & text_symbol ); bool strict_; + std::map datasource_templates_; freetype_engine font_engine_; face_manager font_manager_; + std::map file_sources_; }; void load_map(Map & map, std::string const& filename, bool strict) @@ -143,6 +145,38 @@ namespace mapnik parse_layer(map, v.second ); } + else if (v.first == "FileSource") + { + std::string name = get_attr( v.second, "name"); + std::string value = get_own( v.second, ""); + file_sources_[name] = value; + } + else if (v.first == "Datasource") + { + std::string name = get_attr(v.second, "name", string("Unnamed")); + parameters params; + ptree::const_iterator paramIter = v.second.begin(); + ptree::const_iterator endParam = v.second.end(); + for (; paramIter != endParam; ++paramIter) + { + ptree const& param = paramIter->second; + + if (paramIter->first == "Parameter") + { + std::string name = get_attr(param, "name"); + std::string value = get_own( param, + "datasource parameter"); + params[name] = value; + } + else if( paramIter->first != "" ) + { + throw config_error(std::string("Unknown child node in ") + + "'Datasource'. Expected 'Parameter' but got '" + + paramIter->first + "'"); + } + } + datasource_templates_[name] = params; + } else if (v.first != "" && v.first != "") { @@ -233,6 +267,14 @@ namespace mapnik else if (child.first == "Datasource") { parameters params; + optional base = get_opt_attr( child.second, "base" ); + if( base ) + { + std::map::const_iterator base_itr = datasource_templates_.find(*base); + if (base_itr!=datasource_templates_.end()) + params = base_itr->second; + } + ptree::const_iterator paramIter = child.second.begin(); ptree::const_iterator endParam = child.second.end(); for (; paramIter != endParam; ++paramIter) @@ -246,7 +288,7 @@ namespace mapnik "datasource parameter"); params[name] = value; } - else + else if( paramIter->first != "" ) { throw config_error(std::string("Unknown child node in ") + "'Datasource'. Expected 'Parameter' but got '" + @@ -400,6 +442,7 @@ namespace mapnik try { optional file = get_opt_attr(sym, "file"); + optional base = get_opt_attr(sym, "base"); optional type = get_opt_attr(sym, "type"); optional allow_overlap = get_opt_attr(sym, "allow_overlap"); @@ -411,12 +454,20 @@ namespace mapnik { try { - point_symbolizer symbol(*file,*type,*width,*height); - if (allow_overlap) - { - symbol.set_allow_overlap( * allow_overlap ); - } - rule.append(symbol); + if( base ) + { + std::map::const_iterator itr = file_sources_.find(*base); + if (itr!=file_sources_.end()) + { + *file = itr->second + "/" + *file; + } + } + point_symbolizer symbol(*file,*type,*width,*height); + if (allow_overlap) + { + symbol.set_allow_overlap( * allow_overlap ); + } + rule.append(symbol); } catch (ImageReaderException const & ex ) { @@ -460,13 +511,22 @@ namespace mapnik try { std::string file = get_attr(sym, "file"); + optional base = get_opt_attr(sym, "base"); std::string type = get_attr(sym, "type"); unsigned width = get_attr(sym, "width"); unsigned height = get_attr(sym, "height"); try { - rule.append(line_pattern_symbolizer(file,type,width,height)); + if( base ) + { + std::map::const_iterator itr = file_sources_.find(*base); + if (itr!=file_sources_.end()) + { + file = itr->second + "/" + file; + } + } + rule.append(line_pattern_symbolizer(file,type,width,height)); } catch (ImageReaderException const & ex ) { @@ -495,12 +555,21 @@ namespace mapnik try { std::string file = get_attr(sym, "file"); + optional base = get_opt_attr(sym, "base"); std::string type = get_attr(sym, "type"); unsigned width = get_attr(sym, "width"); unsigned height = get_attr(sym, "height"); try { + if( base ) + { + std::map::iterator itr = file_sources_.find(*base); + if (itr!=file_sources_.end()) + { + file = itr->second + "/" + file; + } + } rule.append(polygon_pattern_symbolizer(file,type,width,height)); } catch (ImageReaderException const & ex ) @@ -631,15 +700,24 @@ namespace mapnik Color fill = get_attr(sym, "fill", Color(0,0,0)); std::string image_file = get_attr(sym, "file"); + optional base = get_opt_attr(sym, "base"); std::string type = get_attr(sym, "type"); unsigned width = get_attr(sym, "width"); unsigned height = get_attr(sym, "height"); try { + if( base ) + { + std::map::const_iterator itr = file_sources_.find(*base); + if (itr!=file_sources_.end()) + { + image_file = itr->second + "/" + image_file; + } + } shield_symbolizer shield_symbol(name,face_name,size,fill, - image_file,type,width,height); - + image_file,type,width,height); + // minimum distance between labels optional min_distance = get_opt_attr(sym, "min_distance"); @@ -651,18 +729,18 @@ namespace mapnik } catch (ImageReaderException const & ex ) { - string msg("Failed to load image file '" + image_file + + string msg("Failed to load image file '" + image_file + "': " + ex.what()); - if (strict_) - { - throw config_error(msg); - } - else - { - clog << "### WARNING: " << msg << endl; - } + if (strict_) + { + throw config_error(msg); + } + else + { + clog << "### WARNING: " << msg << endl; + } } - + } catch (const config_error & ex) {