Skip to content

Commit

Permalink
Applied patches from Martijn van Oosterhout:
Browse files Browse the repository at this point in the history
1. The first allows the user to add a <FileSource
name="foo">/home/bar/baz/</FileSource> to the beginning of the file
and then in any of the symbolisers you can say:

<FooSymboliser base="foo" name="bridge">
It it will refer to the file /home/bar/baz/bridge.

2. The second allows you to create Datasource templates at the top
level, which can be used later in the actual layers like so:
<Map>
  <Datasource name="db">
   <Paramaeter name="host">/tmp</Parameter>
  </Datasource>
  <Layer name="lay">
    <Datasource base="db">
      <Parameter name="table">points</Parameter>
    </Datasource>
  </Layer>
</Map>

And the host parameter will be used in the layer.

3. The third adds the "base" parameter to the raster and shape input
plugins. All it does is specify a path to prefix to the filename prior
to using it. Together with the above feature it allows things like:
<Map>
  <Datasource name="shapes">
   <Paramaeter name="base">/home/foo/shapes</Parameter>
  </Datasource>
  <Layer name="lay">
    <Datasource base="shapes">
      <Parameter name="file">places</Parameter>
    </Datasource>
  </Layer>
</Map>

And it will use the shapefile /home/foo/shapes/places
  • Loading branch information
artemp committed Dec 17, 2007
1 parent 002f37b commit 37f49e2
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 22 deletions.
6 changes: 5 additions & 1 deletion plugins/input/raster/raster_datasource.cpp
Expand Up @@ -51,8 +51,12 @@ raster_datasource::raster_datasource(const parameters& params)
{

boost::optional<std::string> file=params.get<std::string>("file");
boost::optional<std::string> base=params.get<std::string>("base");
if (!file) throw datasource_exception("missing <file> parameter ");
filename_ = *file;
if (base)
filename_ = *base + "/" + *file;
else
filename_ = *file;
format_=*params.get<std::string>("format","tiff");
boost::optional<double> lox = params.get<double>("lox");
boost::optional<double> loy = params.get<double>("loy");
Expand Down
6 changes: 5 additions & 1 deletion plugins/input/shape/shape.cpp
Expand Up @@ -41,11 +41,15 @@ using mapnik::attribute_descriptor;
shape_datasource::shape_datasource(const parameters &params)
: datasource (params),
type_(datasource::Vector),
shape_name_(*params_.get<std::string>("file","")),
file_length_(0),
indexed_(false),
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8"))
{
boost::optional<std::string> base = params.get<std::string>("base");
if (base)
shape_name_ = *base + "/" + *params_.get<std::string>("file","");
else
shape_name_ = *params_.get<std::string>("file","");
try
{
shape_io shape(shape_name_);
Expand Down
118 changes: 98 additions & 20 deletions src/load_map.cpp
Expand Up @@ -82,8 +82,10 @@ namespace mapnik
void ensure_font_face( const text_symbolizer & text_symbol );

bool strict_;
std::map<std::string,parameters> datasource_templates_;
freetype_engine font_engine_;
face_manager<freetype_engine> font_manager_;
std::map<std::string,std::string> file_sources_;
};

void load_map(Map & map, std::string const& filename, bool strict)
Expand Down Expand Up @@ -143,6 +145,38 @@ namespace mapnik

parse_layer(map, v.second );
}
else if (v.first == "FileSource")
{
std::string name = get_attr<string>( v.second, "name");
std::string value = get_own<string>( 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<string>(param, "name");
std::string value = get_own<string>( param,
"datasource parameter");
params[name] = value;
}
else if( paramIter->first != "<xmlattr>" )
{
throw config_error(std::string("Unknown child node in ") +
"'Datasource'. Expected 'Parameter' but got '" +
paramIter->first + "'");
}
}
datasource_templates_[name] = params;
}
else if (v.first != "<xmlcomment>" &&
v.first != "<xmlattr>")
{
Expand Down Expand Up @@ -233,6 +267,14 @@ namespace mapnik
else if (child.first == "Datasource")
{
parameters params;
optional<std::string> base = get_opt_attr<std::string>( child.second, "base" );
if( base )
{
std::map<std::string,parameters>::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)
Expand All @@ -246,7 +288,7 @@ namespace mapnik
"datasource parameter");
params[name] = value;
}
else
else if( paramIter->first != "<xmlattr>" )
{
throw config_error(std::string("Unknown child node in ") +
"'Datasource'. Expected 'Parameter' but got '" +
Expand Down Expand Up @@ -400,6 +442,7 @@ namespace mapnik
try
{
optional<std::string> file = get_opt_attr<string>(sym, "file");
optional<std::string> base = get_opt_attr<string>(sym, "base");
optional<std::string> type = get_opt_attr<string>(sym, "type");
optional<boolean> allow_overlap =
get_opt_attr<boolean>(sym, "allow_overlap");
Expand All @@ -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<std::string,std::string>::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 )
{
Expand Down Expand Up @@ -460,13 +511,22 @@ namespace mapnik
try
{
std::string file = get_attr<string>(sym, "file");
optional<std::string> base = get_opt_attr<string>(sym, "base");
std::string type = get_attr<string>(sym, "type");
unsigned width = get_attr<unsigned>(sym, "width");
unsigned height = get_attr<unsigned>(sym, "height");

try
{
rule.append(line_pattern_symbolizer(file,type,width,height));
if( base )
{
std::map<std::string,std::string>::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 )
{
Expand Down Expand Up @@ -495,12 +555,21 @@ namespace mapnik
try
{
std::string file = get_attr<string>(sym, "file");
optional<std::string> base = get_opt_attr<string>(sym, "base");
std::string type = get_attr<string>(sym, "type");
unsigned width = get_attr<unsigned>(sym, "width");
unsigned height = get_attr<unsigned>(sym, "height");

try
{
if( base )
{
std::map<std::string,std::string>::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 )
Expand Down Expand Up @@ -631,15 +700,24 @@ namespace mapnik
Color fill = get_attr(sym, "fill", Color(0,0,0));

std::string image_file = get_attr<string>(sym, "file");
optional<std::string> base = get_opt_attr<string>(sym, "base");
std::string type = get_attr<string>(sym, "type");
unsigned width = get_attr<unsigned>(sym, "width");
unsigned height = get_attr<unsigned>(sym, "height");

try
{
if( base )
{
std::map<std::string,std::string>::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<unsigned> min_distance =
get_opt_attr<unsigned>(sym, "min_distance");
Expand All @@ -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)
{
Expand Down

0 comments on commit 37f49e2

Please sign in to comment.