no need to catch image_reader_exception any more during load map because all errors are now at runtime due to path expressions

This commit is contained in:
Dane Springmeyer 2012-06-29 16:21:52 -07:00
parent 531a25bbb7
commit f866ab1f80

View file

@ -27,7 +27,6 @@
#include <mapnik/xml_tree.hpp> #include <mapnik/xml_tree.hpp>
#include <mapnik/version.hpp> #include <mapnik/version.hpp>
#include <mapnik/image_reader.hpp>
#include <mapnik/image_compositing.hpp> #include <mapnik/image_compositing.hpp>
#include <mapnik/color.hpp> #include <mapnik/color.hpp>
#include <mapnik/color_factory.hpp> #include <mapnik/color_factory.hpp>
@ -899,60 +898,44 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym)
if (file) if (file)
{ {
try if(base)
{ {
if(base) std::map<std::string,std::string>::const_iterator itr = file_sources_.find(*base);
if (itr!=file_sources_.end())
{ {
std::map<std::string,std::string>::const_iterator itr = file_sources_.find(*base); *file = itr->second + "/" + *file;
if (itr!=file_sources_.end())
{
*file = itr->second + "/" + *file;
}
}
*file = ensure_relative_to_xml(file);
path_expression_ptr expr(boost::make_shared<path_expression>());
if (!parse_path_from_string(expr, *file, sym.get_tree().path_expr_grammar))
{
throw mapnik::config_error("Failed to parse path_expression '" + *file + "'");
}
symbol.set_filename(expr);
optional<std::string> image_transform_wkt = sym.get_opt_attr<std::string>("image-transform");
if (image_transform_wkt)
{
mapnik::transform_list_ptr tl = boost::make_shared<mapnik::transform_list>();
if (!mapnik::parse_transform(*tl, *image_transform_wkt, sym.get_tree().transform_expr_grammar))
{
std::stringstream ss;
ss << "Could not parse transform from '" << *image_transform_wkt
<< "', expected SVG transform attribute";
if (strict_)
{
throw config_error(ss.str()); // value_error here?
}
else
{
MAPNIK_LOG_WARN(load_map) << "map_parser: " << ss;
}
}
symbol.set_image_transform(tl);
} }
} }
catch (image_reader_exception const & ex)
*file = ensure_relative_to_xml(file);
path_expression_ptr expr(boost::make_shared<path_expression>());
if (!parse_path_from_string(expr, *file, sym.get_tree().path_expr_grammar))
{ {
std::string msg("Failed to load image file '" + * file + throw mapnik::config_error("Failed to parse path_expression '" + *file + "'");
"': " + ex.what()); }
if (strict_)
symbol.set_filename(expr);
optional<std::string> image_transform_wkt = sym.get_opt_attr<std::string>("image-transform");
if (image_transform_wkt)
{
mapnik::transform_list_ptr tl = boost::make_shared<mapnik::transform_list>();
if (!mapnik::parse_transform(*tl, *image_transform_wkt, sym.get_tree().transform_expr_grammar))
{ {
throw config_error(msg); std::stringstream ss;
} ss << "Could not parse transform from '" << *image_transform_wkt
else << "', expected SVG transform attribute";
{ if (strict_)
MAPNIK_LOG_WARN(load_map) << "map_parser: " << msg; {
throw config_error(ss.str()); // value_error here?
}
else
{
MAPNIK_LOG_WARN(load_map) << "map_parser: " << ss;
}
} }
symbol.set_image_transform(tl);
} }
} }
parse_symbolizer_base(symbol, sym); parse_symbolizer_base(symbol, sym);
@ -1099,41 +1082,25 @@ void map_parser::parse_line_pattern_symbolizer(rule & rule, xml_node const & sym
std::string file = sym.get_attr<std::string>("file"); std::string file = sym.get_attr<std::string>("file");
optional<std::string> base = sym.get_opt_attr<std::string>("base"); optional<std::string> base = sym.get_opt_attr<std::string>("base");
try if(base)
{ {
if(base) std::map<std::string,std::string>::const_iterator itr = file_sources_.find(*base);
if (itr!=file_sources_.end())
{ {
std::map<std::string,std::string>::const_iterator itr = file_sources_.find(*base); file = itr->second + "/" + file;
if (itr!=file_sources_.end())
{
file = itr->second + "/" + file;
}
}
file = ensure_relative_to_xml(file);
path_expression_ptr expr(boost::make_shared<path_expression>());
if (!parse_path_from_string(expr, file, sym.get_tree().path_expr_grammar))
{
throw mapnik::config_error("Failed to parse path_expression '" + file + "'");
}
line_pattern_symbolizer symbol(expr);
parse_symbolizer_base(symbol, sym);
rule.append(symbol);
}
catch (image_reader_exception const & ex)
{
std::string msg("Failed to load image file '" + file +
"': " + ex.what());
if (strict_)
{
throw config_error(msg);
}
else
{
MAPNIK_LOG_WARN(load_map) << "map_parser: " << msg;
} }
} }
file = ensure_relative_to_xml(file);
path_expression_ptr expr(boost::make_shared<path_expression>());
if (!parse_path_from_string(expr, file, sym.get_tree().path_expr_grammar))
{
throw mapnik::config_error("Failed to parse path_expression '" + file + "'");
}
line_pattern_symbolizer symbol(expr);
parse_symbolizer_base(symbol, sym);
rule.append(symbol);
} }
catch (const config_error & ex) catch (const config_error & ex)
{ {
@ -1150,58 +1117,42 @@ void map_parser::parse_polygon_pattern_symbolizer(rule & rule,
std::string file = sym.get_attr<std::string>("file"); std::string file = sym.get_attr<std::string>("file");
optional<std::string> base = sym.get_opt_attr<std::string>("base"); optional<std::string> base = sym.get_opt_attr<std::string>("base");
try if(base)
{ {
if(base) std::map<std::string,std::string>::iterator itr = file_sources_.find(*base);
if (itr!=file_sources_.end())
{ {
std::map<std::string,std::string>::iterator itr = file_sources_.find(*base); file = itr->second + "/" + file;
if (itr!=file_sources_.end())
{
file = itr->second + "/" + file;
}
}
file = ensure_relative_to_xml(file);
path_expression_ptr expr(boost::make_shared<path_expression>());
if (!parse_path_from_string(expr, file, sym.get_tree().path_expr_grammar))
{
throw mapnik::config_error("Failed to parse path_expression '" + file + "'");
}
polygon_pattern_symbolizer symbol(expr);
// pattern alignment
pattern_alignment_e p_alignment = sym.get_attr<pattern_alignment_e>("alignment",LOCAL_ALIGNMENT);
symbol.set_alignment(p_alignment);
// opacity
optional<double> opacity = sym.get_opt_attr<double>("opacity");
if (opacity) symbol.set_opacity(*opacity);
// gamma
optional<double> gamma = sym.get_opt_attr<double>("gamma");
if (gamma) symbol.set_gamma(*gamma);
// gamma method
optional<gamma_method_e> gamma_method = sym.get_opt_attr<gamma_method_e>("gamma-method");
if (gamma_method) symbol.set_gamma_method(*gamma_method);
parse_symbolizer_base(symbol, sym);
rule.append(symbol);
}
catch (image_reader_exception const & ex)
{
std::string msg("Failed to load image file '" + file +
"': " + ex.what());
if (strict_)
{
throw config_error(msg);
}
else
{
MAPNIK_LOG_WARN(load_map) << "map_parser: " << msg;
} }
} }
file = ensure_relative_to_xml(file);
path_expression_ptr expr(boost::make_shared<path_expression>());
if (!parse_path_from_string(expr, file, sym.get_tree().path_expr_grammar))
{
throw mapnik::config_error("Failed to parse path_expression '" + file + "'");
}
polygon_pattern_symbolizer symbol(expr);
// pattern alignment
pattern_alignment_e p_alignment = sym.get_attr<pattern_alignment_e>("alignment",LOCAL_ALIGNMENT);
symbol.set_alignment(p_alignment);
// opacity
optional<double> opacity = sym.get_opt_attr<double>("opacity");
if (opacity) symbol.set_opacity(*opacity);
// gamma
optional<double> gamma = sym.get_opt_attr<double>("gamma");
if (gamma) symbol.set_gamma(*gamma);
// gamma method
optional<gamma_method_e> gamma_method = sym.get_opt_attr<gamma_method_e>("gamma-method");
if (gamma_method) symbol.set_gamma_method(*gamma_method);
parse_symbolizer_base(symbol, sym);
rule.append(symbol);
} }
catch (const config_error & ex) catch (const config_error & ex)
{ {
@ -1314,38 +1265,22 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym)
std::string image_file = sym.get_attr<std::string>("file"); std::string image_file = sym.get_attr<std::string>("file");
optional<std::string> base = sym.get_opt_attr<std::string>("base"); optional<std::string> base = sym.get_opt_attr<std::string>("base");
try if(base)
{ {
if(base) std::map<std::string,std::string>::const_iterator itr = file_sources_.find(*base);
if (itr!=file_sources_.end())
{ {
std::map<std::string,std::string>::const_iterator itr = file_sources_.find(*base); image_file = itr->second + "/" + image_file;
if (itr!=file_sources_.end())
{
image_file = itr->second + "/" + image_file;
}
} }
}
image_file = ensure_relative_to_xml(image_file); image_file = ensure_relative_to_xml(image_file);
path_expression_ptr expr(boost::make_shared<path_expression>()); path_expression_ptr expr(boost::make_shared<path_expression>());
if (!parse_path_from_string(expr, image_file, sym.get_tree().path_expr_grammar)) if (!parse_path_from_string(expr, image_file, sym.get_tree().path_expr_grammar))
{
throw mapnik::config_error("Failed to parse path_expression '" + image_file + "'");
}
shield_symbol.set_filename(expr);
}
catch (image_reader_exception const & ex)
{ {
std::string msg("Failed to load image file '" + image_file + throw mapnik::config_error("Failed to parse path_expression '" + image_file + "'");
"': " + ex.what());
if (strict_)
{
throw config_error(msg);
}
else
{
MAPNIK_LOG_WARN(load_map) << "map_parser: " << msg;
}
} }
shield_symbol.set_filename(expr);
rule.append(shield_symbol); rule.append(shield_symbol);
} }
catch (const config_error & ex) catch (const config_error & ex)