avoid muffling proj_init at render time and instead catch at load_map - closes #646

This commit is contained in:
Dane Springmeyer 2013-05-29 15:16:44 -07:00
parent 97fe52ac04
commit b0f15bf5de
5 changed files with 63 additions and 50 deletions

View file

@ -32,6 +32,10 @@ Summary: The 2.2.0 release is the fastest running and most stable release in the
- Fixed blurry rendering of image and SVG icons (#1316) - Fixed blurry rendering of image and SVG icons (#1316)
- Added detection of invalid srs values when loading xml (#646)
- Removed muffling of projection errors while rendering (#646)
- Improved logging system (https://github.com/mapnik/mapnik/wiki/Logging) - Improved logging system (https://github.com/mapnik/mapnik/wiki/Logging)
- Added support for reading images from in memory streams (#1805) - Added support for reading images from in memory streams (#1805)

View file

@ -160,36 +160,29 @@ void feature_style_processor<Processor>::apply(double scale_denom)
Processor & p = static_cast<Processor&>(*this); Processor & p = static_cast<Processor&>(*this);
p.start_map_processing(m_); p.start_map_processing(m_);
try projection proj(m_.srs(),true);
{ if (scale_denom <= 0.0)
projection proj(m_.srs(),true); scale_denom = mapnik::scale_denominator(m_.scale(),proj.is_geographic());
if (scale_denom <= 0.0) scale_denom *= scale_factor_;
scale_denom = mapnik::scale_denominator(m_.scale(),proj.is_geographic());
scale_denom *= scale_factor_;
BOOST_FOREACH ( layer const& lyr, m_.layers() ) BOOST_FOREACH ( layer const& lyr, m_.layers() )
{
if (lyr.visible(scale_denom))
{ {
if (lyr.visible(scale_denom)) std::set<std::string> names;
{ apply_to_layer(lyr,
std::set<std::string> names; p,
apply_to_layer(lyr, proj,
p, m_.scale(),
proj, scale_denom,
m_.scale(), m_.width(),
scale_denom, m_.height(),
m_.width(), m_.get_current_extent(),
m_.height(), m_.buffer_size(),
m_.get_current_extent(), names);
m_.buffer_size(),
names);
}
} }
} }
catch (proj_init_error const& ex)
{
MAPNIK_LOG_ERROR(feature_style_processor) << "feature_style_processor: proj_init_error=" << ex.what();
}
p.end_map_processing(m_); p.end_map_processing(m_);
@ -207,30 +200,23 @@ void feature_style_processor<Processor>::apply(mapnik::layer const& lyr,
{ {
Processor & p = static_cast<Processor&>(*this); Processor & p = static_cast<Processor&>(*this);
p.start_map_processing(m_); p.start_map_processing(m_);
try projection proj(m_.srs(),true);
{ if (scale_denom <= 0.0)
projection proj(m_.srs(),true); scale_denom = mapnik::scale_denominator(m_.scale(),proj.is_geographic());
if (scale_denom <= 0.0) scale_denom *= scale_factor_;
scale_denom = mapnik::scale_denominator(m_.scale(),proj.is_geographic());
scale_denom *= scale_factor_;
if (lyr.visible(scale_denom)) if (lyr.visible(scale_denom))
{
apply_to_layer(lyr,
p,
proj,
m_.scale(),
scale_denom,
m_.width(),
m_.height(),
m_.get_current_extent(),
m_.buffer_size(),
names);
}
}
catch (proj_init_error const& ex)
{ {
MAPNIK_LOG_ERROR(feature_style_processor) << "feature_style_processor: proj_init_error=" << ex.what(); apply_to_layer(lyr,
p,
proj,
m_.scale(),
scale_denom,
m_.width(),
m_.height(),
m_.get_current_extent(),
m_.buffer_size(),
names);
} }
p.end_map_processing(m_); p.end_map_processing(m_);
} }

View file

@ -199,7 +199,17 @@ void map_parser::parse_map(Map & map, xml_node const& pt, std::string const& bas
map.set_background_image(ensure_relative_to_xml(image_filename)); map.set_background_image(ensure_relative_to_xml(image_filename));
} }
map.set_srs(map_node.get_attr("srs", map.srs())); std::string srs = map_node.get_attr("srs", map.srs());
try
{
// create throwaway projection object here to ensure it is valid
projection proj(srs);
}
catch (proj_init_error const& ex)
{
throw mapnik::config_error(ex.what());
}
map.set_srs(srs);
optional<unsigned> buffer_size = map_node.get_opt_attr<unsigned>("buffer-size"); optional<unsigned> buffer_size = map_node.get_opt_attr<unsigned>("buffer-size");
if (buffer_size) if (buffer_size)
@ -543,9 +553,17 @@ void map_parser::parse_layer(Map & map, xml_node const& node)
{ {
name = node.get_attr("name", std::string("Unnamed")); name = node.get_attr("name", std::string("Unnamed"));
// XXX if no projection is given inherit from map? [DS] // If no projection is given inherit from map
std::string srs = node.get_attr("srs", map.srs()); std::string srs = node.get_attr("srs", map.srs());
try
{
// create throwaway projection object here to ensure it is valid
projection proj(srs);
}
catch (proj_init_error const& ex)
{
throw mapnik::config_error(ex.what());
}
layer lyr(name, srs); layer lyr(name, srs);
optional<boolean> status = node.get_opt_attr<boolean>("status"); optional<boolean> status = node.get_opt_attr<boolean>("status");

View file

@ -0,0 +1,3 @@
<Map>
<Layer srs="+init=invalid_srs_value" />
</Map>

View file

@ -0,0 +1,2 @@
<Map srs="+init=invalid_srs_value">
</Map>