2006-10-03 10:39:43 +02:00
/*****************************************************************************
Patch from David Eastcott :
1. Modified Text Symbolizer
a) corrected line fragment centering (for 2nd and subsequent lines, when line breaks occur).
b) adjusted vertical alignment calculation so that:
i) middle -> has the center of the text line(s) at the point origin
ii) bottom -> has the text line(s) below the point origin
iii) top -> has the text line(s) above the point origin
c) added new text_symbolizer attribute: 'wrap_before', value range: true/false, default == false
allows line breaks at first wrap_char before wrap_width as an alternative to the original
which was to create the line break at the first wrap_char after wrap_width
d) added new text_symbolizer attribute: 'horizontal_alignment', value range: left/middle/right, default == middle
i) left -> has all text line(s) to left of the point origin
ii) middle -> has all text line(s) centered on the the point origin
iii) right -> has all text line(s) to the right of the point origin
NOTE: dx, dy position adjustments are applied after alignments and before Justify.
e) added new text_symbolizer attribute: 'justify_alignment', value range: left/middle/right, default == middle
i) left -> after alignments, has all text line(s) are left justified (left to right reading)
ii) middle -> after alignments, has all text line(s) center justified
iii) right -> after alignments, has all text line(s) right justified (right to left reading)
f) added new text_symbolizer attribute: 'opacity', value range: 0.0 thru 1.0; 1.0 == fully opaque
g) modified positioning to compensate for both line_spacing and character_spacing, to ensure proper
centering of the text envelope. Also ensure that centering occurs correctly even if no wrapping
occurs. Line spacing is uniform and consistent and compensates for errors between text_size and
the actual size (ci.height is inconsistent, depending on case and character); fixes issue with
multi-line text where some lines have a slight gap and others are compressed together.
2. Modified shield_symbolizer
a) added the attributes:
i) allow_overlap
ii) vertical_alignment
iii) horizontal_alignment
iv) justify_alignment
v) wrap_width
vi) wrap_character
vii) wrap_before
viii) text_convert
ix) line_spacing
x) character_spacing
xi) opacity
b) added new shield_symbolizer attribute: 'unlock_image', value range: true/false, default == false
i) false == image and text placement behaviour same as before
ii) true == image placement independant of text, image is always centered at geometry point, text placed per attributes,
dx/dy only affect text.
Allows user to create point markers with text, but both the text and image rendering collision detection are done
as a pair (they come and go together - solves problem if using point_symbolizer and text_symbolizers where one or the
other are omitted due to overlaps, but not both)
c) extended choices for the attribute 'placement' to include vertex; effect is limited to the shield_symbolizer
Allows an attempted placement at every vertex available, gives additional shield placement volume when using line geometry
d) ensured that the text placement was not updating the detector unless a shield image was actually placed.
e) added new shield_symbolizer attribute: 'no_text', value range: true/false, default = false
When set true, the text for the feature is ignored ('space' subsituted) so that pure graphic symbols can be used
and no text is rendered over top of them.
2009-10-19 15:52:53 +02:00
*
2006-10-03 10:39:43 +02:00
* This file is part of Mapnik ( c + + mapping toolkit )
*
2011-10-23 15:04:25 +02:00
* Copyright ( C ) 2011 Artem Pavlenko
2006-10-03 10:39:43 +02:00
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-04-08 02:20:56 +02:00
2006-10-04 13:22:18 +02:00
// mapnik
2012-04-08 02:20:56 +02:00
# include <mapnik/debug.hpp>
2007-10-08 19:42:41 +02:00
# include <mapnik/load_map.hpp>
2012-03-06 15:18:11 +01:00
# include <mapnik/xml_tree.hpp>
2009-12-05 04:58:48 +01:00
# include <mapnik/version.hpp>
2012-03-21 16:47:33 +01:00
# include <mapnik/image_compositing.hpp>
2012-07-07 01:45:58 +02:00
# include <mapnik/image_scaling.hpp>
2006-10-04 13:22:18 +02:00
# include <mapnik/color.hpp>
# include <mapnik/color_factory.hpp>
2011-08-29 23:07:45 +02:00
# include <mapnik/symbolizer.hpp>
# include <mapnik/feature_type_style.hpp>
2012-04-18 13:14:23 +02:00
# include <mapnik/image_filter_parser.hpp>
2006-10-04 13:22:18 +02:00
# include <mapnik/layer.hpp>
# include <mapnik/datasource_cache.hpp>
2007-09-25 20:47:12 +02:00
# include <mapnik/font_engine_freetype.hpp>
2008-06-29 12:58:48 +02:00
# include <mapnik/font_set.hpp>
2012-03-13 09:02:53 +01:00
# include <mapnik/xml_loader.hpp>
2012-02-12 12:46:07 +01:00
# include <mapnik/expression.hpp>
2010-06-18 17:39:32 +02:00
# include <mapnik/parse_path.hpp>
2012-05-27 23:50:09 +02:00
# include <mapnik/parse_transform.hpp>
2010-03-12 15:49:34 +01:00
# include <mapnik/raster_colorizer.hpp>
2010-06-01 17:27:19 +02:00
# include <mapnik/svg/svg_path_parser.hpp>
2011-03-16 14:32:04 +01:00
# include <mapnik/metawriter_factory.hpp>
2012-02-18 00:39:14 +01:00
# include <mapnik/text_placements/registry.hpp>
2012-02-12 03:55:13 +01:00
# include <mapnik/text_placements/dummy.hpp>
2012-01-22 03:39:59 +01:00
# include <mapnik/symbolizer.hpp>
# include <mapnik/rule.hpp>
2012-03-12 01:09:26 +01:00
# include <mapnik/config_error.hpp>
2012-03-23 12:56:23 +01:00
# include <mapnik/util/dasharray_parser.hpp>
2012-04-06 22:39:13 +02:00
# include <mapnik/util/conversions.hpp>
2012-07-11 07:38:53 +02:00
# include <mapnik/marker_cache.hpp>
2011-02-28 14:17:46 +01:00
2007-10-08 19:42:41 +02:00
// boost
# include <boost/optional.hpp>
# include <boost/algorithm/string.hpp>
2012-02-23 18:09:02 +01:00
# include <boost/algorithm/string/trim.hpp>
2007-10-08 19:42:41 +02:00
# include <boost/tokenizer.hpp>
# include <boost/property_tree/ptree.hpp>
# include <boost/property_tree/xml_parser.hpp>
# include <boost/static_assert.hpp>
2009-05-01 03:59:01 +02:00
# include <boost/filesystem/operations.hpp>
2010-06-01 17:27:19 +02:00
// agg
# include "agg_trans_affine.h"
2007-10-08 19:42:41 +02:00
// stl
# include <iostream>
2012-03-12 02:12:58 +01:00
# include <sstream>
2006-10-03 10:39:43 +02:00
2006-10-04 13:22:18 +02:00
using boost : : tokenizer ;
2007-09-25 20:47:12 +02:00
using std : : endl ;
2006-10-03 10:39:43 +02:00
Patch from David Eastcott :
1. Modified Text Symbolizer
a) corrected line fragment centering (for 2nd and subsequent lines, when line breaks occur).
b) adjusted vertical alignment calculation so that:
i) middle -> has the center of the text line(s) at the point origin
ii) bottom -> has the text line(s) below the point origin
iii) top -> has the text line(s) above the point origin
c) added new text_symbolizer attribute: 'wrap_before', value range: true/false, default == false
allows line breaks at first wrap_char before wrap_width as an alternative to the original
which was to create the line break at the first wrap_char after wrap_width
d) added new text_symbolizer attribute: 'horizontal_alignment', value range: left/middle/right, default == middle
i) left -> has all text line(s) to left of the point origin
ii) middle -> has all text line(s) centered on the the point origin
iii) right -> has all text line(s) to the right of the point origin
NOTE: dx, dy position adjustments are applied after alignments and before Justify.
e) added new text_symbolizer attribute: 'justify_alignment', value range: left/middle/right, default == middle
i) left -> after alignments, has all text line(s) are left justified (left to right reading)
ii) middle -> after alignments, has all text line(s) center justified
iii) right -> after alignments, has all text line(s) right justified (right to left reading)
f) added new text_symbolizer attribute: 'opacity', value range: 0.0 thru 1.0; 1.0 == fully opaque
g) modified positioning to compensate for both line_spacing and character_spacing, to ensure proper
centering of the text envelope. Also ensure that centering occurs correctly even if no wrapping
occurs. Line spacing is uniform and consistent and compensates for errors between text_size and
the actual size (ci.height is inconsistent, depending on case and character); fixes issue with
multi-line text where some lines have a slight gap and others are compressed together.
2. Modified shield_symbolizer
a) added the attributes:
i) allow_overlap
ii) vertical_alignment
iii) horizontal_alignment
iv) justify_alignment
v) wrap_width
vi) wrap_character
vii) wrap_before
viii) text_convert
ix) line_spacing
x) character_spacing
xi) opacity
b) added new shield_symbolizer attribute: 'unlock_image', value range: true/false, default == false
i) false == image and text placement behaviour same as before
ii) true == image placement independant of text, image is always centered at geometry point, text placed per attributes,
dx/dy only affect text.
Allows user to create point markers with text, but both the text and image rendering collision detection are done
as a pair (they come and go together - solves problem if using point_symbolizer and text_symbolizers where one or the
other are omitted due to overlaps, but not both)
c) extended choices for the attribute 'placement' to include vertex; effect is limited to the shield_symbolizer
Allows an attempted placement at every vertex available, gives additional shield placement volume when using line geometry
d) ensured that the text placement was not updating the detector unless a shield image was actually placed.
e) added new shield_symbolizer attribute: 'no_text', value range: true/false, default = false
When set true, the text for the feature is ignored ('space' subsituted) so that pure graphic symbols can be used
and no text is rendered over top of them.
2009-10-19 15:52:53 +02:00
namespace mapnik
2006-10-03 10:39:43 +02:00
{
2010-04-09 20:47:19 +02:00
using boost : : optional ;
class map_parser : boost : : noncopyable {
public :
2012-03-16 01:50:55 +01:00
map_parser ( bool strict , std : : string const & filename = " " ) :
strict_ ( strict ) ,
filename_ ( filename ) ,
2010-06-02 13:03:30 +02:00
relative_to_xml_ ( true ) ,
2012-03-11 23:24:28 +01:00
font_manager_ ( font_engine_ )
2012-03-13 15:56:11 +01:00
{ }
2010-04-09 20:47:19 +02:00
2012-03-13 11:11:28 +01:00
void parse_map ( Map & map , xml_node const & sty , std : : string const & base_path ) ;
2010-04-09 20:47:19 +02:00
private :
2012-03-16 01:50:55 +01:00
void parse_map_include ( Map & map , xml_node const & include ) ;
2012-03-06 17:29:33 +01:00
void parse_style ( Map & map , xml_node const & sty ) ;
void parse_layer ( Map & map , xml_node const & lay ) ;
void parse_metawriter ( Map & map , xml_node const & lay ) ;
2012-05-07 17:08:16 +02:00
void parse_symbolizer_base ( symbolizer_base & sym , xml_node const & pt ) ;
2010-05-27 12:20:10 +02:00
2012-03-06 17:29:33 +01:00
void parse_fontset ( Map & map , xml_node const & fset ) ;
2012-04-19 20:22:42 +02:00
bool parse_font ( font_set & fset , xml_node const & f ) ;
2010-05-27 12:20:10 +02:00
2012-03-07 01:35:37 +01:00
void parse_rule ( feature_type_style & style , xml_node const & r ) ;
void parse_point_symbolizer ( rule & rule , xml_node const & sym ) ;
void parse_line_pattern_symbolizer ( rule & rule , xml_node const & sym ) ;
void parse_polygon_pattern_symbolizer ( rule & rule , xml_node const & sym ) ;
void parse_text_symbolizer ( rule & rule , xml_node const & sym ) ;
void parse_shield_symbolizer ( rule & rule , xml_node const & sym ) ;
void parse_line_symbolizer ( rule & rule , xml_node const & sym ) ;
void parse_polygon_symbolizer ( rule & rule , xml_node const & sym ) ;
2012-03-16 01:50:55 +01:00
void parse_building_symbolizer ( rule & rule , xml_node const & sym ) ;
void parse_raster_symbolizer ( rule & rule , xml_node const & sym ) ;
void parse_markers_symbolizer ( rule & rule , xml_node const & sym ) ;
2012-03-07 01:35:37 +01:00
2012-03-11 23:24:28 +01:00
void parse_raster_colorizer ( raster_colorizer_ptr const & rc , xml_node const & node ) ;
2012-07-28 04:21:46 +02:00
bool parse_stroke ( stroke & strk , xml_node const & sym ) ;
2010-05-27 12:20:10 +02:00
2012-03-13 11:11:28 +01:00
void ensure_font_face ( std : : string const & face_name ) ;
2012-03-12 02:12:58 +01:00
void find_unused_nodes ( xml_node const & root ) ;
void find_unused_nodes_recursive ( xml_node const & node , std : : stringstream & error_text ) ;
2010-05-27 12:20:10 +02:00
2012-03-13 11:11:28 +01:00
2012-03-11 23:24:28 +01:00
std : : string ensure_relative_to_xml ( boost : : optional < std : : string > opt_path ) ;
2012-02-25 01:34:39 +01:00
boost : : optional < color > get_opt_color_attr ( boost : : property_tree : : ptree const & node ,
2012-03-13 15:56:11 +01:00
std : : string const & name ) ;
2010-05-27 12:20:10 +02:00
bool strict_ ;
std : : string filename_ ;
bool relative_to_xml_ ;
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_ ;
std : : map < std : : string , font_set > fontsets_ ;
2010-04-09 20:47:19 +02:00
} ;
2012-04-08 02:20:56 +02:00
//#include <mapnik/internal/dump_xml.hpp>
2010-04-09 20:47:19 +02:00
void load_map ( Map & map , std : : string const & filename , bool strict )
{
2012-03-11 23:24:28 +01:00
// TODO - use xml encoding?
xml_tree tree ( " utf8 " ) ;
2012-03-06 15:18:11 +01:00
tree . set_filename ( filename ) ;
2012-03-13 09:02:53 +01:00
read_xml ( filename , tree . root ( ) ) ;
2012-03-06 15:18:11 +01:00
map_parser parser ( strict , filename ) ;
2012-03-13 11:11:28 +01:00
parser . parse_map ( map , tree . root ( ) , " " ) ;
2012-04-08 02:20:56 +02:00
//dump_xml(tree.root());
2010-04-09 20:47:19 +02:00
}
2009-01-16 00:51:07 +01:00
2012-03-05 19:44:20 +01:00
void load_map_string ( Map & map , std : : string const & str , bool strict , std : : string base_path )
2010-04-09 20:47:19 +02:00
{
2012-03-11 23:24:28 +01:00
// TODO - use xml encoding?
xml_tree tree ( " utf8 " ) ;
2011-05-26 01:48:07 +02:00
if ( ! base_path . empty ( ) )
2012-03-13 09:02:53 +01:00
read_xml_string ( str , tree . root ( ) , base_path ) ; // accept base_path passed into function
2011-05-26 01:48:07 +02:00
else
2012-03-13 09:02:53 +01:00
read_xml_string ( str , tree . root ( ) , map . base_path ( ) ) ; // default to map base_path
2012-03-06 15:18:11 +01:00
map_parser parser ( strict , base_path ) ;
2012-03-07 01:35:37 +01:00
parser . parse_map ( map , tree . root ( ) , base_path ) ;
2012-02-25 01:34:39 +01:00
}
2012-03-06 15:18:11 +01:00
void map_parser : : parse_map ( Map & map , xml_node const & pt , std : : string const & base_path )
2010-04-09 20:47:19 +02:00
{
2010-05-27 12:20:10 +02:00
try
{
2012-03-06 15:18:11 +01:00
xml_node const & map_node = pt . get_child ( " Map " ) ;
2010-06-02 13:03:30 +02:00
try
{
2011-01-25 21:47:56 +01:00
// Check if relative paths should be interpreted as relative to/from XML location
// Default is true, and map_parser::ensure_relative_to_xml will be called to modify path
2012-03-06 15:18:11 +01:00
optional < boolean > paths_from_xml = map_node . get_opt_attr < boolean > ( " paths-from-xml " ) ;
2011-01-25 21:47:56 +01:00
if ( paths_from_xml )
{
relative_to_xml_ = * paths_from_xml ;
}
2012-03-06 15:18:11 +01:00
optional < std : : string > base_path_from_xml = map_node . get_opt_attr < std : : string > ( " base " ) ;
2011-05-26 01:48:07 +02:00
if ( ! base_path . empty ( ) )
{
2012-03-06 15:18:11 +01:00
map . set_base_path ( base_path ) ;
2011-05-26 01:48:07 +02:00
}
else if ( base_path_from_xml )
{
2012-03-06 15:18:11 +01:00
map . set_base_path ( * base_path_from_xml ) ;
2011-05-26 01:48:07 +02:00
}
else
{
boost : : filesystem : : path xml_path ( filename_ ) ;
// TODO - should we make this absolute?
2012-02-02 02:53:35 +01:00
# if (BOOST_FILESYSTEM_VERSION == 3)
std : : string base = xml_path . parent_path ( ) . string ( ) ;
# else // v2
std : : string base = xml_path . branch_path ( ) . string ( ) ;
# endif
2011-05-26 01:48:07 +02:00
2012-03-06 15:18:11 +01:00
map . set_base_path ( base ) ;
2011-05-26 01:48:07 +02:00
}
2012-03-06 15:18:11 +01:00
optional < color > bgcolor = map_node . get_opt_attr < color > ( " background-color " ) ;
2012-02-02 02:53:35 +01:00
if ( bgcolor )
2010-07-19 13:10:03 +02:00
{
2012-03-06 15:18:11 +01:00
map . set_background ( * bgcolor ) ;
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
2012-03-06 15:18:11 +01:00
optional < std : : string > image_filename = map_node . get_opt_attr < std : : string > ( " background-image " ) ;
2010-07-19 13:10:03 +02:00
if ( image_filename )
2012-02-02 02:53:35 +01:00
{
2011-01-25 21:47:56 +01:00
map . set_background_image ( ensure_relative_to_xml ( image_filename ) ) ;
2010-07-19 13:10:03 +02:00
}
2012-02-02 02:53:35 +01:00
2012-03-06 15:18:11 +01:00
map . set_srs ( map_node . get_attr ( " srs " , map . srs ( ) ) ) ;
2010-04-09 20:47:19 +02:00
2012-03-06 15:18:11 +01:00
optional < unsigned > buffer_size = map_node . get_opt_attr < unsigned > ( " buffer-size " ) ;
2010-06-02 13:03:30 +02:00
if ( buffer_size )
{
map . set_buffer_size ( * buffer_size ) ;
}
2010-04-09 20:47:19 +02:00
2012-03-06 15:18:11 +01:00
optional < std : : string > maximum_extent = map_node . get_opt_attr < std : : string > ( " maximum-extent " ) ;
2011-04-14 04:32:51 +02:00
if ( maximum_extent )
{
box2d < double > box ;
if ( box . from_string ( * maximum_extent ) )
{
map . set_maximum_extent ( box ) ;
}
else
{
2011-12-01 01:48:01 +01:00
std : : ostringstream s_err ;
2012-03-06 15:18:11 +01:00
s_err < < " failed to parse 'maximum-extent' " ;
if ( strict_ )
2012-04-08 02:20:56 +02:00
{
2011-12-01 01:48:01 +01:00
throw config_error ( s_err . str ( ) ) ;
2012-04-08 02:20:56 +02:00
}
2011-04-14 04:32:51 +02:00
else
2012-04-08 02:20:56 +02:00
{
2012-04-09 21:41:56 +02:00
MAPNIK_LOG_WARN ( load_map ) < < " map_parser: " < < s_err . str ( ) ;
2012-04-08 02:20:56 +02:00
}
2011-04-14 04:32:51 +02:00
}
}
2012-03-06 15:18:11 +01:00
optional < std : : string > font_directory = map_node . get_opt_attr < std : : string > ( " font-directory " ) ;
2010-10-07 03:49:07 +02:00
if ( font_directory )
{
2012-03-23 23:07:28 +01:00
if ( ! freetype_engine : : register_fonts ( ensure_relative_to_xml ( font_directory ) , false ) )
{
if ( strict_ )
{
2012-03-24 01:27:01 +01:00
throw config_error ( std : : string ( " Failed to load fonts from: " ) + * font_directory ) ;
2012-03-23 23:07:28 +01:00
}
}
2010-10-07 03:49:07 +02:00
}
2012-03-06 15:18:11 +01:00
optional < std : : string > min_version_string = map_node . get_opt_attr < std : : string > ( " minimum-version " ) ;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
if ( min_version_string )
{
boost : : char_separator < char > sep ( " . " ) ;
2012-03-06 15:18:11 +01:00
boost : : tokenizer < boost : : char_separator < char > > tokens ( * min_version_string , sep ) ;
2010-06-02 13:03:30 +02:00
unsigned i = 0 ;
bool success = false ;
int n [ 3 ] ;
2012-03-06 15:18:11 +01:00
for ( boost : : tokenizer < boost : : char_separator < char > > : : iterator beg = tokens . begin ( ) ;
beg ! = tokens . end ( ) ; + + beg )
2010-06-02 13:03:30 +02:00
{
2012-04-06 22:39:13 +02:00
std : : string item ( * beg ) ;
boost : : trim ( item ) ;
if ( ! mapnik : : util : : string2int ( item , n [ i ] ) )
2010-06-02 13:03:30 +02:00
{
2012-04-06 22:39:13 +02:00
throw config_error ( std : : string ( " Invalid version string encountered: ' " )
+ * beg + " ' in ' " + * min_version_string + " ' " ) ;
2012-04-08 02:20:56 +02:00
2010-06-02 13:03:30 +02:00
break ;
}
2012-02-02 02:53:35 +01:00
if ( i = = 2 )
2010-06-02 13:03:30 +02:00
{
success = true ;
break ;
}
+ + i ;
}
if ( success )
{
int min_version = ( n [ 0 ] * 100000 ) + ( n [ 1 ] * 100 ) + ( n [ 2 ] ) ;
if ( min_version > MAPNIK_VERSION )
{
throw config_error ( std : : string ( " This map uses features only present in Mapnik version " ) + * min_version_string + " and newer " ) ;
}
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
}
}
catch ( const config_error & ex )
{
2012-03-12 01:09:26 +01:00
ex . append_context ( map_node ) ;
2010-06-02 13:03:30 +02:00
throw ;
}
2012-02-02 02:53:35 +01:00
2012-03-06 15:47:08 +01:00
parse_map_include ( map , map_node ) ;
2010-08-10 08:01:16 +02:00
}
2012-03-06 15:18:11 +01:00
catch ( node_not_found const & )
2010-08-10 08:01:16 +02:00
{
throw config_error ( " Not a map file. Node 'Map' not found. " ) ;
}
2012-03-12 02:12:58 +01:00
find_unused_nodes ( pt ) ;
2010-08-10 08:01:16 +02:00
}
2012-02-02 02:53:35 +01:00
2012-03-06 15:47:08 +01:00
void map_parser : : parse_map_include ( Map & map , xml_node const & include )
2010-08-10 08:01:16 +02:00
{
2012-03-06 17:29:33 +01:00
try
{
2012-03-13 15:56:11 +01:00
xml_node : : const_iterator itr = include . begin ( ) ;
xml_node : : const_iterator end = include . end ( ) ;
2010-06-02 13:03:30 +02:00
2012-03-13 15:56:11 +01:00
for ( ; itr ! = end ; + + itr )
2011-01-04 16:22:49 +01:00
{
2012-03-13 15:56:11 +01:00
if ( itr - > is_text ( ) ) continue ;
if ( itr - > is ( " Include " ) )
{
parse_map_include ( map , * itr ) ;
}
else if ( itr - > is ( " Style " ) )
{
parse_style ( map , * itr ) ;
}
else if ( itr - > is ( " Layer " ) )
{
parse_layer ( map , * itr ) ;
}
else if ( itr - > is ( " FontSet " ) )
{
parse_fontset ( map , * itr ) ;
}
else if ( itr - > is ( " MetaWriter " ) )
{
parse_metawriter ( map , * itr ) ;
}
else if ( itr - > is ( " FileSource " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-13 15:56:11 +01:00
std : : string name = itr - > get_attr < std : : string > ( " name " ) ;
std : : string value = itr - > get_text ( ) ;
file_sources_ [ name ] = value ;
}
else if ( itr - > is ( " Datasource " ) )
{
std : : string name = itr - > get_attr ( " name " , std : : string ( " Unnamed " ) ) ;
parameters params ;
xml_node : : const_iterator paramIter = itr - > begin ( ) ;
xml_node : : const_iterator endParam = itr - > end ( ) ;
for ( ; paramIter ! = endParam ; + + paramIter )
2011-01-04 16:22:49 +01:00
{
2012-03-13 15:56:11 +01:00
if ( paramIter - > is ( " Parameter " ) )
{
std : : string name = paramIter - > get_attr < std : : string > ( " name " ) ;
std : : string value = paramIter - > get_text ( ) ;
params [ name ] = value ;
}
2011-01-04 16:22:49 +01:00
}
2012-03-13 15:56:11 +01:00
datasource_templates_ [ name ] = params ;
2010-06-02 13:03:30 +02:00
}
2012-03-13 15:56:11 +01:00
else if ( itr - > is ( " Parameters " ) )
2011-12-03 02:48:09 +01:00
{
2012-03-13 15:56:11 +01:00
std : : string name = itr - > get_attr ( " name " , std : : string ( " Unnamed " ) ) ;
parameters & params = map . get_extra_parameters ( ) ;
xml_node : : const_iterator paramIter = itr - > begin ( ) ;
xml_node : : const_iterator endParam = itr - > end ( ) ;
for ( ; paramIter ! = endParam ; + + paramIter )
2011-12-03 02:48:09 +01:00
{
2012-03-13 15:56:11 +01:00
if ( paramIter - > is ( " Parameter " ) )
2011-12-05 23:46:38 +01:00
{
2012-03-13 15:56:11 +01:00
std : : string name = paramIter - > get_attr < std : : string > ( " name " ) ;
bool is_string = true ;
boost : : optional < std : : string > type = paramIter - > get_opt_attr < std : : string > ( " type " ) ;
if ( type )
2011-12-05 23:46:38 +01:00
{
2012-03-13 15:56:11 +01:00
if ( * type = = " int " )
{
is_string = false ;
int value = paramIter - > get_value < int > ( ) ;
params [ name ] = value ;
}
else if ( * type = = " float " )
{
is_string = false ;
double value = paramIter - > get_value < double > ( ) ;
params [ name ] = value ;
}
2011-12-05 23:46:38 +01:00
}
2012-03-13 15:56:11 +01:00
if ( is_string )
2011-12-05 23:46:38 +01:00
{
2012-03-13 15:56:11 +01:00
std : : string value = paramIter - > get_text ( ) ;
2011-12-05 23:46:38 +01:00
params [ name ] = value ;
}
}
2011-12-03 02:48:09 +01:00
}
}
}
2012-03-06 17:29:33 +01:00
} catch ( const config_error & ex ) {
2012-03-12 01:09:26 +01:00
ex . append_context ( include ) ;
2012-03-06 17:29:33 +01:00
throw ;
}
2010-08-10 08:01:16 +02:00
2010-07-06 02:37:05 +02:00
map . init_metawriters ( ) ;
2010-04-09 20:47:19 +02:00
}
2007-09-25 20:47:12 +02:00
2012-03-06 17:29:33 +01:00
void map_parser : : parse_style ( Map & map , xml_node const & sty )
2010-04-09 20:47:19 +02:00
{
2011-06-24 02:53:00 +02:00
std : : string name ( " <missing name> " ) ;
2010-04-09 20:47:19 +02:00
try
2008-06-29 12:58:48 +02:00
{
2012-03-06 17:29:33 +01:00
name = sty . get_attr < std : : string > ( " name " ) ;
2010-06-02 13:03:30 +02:00
feature_type_style style ;
2012-03-06 17:29:33 +01:00
filter_mode_e filter_mode = sty . get_attr < filter_mode_e > ( " filter-mode " , FILTER_ALL ) ;
2011-02-01 23:55:50 +01:00
style . set_filter_mode ( filter_mode ) ;
2012-04-05 18:04:11 +02:00
2012-04-03 14:10:30 +02:00
// compositing
optional < std : : string > comp_op_name = sty . get_opt_attr < std : : string > ( " comp-op " ) ;
if ( comp_op_name )
{
2012-04-18 16:37:14 +02:00
optional < composite_mode_e > comp_op = comp_op_from_string ( * comp_op_name ) ;
if ( comp_op )
{
style . set_comp_op ( * comp_op ) ;
}
else
{
throw config_error ( " failed to parse comp-op: ' " + * comp_op_name + " ' " ) ;
}
2012-04-03 14:10:30 +02:00
}
2012-04-18 13:14:23 +02:00
2012-06-19 21:10:28 +02:00
optional < float > opacity = sty . get_opt_attr < float > ( " opacity " ) ;
if ( opacity )
{
style . set_opacity ( * opacity ) ;
}
2012-04-25 11:53:34 +02:00
2012-06-19 21:10:28 +02:00
// image filters
2012-04-25 11:53:34 +02:00
mapnik : : image_filter_grammar < std : : string : : const_iterator ,
std : : vector < mapnik : : filter : : filter_type > > filter_grammar ;
2012-07-05 18:16:11 +02:00
2012-04-18 13:14:23 +02:00
optional < std : : string > filters = sty . get_opt_attr < std : : string > ( " image-filters " ) ;
if ( filters )
2012-04-03 14:10:30 +02:00
{
2012-04-18 16:37:14 +02:00
std : : string filter_mode = * filters ;
std : : string : : const_iterator itr = filter_mode . begin ( ) ;
std : : string : : const_iterator end = filter_mode . end ( ) ;
2012-04-05 18:04:11 +02:00
2012-07-05 18:16:11 +02:00
bool result = boost : : spirit : : qi : : phrase_parse ( itr , end ,
filter_grammar ,
boost : : spirit : : qi : : ascii : : space ,
2012-04-25 11:53:34 +02:00
style . image_filters ( ) ) ;
if ( ! result | | itr ! = end )
{
throw config_error ( " failed to parse image-filters: ' " + std : : string ( itr , end ) + " ' " ) ;
2012-07-05 18:16:11 +02:00
}
2012-04-25 11:53:34 +02:00
}
2012-07-05 18:16:11 +02:00
// direct image filters (applied directly on main image buffer
// TODO : consider creating a separate XML node e.g
// <ImageFilter name="myfilter" op="blur emboss"/>
//
2012-04-25 11:53:34 +02:00
optional < std : : string > direct_filters = sty . get_opt_attr < std : : string > ( " direct-image-filters " ) ;
if ( direct_filters )
{
std : : string filter_mode = * direct_filters ;
std : : string : : const_iterator itr = filter_mode . begin ( ) ;
2012-07-05 18:16:11 +02:00
std : : string : : const_iterator end = filter_mode . end ( ) ;
bool result = boost : : spirit : : qi : : phrase_parse ( itr , end ,
filter_grammar ,
boost : : spirit : : qi : : ascii : : space ,
2012-04-25 11:53:34 +02:00
style . direct_image_filters ( ) ) ;
2012-04-18 13:14:23 +02:00
if ( ! result | | itr ! = end )
{
2012-04-25 11:53:34 +02:00
throw config_error ( " failed to parse direct-image-filters: ' " + std : : string ( itr , end ) + " ' " ) ;
2012-07-05 18:16:11 +02:00
}
2012-04-18 13:14:23 +02:00
}
2012-07-05 18:16:11 +02:00
2012-04-18 13:14:23 +02:00
// rules
2012-03-06 17:29:33 +01:00
xml_node : : const_iterator ruleIter = sty . begin ( ) ;
xml_node : : const_iterator endRule = sty . end ( ) ;
2010-06-02 13:03:30 +02:00
for ( ; ruleIter ! = endRule ; + + ruleIter )
{
2012-03-06 17:29:33 +01:00
if ( ruleIter - > is ( " Rule " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_rule ( style , * ruleIter ) ;
2010-06-02 13:03:30 +02:00
}
}
map . insert_style ( name , style ) ;
2010-04-09 20:47:19 +02:00
} catch ( const config_error & ex ) {
2012-03-12 01:09:26 +01:00
ex . append_context ( std : : string ( " in style ' " ) + name + " ' " , sty ) ;
2010-07-06 02:37:05 +02:00
throw ;
}
}
2012-03-06 17:29:33 +01:00
void map_parser : : parse_metawriter ( Map & map , xml_node const & pt )
2010-07-06 02:37:05 +02:00
{
2011-06-24 02:53:00 +02:00
std : : string name ( " <missing name> " ) ;
2010-07-06 02:37:05 +02:00
metawriter_ptr writer ;
try
{
2012-03-06 17:29:33 +01:00
name = pt . get_attr < std : : string > ( " name " ) ;
2011-03-16 14:32:04 +01:00
writer = metawriter_create ( pt ) ;
2010-07-06 02:37:05 +02:00
map . insert_metawriter ( name , writer ) ;
} catch ( const config_error & ex ) {
2012-03-12 01:09:26 +01:00
ex . append_context ( std : : string ( " in meta writer ' " ) + name + " ' " , pt ) ;
2008-06-29 12:58:48 +02:00
}
2010-04-09 20:47:19 +02:00
}
2012-03-06 17:29:33 +01:00
void map_parser : : parse_fontset ( Map & map , xml_node const & fset )
2010-04-09 20:47:19 +02:00
{
2011-06-24 02:53:00 +02:00
std : : string name ( " <missing name> " ) ;
2010-04-09 20:47:19 +02:00
try
{
2012-03-06 17:29:33 +01:00
name = fset . get_attr < std : : string > ( " name " ) ;
2010-06-02 13:03:30 +02:00
font_set fontset ( name ) ;
2012-03-06 17:29:33 +01:00
xml_node : : const_iterator itr = fset . begin ( ) ;
xml_node : : const_iterator end = fset . end ( ) ;
2010-06-02 13:03:30 +02:00
2012-04-19 20:22:42 +02:00
bool success = false ;
2010-06-02 13:03:30 +02:00
for ( ; itr ! = end ; + + itr )
{
2012-03-06 17:29:33 +01:00
if ( itr - > is ( " Font " ) )
2010-06-02 13:03:30 +02:00
{
2012-04-19 20:22:42 +02:00
if ( parse_font ( fontset , * itr ) )
{
success = true ;
}
2010-06-02 13:03:30 +02:00
}
}
2012-04-19 20:22:42 +02:00
// if not at least one face-name is valid
if ( ! success )
{
throw mapnik : : config_error ( " no valid fonts could be loaded " ) ;
}
2010-06-02 13:03:30 +02:00
map . insert_fontset ( name , fontset ) ;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
// XXX Hack because map object isn't accessible by text_symbolizer
// when it's parsed
fontsets_ . insert ( pair < std : : string , font_set > ( name , fontset ) ) ;
2012-04-19 20:22:42 +02:00
}
catch ( const config_error & ex )
{
2012-03-12 01:09:26 +01:00
ex . append_context ( std : : string ( " in FontSet ' " ) + name + " ' " , fset ) ;
2010-06-02 13:03:30 +02:00
throw ;
2010-04-09 20:47:19 +02:00
}
}
2008-06-29 12:58:48 +02:00
2012-04-19 20:22:42 +02:00
bool map_parser : : parse_font ( font_set & fset , xml_node const & f )
2010-04-09 20:47:19 +02:00
{
2012-03-06 17:29:33 +01:00
optional < std : : string > face_name = f . get_opt_attr < std : : string > ( " face-name " ) ;
2011-12-20 21:31:38 +01:00
if ( face_name )
2007-09-25 20:47:12 +02:00
{
2012-04-19 20:22:42 +02:00
face_ptr face = font_manager_ . get_face ( * face_name ) ;
if ( face )
2011-12-20 21:31:38 +01:00
{
2012-04-19 20:22:42 +02:00
fset . add_face_name ( * face_name ) ;
return true ;
}
else if ( strict_ )
2011-12-20 21:31:38 +01:00
{
2012-04-19 20:22:42 +02:00
throw config_error ( " Failed to find font face ' " +
* face_name + " ' " ) ;
2011-12-20 21:31:38 +01:00
}
}
else
{
2012-03-12 01:09:26 +01:00
throw config_error ( " Must have 'face-name' set " , f ) ;
2007-09-25 20:47:12 +02:00
}
2012-04-19 20:22:42 +02:00
return false ;
2010-04-09 20:47:19 +02:00
}
2012-08-01 16:44:36 +02:00
void map_parser : : parse_layer ( Map & map , xml_node const & node )
2010-04-09 20:47:19 +02:00
{
std : : string name ;
try
2007-09-25 20:47:12 +02:00
{
2012-08-01 16:44:36 +02:00
name = node . get_attr ( " name " , std : : string ( " Unnamed " ) ) ;
2010-06-02 13:03:30 +02:00
// XXX if no projection is given inherit from map? [DS]
2012-08-01 16:44:36 +02:00
std : : string srs = node . get_attr ( " srs " , map . srs ( ) ) ;
2010-06-02 13:03:30 +02:00
layer lyr ( name , srs ) ;
2012-08-01 16:44:36 +02:00
optional < boolean > status = node . get_opt_attr < boolean > ( " status " ) ;
2010-06-02 13:03:30 +02:00
if ( status )
{
2012-03-16 01:50:55 +01:00
lyr . set_active ( * status ) ;
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
2012-08-01 16:44:36 +02:00
optional < double > min_zoom = node . get_opt_attr < double > ( " minzoom " ) ;
2012-03-12 16:39:59 +01:00
if ( min_zoom )
2010-06-02 13:03:30 +02:00
{
2012-03-16 01:50:55 +01:00
lyr . set_min_zoom ( * min_zoom ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-13 11:11:28 +01:00
2012-08-01 16:44:36 +02:00
optional < double > max_zoom = node . get_opt_attr < double > ( " maxzoom " ) ;
2012-03-12 16:39:59 +01:00
if ( max_zoom )
2010-06-02 13:03:30 +02:00
{
2012-03-16 01:50:55 +01:00
lyr . set_max_zoom ( * max_zoom ) ;
2010-06-02 13:03:30 +02:00
}
2012-08-01 16:44:36 +02:00
optional < boolean > queryable = node . get_opt_attr < boolean > ( " queryable " ) ;
2010-06-02 13:03:30 +02:00
if ( queryable )
{
2012-03-16 01:50:55 +01:00
lyr . set_queryable ( * queryable ) ;
2010-06-02 13:03:30 +02:00
}
optional < boolean > clear_cache =
2012-08-01 16:44:36 +02:00
node . get_opt_attr < boolean > ( " clear-label-cache " ) ;
2010-06-02 13:03:30 +02:00
if ( clear_cache )
{
2012-03-16 01:50:55 +01:00
lyr . set_clear_label_cache ( * clear_cache ) ;
2010-06-02 13:03:30 +02:00
}
2011-03-01 18:09:29 +01:00
optional < boolean > cache_features =
2012-08-01 16:44:36 +02:00
node . get_opt_attr < boolean > ( " cache-features " ) ;
2011-03-01 18:09:29 +01:00
if ( cache_features )
{
2012-03-16 01:50:55 +01:00
lyr . set_cache_features ( * cache_features ) ;
2011-03-01 18:09:29 +01:00
}
2011-10-13 01:30:18 +02:00
optional < std : : string > group_by =
2012-08-01 16:44:36 +02:00
node . get_opt_attr < std : : string > ( " group-by " ) ;
2011-10-13 01:30:18 +02:00
if ( group_by )
{
2012-03-16 01:50:55 +01:00
lyr . set_group_by ( * group_by ) ;
2011-10-13 01:30:18 +02:00
}
2012-04-05 18:04:11 +02:00
2012-08-01 16:44:36 +02:00
optional < unsigned > buffer_size = node . get_opt_attr < unsigned > ( " buffer-size " ) ;
if ( buffer_size )
{
lyr . set_buffer_size ( * buffer_size ) ;
}
optional < std : : string > maximum_extent = node . get_opt_attr < std : : string > ( " maximum-extent " ) ;
if ( maximum_extent )
{
box2d < double > box ;
if ( box . from_string ( * maximum_extent ) )
{
lyr . set_maximum_extent ( box ) ;
}
else
{
std : : ostringstream s_err ;
s_err < < " failed to parse 'maximum-extent' in layer " < < name ;
if ( strict_ )
{
throw config_error ( s_err . str ( ) ) ;
}
else
{
MAPNIK_LOG_WARN ( load_map ) < < " map_parser: " < < s_err . str ( ) ;
}
}
}
xml_node : : const_iterator child = node . begin ( ) ;
xml_node : : const_iterator end = node . end ( ) ;
2010-06-02 13:03:30 +02:00
2012-03-06 17:29:33 +01:00
for ( ; child ! = end ; + + child )
2010-06-02 13:03:30 +02:00
{
2012-03-06 17:29:33 +01:00
if ( child - > is ( " StyleName " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 15:26:13 +01:00
std : : string style_name = child - > get_text ( ) ;
2011-02-05 04:15:17 +01:00
if ( style_name . empty ( ) )
{
std : : ostringstream ss ;
ss < < " StyleName is empty in Layer: ' " < < lyr . name ( ) < < " ' " ;
if ( strict_ )
2012-04-08 02:20:56 +02:00
{
2011-02-05 04:15:17 +01:00
throw config_error ( ss . str ( ) ) ;
2012-04-08 02:20:56 +02:00
}
2011-02-05 04:15:17 +01:00
else
2012-04-08 02:20:56 +02:00
{
2012-04-09 21:41:56 +02:00
MAPNIK_LOG_WARN ( load_map ) < < " map_parser: " < < ss . str ( ) ;
2012-04-08 02:20:56 +02:00
}
2011-02-05 04:15:17 +01:00
}
else
{
lyr . add_style ( style_name ) ;
}
2010-06-02 13:03:30 +02:00
}
2012-03-06 17:29:33 +01:00
else if ( child - > is ( " Datasource " ) )
2010-06-02 13:03:30 +02:00
{
parameters params ;
2012-03-06 17:29:33 +01:00
optional < std : : string > base = child - > get_opt_attr < std : : string > ( " base " ) ;
2012-03-16 01:50:55 +01:00
if ( base )
2010-06-02 13:03:30 +02:00
{
std : : map < std : : string , parameters > : : const_iterator base_itr = datasource_templates_ . find ( * base ) ;
if ( base_itr ! = datasource_templates_ . end ( ) )
params = base_itr - > second ;
}
2012-03-06 17:29:33 +01:00
xml_node : : const_iterator paramIter = child - > begin ( ) ;
xml_node : : const_iterator endParam = child - > end ( ) ;
2010-06-02 13:03:30 +02:00
for ( ; paramIter ! = endParam ; + + paramIter )
{
2012-03-06 17:29:33 +01:00
if ( paramIter - > is ( " Parameter " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-06 17:29:33 +01:00
std : : string name = paramIter - > get_attr < std : : string > ( " name " ) ;
std : : string value = paramIter - > get_text ( ) ;
2010-06-02 13:03:30 +02:00
params [ name ] = value ;
}
}
2011-01-25 21:47:56 +01:00
boost : : optional < std : : string > base_param = params . get < std : : string > ( " base " ) ;
boost : : optional < std : : string > file_param = params . get < std : : string > ( " file " ) ;
2010-06-02 13:03:30 +02:00
2011-01-25 21:47:56 +01:00
if ( base_param ) {
params [ " base " ] = ensure_relative_to_xml ( base_param ) ;
2010-06-02 13:03:30 +02:00
}
2011-01-25 21:47:56 +01:00
else if ( file_param ) {
params [ " file " ] = ensure_relative_to_xml ( file_param ) ;
2010-06-02 13:03:30 +02:00
}
2010-04-09 20:47:19 +02:00
2010-06-02 13:03:30 +02:00
//now we are ready to create datasource
try
{
boost : : shared_ptr < datasource > ds =
datasource_cache : : instance ( ) - > create ( params ) ;
lyr . set_datasource ( ds ) ;
}
2012-03-16 01:50:55 +01:00
catch ( const std : : exception & ex )
2010-06-02 13:03:30 +02:00
{
2012-03-16 01:50:55 +01:00
throw config_error ( ex . what ( ) ) ;
2010-06-02 13:03:30 +02:00
}
catch ( . . . )
{
2011-08-30 01:51:15 +02:00
throw config_error ( " Unknown exception occured attempting to create datasoure for layer ' " + lyr . name ( ) + " ' " ) ;
2010-06-02 13:03:30 +02:00
}
}
}
map . addLayer ( lyr ) ;
2012-02-02 02:53:35 +01:00
}
catch ( const config_error & ex )
2011-01-04 16:22:49 +01:00
{
2012-03-06 17:29:33 +01:00
if ( ! name . empty ( ) )
2011-01-04 16:22:49 +01:00
{
2012-08-01 16:44:36 +02:00
ex . append_context ( std : : string ( " encountered during parsing of layer ' " ) + name + " ' " , node ) ;
2010-06-02 13:03:30 +02:00
}
throw ;
2007-09-25 20:47:12 +02:00
}
2010-04-09 20:47:19 +02:00
}
2007-09-25 20:47:12 +02:00
2012-03-07 01:35:37 +01:00
void map_parser : : parse_rule ( feature_type_style & style , xml_node const & r )
2010-04-09 20:47:19 +02:00
{
std : : string name ;
try
2007-09-25 20:47:12 +02:00
{
2012-03-07 01:35:37 +01:00
name = r . get_attr ( " name " , std : : string ( ) ) ;
2011-12-13 17:47:45 +01:00
rule rule ( name ) ;
2010-06-02 13:03:30 +02:00
2012-03-07 03:57:31 +01:00
xml_node const * child = r . get_opt_child ( " Filter " ) ;
2012-03-07 01:35:37 +01:00
if ( child )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
rule . set_filter ( child - > get_value < expression_ptr > ( ) ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
if ( r . has_child ( " ElseFilter " ) )
2010-06-02 13:03:30 +02:00
{
rule . set_else ( true ) ;
}
2012-03-07 01:35:37 +01:00
if ( r . has_child ( " AlsoFilter " ) )
2011-08-30 19:38:27 +02:00
{
rule . set_also ( true ) ;
}
2012-03-07 01:35:37 +01:00
child = r . get_opt_child ( " MinScaleDenominator " ) ;
if ( child )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
rule . set_min_scale ( child - > get_value < double > ( ) ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
child = r . get_opt_child ( " MaxScaleDenominator " ) ;
if ( child )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
rule . set_max_scale ( child - > get_value < double > ( ) ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
xml_node : : const_iterator symIter = r . begin ( ) ;
xml_node : : const_iterator endSym = r . end ( ) ;
2010-06-02 13:03:30 +02:00
2012-03-16 01:50:55 +01:00
for ( ; symIter ! = endSym ; + + symIter )
2010-06-02 13:03:30 +02:00
{
2012-03-16 01:50:55 +01:00
if ( symIter - > is ( " PointSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_point_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
else if ( symIter - > is ( " LinePatternSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_line_pattern_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
else if ( symIter - > is ( " PolygonPatternSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_polygon_pattern_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
else if ( symIter - > is ( " TextSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_text_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
else if ( symIter - > is ( " ShieldSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_shield_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
else if ( symIter - > is ( " LineSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_line_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
else if ( symIter - > is ( " PolygonSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_polygon_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
else if ( symIter - > is ( " BuildingSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_building_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
else if ( symIter - > is ( " RasterSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-16 01:50:55 +01:00
parse_raster_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
2012-03-07 01:35:37 +01:00
else if ( symIter - > is ( " MarkersSymbolizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-07 01:35:37 +01:00
parse_markers_symbolizer ( rule , * symIter ) ;
2010-06-02 13:03:30 +02:00
}
}
style . add_rule ( rule ) ;
2010-04-09 20:47:19 +02:00
}
catch ( const config_error & ex )
{
2012-03-16 01:50:55 +01:00
if ( ! name . empty ( ) )
2010-06-02 13:03:30 +02:00
{
2012-03-12 01:09:26 +01:00
ex . append_context ( std : : string ( " in rule ' " ) + name + " ' " , r ) ;
2010-06-02 13:03:30 +02:00
}
throw ;
2010-04-09 20:47:19 +02:00
}
}
2012-05-07 17:08:16 +02:00
void map_parser : : parse_symbolizer_base ( symbolizer_base & sym , xml_node const & pt )
2010-07-06 02:37:05 +02:00
{
2012-04-05 16:59:11 +02:00
optional < std : : string > comp_op_name = pt . get_opt_attr < std : : string > ( " comp-op " ) ;
if ( comp_op_name )
{
2012-04-18 16:37:14 +02:00
optional < composite_mode_e > comp_op = comp_op_from_string ( * comp_op_name ) ;
if ( comp_op )
{
sym . set_comp_op ( * comp_op ) ;
}
else
{
throw config_error ( " failed to parse comp-op: ' " + * comp_op_name + " ' " ) ;
}
2012-04-05 16:59:11 +02:00
}
2012-07-05 18:16:11 +02:00
2012-07-04 03:34:11 +02:00
optional < std : : string > geometry_transform_wkt = pt . get_opt_attr < std : : string > ( " geometry-transform " ) ;
if ( geometry_transform_wkt )
2012-04-18 10:46:19 +02:00
{
2012-05-27 23:50:09 +02:00
mapnik : : transform_list_ptr tl = boost : : make_shared < mapnik : : transform_list > ( ) ;
2012-07-04 03:34:11 +02:00
if ( ! mapnik : : parse_transform ( * tl , * geometry_transform_wkt , pt . get_tree ( ) . transform_expr_grammar ) )
2012-04-18 10:46:19 +02:00
{
std : : stringstream ss ;
2012-07-04 03:34:11 +02:00
ss < < " Could not parse transform from ' " < < geometry_transform_wkt < < " ', expected transform attribute " ;
2012-04-18 10:46:19 +02:00
if ( strict_ )
throw config_error ( ss . str ( ) ) ; // value_error here?
else
2012-07-06 01:07:38 +02:00
MAPNIK_LOG_WARN ( load_map ) < < " ### WARNING: " < < ss ;
2012-04-18 10:46:19 +02:00
}
2012-05-27 23:50:09 +02:00
sym . set_transform ( tl ) ;
2012-04-18 10:46:19 +02:00
}
2012-07-05 18:16:11 +02:00
2012-04-24 12:10:54 +02:00
optional < boolean > clip = pt . get_opt_attr < boolean > ( " clip " ) ;
if ( clip ) sym . set_clip ( * clip ) ;
2012-07-05 18:16:11 +02:00
2012-05-07 17:08:16 +02:00
// smooth value
optional < double > smooth = pt . get_opt_attr < double > ( " smooth " ) ;
if ( smooth ) sym . set_smooth ( * smooth ) ;
2012-07-05 18:16:11 +02:00
2012-03-07 01:35:37 +01:00
optional < std : : string > writer = pt . get_opt_attr < std : : string > ( " meta-writer " ) ;
2010-07-06 02:37:05 +02:00
if ( ! writer ) return ;
2012-03-07 01:35:37 +01:00
optional < std : : string > output = pt . get_opt_attr < std : : string > ( " meta-output " ) ;
2010-07-14 12:34:18 +02:00
sym . add_metawriter ( * writer , output ) ;
2010-07-06 02:37:05 +02:00
}
2012-03-07 01:35:37 +01:00
void map_parser : : parse_point_symbolizer ( rule & rule , xml_node const & sym )
2010-04-09 20:47:19 +02:00
{
try
{
2012-03-07 01:35:37 +01:00
optional < std : : string > file = sym . get_opt_attr < std : : string > ( " file " ) ;
optional < std : : string > base = sym . get_opt_attr < std : : string > ( " base " ) ;
optional < boolean > allow_overlap = sym . get_opt_attr < boolean > ( " allow-overlap " ) ;
optional < boolean > ignore_placement = sym . get_opt_attr < boolean > ( " ignore-placement " ) ;
optional < float > opacity = sym . get_opt_attr < float > ( " opacity " ) ;
2012-07-05 18:16:11 +02:00
2012-03-07 01:35:37 +01:00
point_symbolizer symbol ;
if ( allow_overlap )
{
2012-03-16 01:50:55 +01:00
symbol . set_allow_overlap ( * allow_overlap ) ;
2012-03-07 01:35:37 +01:00
}
if ( opacity )
{
2012-03-16 01:50:55 +01:00
symbol . set_opacity ( * opacity ) ;
2012-03-07 01:35:37 +01:00
}
if ( ignore_placement )
{
2012-03-16 01:50:55 +01:00
symbol . set_ignore_placement ( * ignore_placement ) ;
2012-03-07 01:35:37 +01:00
}
point_placement_e placement =
2012-08-01 03:13:50 +02:00
sym . get_attr < point_placement_e > ( " placement " , symbol . get_point_placement ( ) ) ;
2012-03-16 01:50:55 +01:00
symbol . set_point_placement ( placement ) ;
2010-06-02 13:03:30 +02:00
2012-07-04 03:04:35 +02:00
if ( file & & ! file - > empty ( ) )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
if ( base )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
std : : map < std : : string , std : : string > : : const_iterator itr = file_sources_ . find ( * base ) ;
if ( itr ! = file_sources_ . end ( ) )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
* file = itr - > second + " / " + * file ;
2010-06-02 13:03:30 +02:00
}
2012-07-04 03:04:35 +02:00
}
2010-06-02 13:03:30 +02:00
2012-07-04 03:04:35 +02:00
* file = ensure_relative_to_xml ( file ) ;
2012-02-02 02:53:35 +01:00
2012-07-04 03:04:35 +02:00
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 + " ' " ) ;
}
2012-04-07 01:50:11 +02:00
2012-07-04 03:04:35 +02:00
symbol . set_filename ( expr ) ;
2011-02-01 09:16:32 +01:00
2012-07-04 03:04:35 +02:00
optional < std : : string > image_transform_wkt = sym . get_opt_attr < std : : string > ( " 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 ) )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
std : : stringstream ss ;
ss < < " Could not parse transform from ' " < < * image_transform_wkt
< < " ', expected transform attribute " ;
if ( strict_ )
2010-12-11 02:10:45 +01:00
{
2012-07-04 03:04:35 +02:00
throw config_error ( ss . str ( ) ) ; // value_error here?
}
else
{
MAPNIK_LOG_WARN ( load_map ) < < " map_parser: " < < ss ;
2010-12-11 02:10:45 +01:00
}
2010-06-02 13:03:30 +02:00
}
2012-07-04 03:04:35 +02:00
symbol . set_image_transform ( tl ) ;
2010-06-02 13:03:30 +02:00
}
2010-04-15 08:09:21 +02:00
}
2012-05-07 17:08:16 +02:00
parse_symbolizer_base ( symbol , sym ) ;
2012-03-07 01:35:37 +01:00
rule . append ( symbol ) ;
2010-04-09 20:47:19 +02:00
}
catch ( const config_error & ex )
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in PointSymbolizer " , sym ) ;
2010-06-02 13:03:30 +02:00
throw ;
2007-09-25 20:47:12 +02:00
}
2010-04-09 20:47:19 +02:00
}
2007-09-25 20:47:12 +02:00
2010-05-27 16:21:31 +02:00
2012-07-09 11:21:12 +02:00
void map_parser : : parse_markers_symbolizer ( rule & rule , xml_node const & node )
2010-05-27 16:21:31 +02:00
{
try
{
2010-05-30 05:16:51 +02:00
std : : string filename ( " " ) ;
2012-07-09 11:21:12 +02:00
optional < std : : string > file = node . get_opt_attr < std : : string > ( " file " ) ;
optional < std : : string > base = node . get_opt_attr < std : : string > ( " base " ) ;
2011-02-05 04:15:17 +01:00
2012-07-04 03:04:35 +02:00
if ( file & & ! file - > empty ( ) )
2010-05-30 05:16:51 +02:00
{
try
{
if ( base )
{
std : : map < std : : string , std : : string > : : const_iterator itr = file_sources_ . find ( * base ) ;
if ( itr ! = file_sources_ . end ( ) )
{
* file = itr - > second + " / " + * file ;
}
}
2011-01-25 21:47:56 +01:00
filename = ensure_relative_to_xml ( file ) ;
2010-05-30 05:16:51 +02:00
}
catch ( . . . )
{
2011-06-24 02:53:00 +02:00
std : : string msg ( " Failed to load marker file ' " + * file + " '! " ) ;
2010-05-30 05:16:51 +02:00
if ( strict_ )
{
throw config_error ( msg ) ;
}
else
{
2012-04-09 21:41:56 +02:00
MAPNIK_LOG_WARN ( load_map ) < < " map_parser: " < < msg ;
2010-05-30 05:16:51 +02:00
}
}
}
2010-05-27 16:21:31 +02:00
2012-07-11 07:38:53 +02:00
optional < std : : string > marker_type = node . get_opt_attr < std : : string > ( " marker-type " ) ;
if ( marker_type )
{
2012-07-13 04:21:04 +02:00
// TODO - before Mapnik 2.1 release change this from WARN TO ERROR
MAPNIK_LOG_WARN ( markers_symbolizer ) < < " 'marker-type' is deprecated and will be removed in Mapnik 3.x, use file='shape://<type>' to specify known svg shapes " ;
2012-07-11 07:38:53 +02:00
// back compatibility with Mapnik 2.0.0
if ( ! marker_type - > empty ( ) & & filename . empty ( ) )
{
if ( * marker_type = = " ellipse " )
{
filename = marker_cache : : known_svg_prefix_ + " ellipse " ;
}
else if ( * marker_type = = " arrow " )
{
filename = marker_cache : : known_svg_prefix_ + " arrow " ;
}
}
}
markers_symbolizer sym ;
2012-07-04 03:04:35 +02:00
if ( ! filename . empty ( ) )
2012-04-07 01:50:11 +02:00
{
2012-07-11 07:38:53 +02:00
path_expression_ptr expr ( boost : : make_shared < path_expression > ( ) ) ;
2012-07-09 11:21:12 +02:00
if ( ! parse_path_from_string ( expr , filename , node . get_tree ( ) . path_expr_grammar ) )
2012-07-04 03:04:35 +02:00
{
throw mapnik : : config_error ( " Failed to parse path_expression ' " + filename + " ' " ) ;
}
2012-07-11 07:38:53 +02:00
sym . set_filename ( expr ) ;
2012-04-07 01:50:11 +02:00
}
2012-07-31 03:31:21 +02:00
// overall opacity - impacts both fill and stroke, like svg
2012-07-09 11:21:12 +02:00
optional < float > opacity = node . get_opt_attr < float > ( " opacity " ) ;
if ( opacity ) sym . set_opacity ( * opacity ) ;
2012-05-01 17:47:33 +02:00
2012-07-31 03:31:21 +02:00
optional < float > fill_opacity = node . get_opt_attr < float > ( " fill-opacity " ) ;
if ( fill_opacity ) sym . set_fill_opacity ( * fill_opacity ) ;
2012-07-09 11:21:12 +02:00
optional < std : : string > image_transform_wkt = node . get_opt_attr < std : : string > ( " transform " ) ;
2012-05-01 17:47:33 +02:00
if ( image_transform_wkt )
2010-06-03 14:35:31 +02:00
{
2012-05-27 23:50:09 +02:00
mapnik : : transform_list_ptr tl = boost : : make_shared < mapnik : : transform_list > ( ) ;
2012-07-09 11:21:12 +02:00
if ( ! mapnik : : parse_transform ( * tl , * image_transform_wkt , node . get_tree ( ) . transform_expr_grammar ) )
2010-12-11 02:10:45 +01:00
{
std : : stringstream ss ;
2012-05-01 17:47:33 +02:00
ss < < " Could not parse transform from ' " < < * image_transform_wkt
2012-06-30 00:59:56 +02:00
< < " ', expected transform attribute " ;
2010-12-11 02:10:45 +01:00
if ( strict_ )
2012-04-08 02:20:56 +02:00
{
2010-12-11 02:10:45 +01:00
throw config_error ( ss . str ( ) ) ; // value_error here?
2012-04-08 02:20:56 +02:00
}
2010-12-11 02:10:45 +01:00
else
2012-04-08 02:20:56 +02:00
{
2012-04-09 21:41:56 +02:00
MAPNIK_LOG_WARN ( load_map ) < < " map_parser: " < < ss ;
2012-04-08 02:20:56 +02:00
}
2010-12-11 02:10:45 +01:00
}
2012-07-09 11:21:12 +02:00
sym . set_image_transform ( tl ) ;
2010-06-03 14:35:31 +02:00
}
2012-07-05 18:16:11 +02:00
2012-07-09 11:21:12 +02:00
optional < color > c = node . get_opt_attr < color > ( " fill " ) ;
if ( c ) sym . set_fill ( * c ) ;
optional < double > spacing = node . get_opt_attr < double > ( " spacing " ) ;
if ( spacing ) sym . set_spacing ( * spacing ) ;
optional < double > max_error = node . get_opt_attr < double > ( " max-error " ) ;
if ( max_error ) sym . set_max_error ( * max_error ) ;
optional < boolean > allow_overlap = node . get_opt_attr < boolean > ( " allow-overlap " ) ;
optional < boolean > ignore_placement = node . get_opt_attr < boolean > ( " ignore-placement " ) ;
if ( allow_overlap ) sym . set_allow_overlap ( * allow_overlap ) ;
if ( ignore_placement ) sym . set_ignore_placement ( * ignore_placement ) ;
2010-08-10 14:03:45 +02:00
2012-07-09 11:21:12 +02:00
optional < expression_ptr > width = node . get_opt_attr < expression_ptr > ( " width " ) ;
if ( width ) sym . set_width ( * width ) ;
2012-06-29 04:54:25 +02:00
2012-07-09 11:21:12 +02:00
optional < expression_ptr > height = node . get_opt_attr < expression_ptr > ( " height " ) ;
if ( height ) sym . set_height ( * height ) ;
2012-02-02 02:53:35 +01:00
2010-08-19 19:33:01 +02:00
stroke strk ;
2012-07-28 04:21:46 +02:00
if ( parse_stroke ( strk , node ) )
{
sym . set_stroke ( strk ) ;
}
2010-08-19 19:33:01 +02:00
2012-08-01 03:06:52 +02:00
marker_placement_e placement = node . get_attr < marker_placement_e > ( " placement " , sym . get_marker_placement ( ) ) ;
2012-07-09 11:21:12 +02:00
sym . set_marker_placement ( placement ) ;
parse_symbolizer_base ( sym , node ) ;
rule . append ( sym ) ;
2010-05-27 16:21:31 +02:00
}
2012-07-09 11:21:12 +02:00
catch ( config_error const & ex )
2010-05-27 16:21:31 +02:00
{
2012-07-09 11:21:12 +02:00
ex . append_context ( " in MarkersSymbolizer " , node ) ;
2010-05-30 05:16:51 +02:00
throw ;
2010-05-27 16:21:31 +02:00
}
}
2012-03-16 01:50:55 +01:00
void map_parser : : parse_line_pattern_symbolizer ( rule & rule , xml_node const & sym )
2010-04-09 20:47:19 +02:00
{
try
2007-09-25 20:47:12 +02:00
{
2012-03-07 01:35:37 +01:00
std : : string file = sym . get_attr < std : : string > ( " file " ) ;
2012-07-04 03:04:35 +02:00
if ( file . empty ( ) )
{
throw config_error ( " empty file attribute " ) ;
}
2012-03-07 01:35:37 +01:00
optional < std : : string > base = sym . get_opt_attr < std : : string > ( " base " ) ;
2012-02-02 02:53:35 +01:00
2012-07-04 03:04:35 +02:00
if ( base )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
std : : map < std : : string , std : : string > : : const_iterator itr = file_sources_ . find ( * base ) ;
if ( itr ! = file_sources_ . end ( ) )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
file = itr - > second + " / " + file ;
2010-06-02 13:03:30 +02:00
}
}
2012-07-04 03:04:35 +02:00
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 ) )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
throw mapnik : : config_error ( " Failed to parse path_expression ' " + file + " ' " ) ;
2010-06-02 13:03:30 +02:00
}
2012-07-04 03:04:35 +02:00
line_pattern_symbolizer symbol ( expr ) ;
parse_symbolizer_base ( symbol , sym ) ;
rule . append ( symbol ) ;
2007-09-25 20:47:12 +02:00
}
2010-04-09 20:47:19 +02:00
catch ( const config_error & ex )
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in LinePatternSymbolizer " , sym ) ;
2010-06-02 13:03:30 +02:00
throw ;
2010-04-09 20:47:19 +02:00
}
}
2007-09-25 20:47:12 +02:00
2012-03-16 01:50:55 +01:00
void map_parser : : parse_polygon_pattern_symbolizer ( rule & rule ,
2012-03-23 00:37:24 +01:00
xml_node const & sym )
2010-04-09 20:47:19 +02:00
{
try
2007-09-25 20:47:12 +02:00
{
2012-03-07 01:35:37 +01:00
std : : string file = sym . get_attr < std : : string > ( " file " ) ;
2012-02-02 02:53:35 +01:00
2012-07-04 03:04:35 +02:00
if ( file . empty ( ) )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
throw config_error ( " empty file attribute " ) ;
}
2011-01-25 21:47:56 +01:00
2012-07-04 03:04:35 +02:00
optional < std : : string > base = sym . get_opt_attr < std : : string > ( " base " ) ;
2010-06-21 00:36:49 +02:00
2012-07-04 03:04:35 +02:00
if ( base )
{
std : : map < std : : string , std : : string > : : iterator itr = file_sources_ . find ( * base ) ;
if ( itr ! = file_sources_ . end ( ) )
2012-04-07 01:50:11 +02:00
{
2012-07-04 03:04:35 +02:00
file = itr - > second + " / " + file ;
2012-04-07 01:50:11 +02:00
}
2012-07-04 03:04:35 +02:00
}
2011-06-29 00:37:35 +02:00
2012-07-04 03:04:35 +02:00
file = ensure_relative_to_xml ( file ) ;
2012-01-13 18:20:03 +01:00
2012-07-04 03:04:35 +02:00
path_expression_ptr expr ( boost : : make_shared < path_expression > ( ) ) ;
if ( ! parse_path_from_string ( expr , file , sym . get_tree ( ) . path_expr_grammar ) )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
throw mapnik : : config_error ( " Failed to parse path_expression ' " + file + " ' " ) ;
2010-06-02 13:03:30 +02:00
}
2012-07-04 03:04:35 +02:00
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 ) ;
2012-07-05 18:16:11 +02:00
2012-07-04 03:04:35 +02:00
// opacity
optional < double > opacity = sym . get_opt_attr < double > ( " opacity " ) ;
if ( opacity ) symbol . set_opacity ( * opacity ) ;
2012-07-05 18:16:11 +02:00
2012-07-04 03:04:35 +02:00
// 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 ) ;
2007-09-25 20:47:12 +02:00
}
2010-04-09 20:47:19 +02:00
catch ( const config_error & ex )
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in PolygonPatternSymbolizer " , sym ) ;
2010-06-02 13:03:30 +02:00
throw ;
2010-04-09 20:47:19 +02:00
}
}
2007-09-25 20:47:12 +02:00
2012-03-16 01:50:55 +01:00
void map_parser : : parse_text_symbolizer ( rule & rule , xml_node const & sym )
2010-04-09 20:47:19 +02:00
{
try
2007-09-25 20:47:12 +02:00
{
2011-02-28 14:17:46 +01:00
text_placements_ptr placement_finder ;
2012-03-07 01:35:37 +01:00
optional < std : : string > placement_type = sym . get_opt_attr < std : : string > ( " placement-type " ) ;
2011-02-28 14:17:46 +01:00
if ( placement_type ) {
2012-02-18 00:39:14 +01:00
placement_finder = placements : : registry : : instance ( ) - > from_xml ( * placement_type , sym , fontsets_ ) ;
} else {
2012-03-12 21:22:07 +01:00
placement_finder = boost : : make_shared < text_placements_dummy > ( ) ;
2012-02-18 00:39:14 +01:00
placement_finder - > defaults . from_xml ( sym , fontsets_ ) ;
2011-02-28 14:17:46 +01:00
}
2012-02-06 11:08:54 +01:00
if ( strict_ & &
2012-03-13 15:56:11 +01:00
! placement_finder - > defaults . format . fontset . size ( ) )
2012-03-21 00:40:07 +01:00
{
2012-02-16 00:17:22 +01:00
ensure_font_face ( placement_finder - > defaults . format . face_name ) ;
2012-03-21 00:40:07 +01:00
}
2012-01-29 04:49:02 +01:00
text_symbolizer text_symbol = text_symbolizer ( placement_finder ) ;
2012-05-07 17:08:16 +02:00
parse_symbolizer_base ( text_symbol , sym ) ;
2010-06-02 13:03:30 +02:00
rule . append ( text_symbol ) ;
2007-09-25 20:47:12 +02:00
}
2010-04-09 20:47:19 +02:00
catch ( const config_error & ex )
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in TextSymbolizer " , sym ) ;
2010-06-02 13:03:30 +02:00
throw ;
2010-04-09 20:47:19 +02:00
}
}
2007-09-25 20:47:12 +02:00
2012-03-16 01:50:55 +01:00
void map_parser : : parse_shield_symbolizer ( rule & rule , xml_node const & sym )
2010-04-09 20:47:19 +02:00
{
try
2007-09-25 20:47:12 +02:00
{
2012-01-29 04:49:02 +01:00
text_placements_ptr placement_finder ;
2012-03-07 01:35:37 +01:00
optional < std : : string > placement_type = sym . get_opt_attr < std : : string > ( " placement-type " ) ;
2012-01-29 04:49:02 +01:00
if ( placement_type ) {
2012-02-18 00:39:14 +01:00
placement_finder = placements : : registry : : instance ( ) - > from_xml ( * placement_type , sym , fontsets_ ) ;
} else {
2012-03-12 21:22:07 +01:00
placement_finder = boost : : make_shared < text_placements_dummy > ( ) ;
2012-01-29 04:49:02 +01:00
}
2012-02-16 00:17:22 +01:00
placement_finder - > defaults . from_xml ( sym , fontsets_ ) ;
2012-02-12 11:34:28 +01:00
if ( strict_ & &
2012-03-13 15:56:11 +01:00
! placement_finder - > defaults . format . fontset . size ( ) )
2012-03-21 00:40:07 +01:00
{
2012-02-16 00:17:22 +01:00
ensure_font_face ( placement_finder - > defaults . format . face_name ) ;
2012-03-21 00:40:07 +01:00
}
2012-01-29 04:49:02 +01:00
shield_symbolizer shield_symbol = shield_symbolizer ( placement_finder ) ;
2012-07-05 18:16:11 +02:00
2012-06-30 00:59:56 +02:00
optional < std : : string > image_transform_wkt = sym . get_opt_attr < std : : string > ( " transform " ) ;
2012-05-01 17:47:33 +02:00
if ( image_transform_wkt )
2012-01-22 04:21:01 +01:00
{
2012-05-27 23:50:09 +02:00
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 ) )
2012-01-22 04:21:01 +01:00
{
std : : stringstream ss ;
2012-07-05 18:16:11 +02:00
ss < < " Could not parse transform from ' " < < * image_transform_wkt
2012-06-30 00:59:56 +02:00
< < " ', expected transform attribute " ;
2012-01-22 04:21:01 +01:00
if ( strict_ )
2012-04-08 02:20:56 +02:00
{
2012-01-22 04:21:01 +01:00
throw config_error ( ss . str ( ) ) ; // value_error here?
2012-04-08 02:20:56 +02:00
}
2012-01-22 04:21:01 +01:00
else
2012-04-08 02:20:56 +02:00
{
2012-04-09 21:41:56 +02:00
MAPNIK_LOG_WARN ( load_map ) < < " map_parser: " < < ss ;
2012-04-08 02:20:56 +02:00
}
2012-01-22 04:21:01 +01:00
}
2012-05-27 23:50:09 +02:00
shield_symbol . set_image_transform ( tl ) ;
2012-01-22 04:21:01 +01:00
}
2012-07-05 18:16:11 +02:00
2012-01-22 04:21:01 +01:00
// shield displacement
2012-03-07 01:35:37 +01:00
double shield_dx = sym . get_attr ( " shield-dx " , 0.0 ) ;
double shield_dy = sym . get_attr ( " shield-dy " , 0.0 ) ;
2012-01-22 04:21:01 +01:00
shield_symbol . set_shield_displacement ( shield_dx , shield_dy ) ;
// opacity
2012-03-07 01:35:37 +01:00
optional < double > opacity = sym . get_opt_attr < double > ( " opacity " ) ;
2012-01-22 04:21:01 +01:00
if ( opacity )
{
shield_symbol . set_opacity ( * opacity ) ;
2011-09-16 02:02:42 +02:00
}
2010-06-02 13:03:30 +02:00
2012-01-22 04:21:01 +01:00
// text-opacity
// TODO: Could be problematic because it is named opacity in TextSymbolizer but opacity has a diffrent meaning here.
optional < double > text_opacity =
2012-03-07 01:35:37 +01:00
sym . get_opt_attr < double > ( " text-opacity " ) ;
2012-01-22 04:21:01 +01:00
if ( text_opacity )
{
2012-03-16 01:50:55 +01:00
shield_symbol . set_text_opacity ( * text_opacity ) ;
2012-01-22 04:21:01 +01:00
}
2010-06-02 13:03:30 +02:00
2012-01-22 04:21:01 +01:00
// unlock_image
optional < boolean > unlock_image =
2012-03-07 01:35:37 +01:00
sym . get_opt_attr < boolean > ( " unlock-image " ) ;
2012-01-22 04:21:01 +01:00
if ( unlock_image )
{
2012-03-16 01:50:55 +01:00
shield_symbol . set_unlock_image ( * unlock_image ) ;
2012-01-22 04:21:01 +01:00
}
2010-06-02 13:03:30 +02:00
2012-07-04 03:04:35 +02:00
std : : string file = sym . get_attr < std : : string > ( " file " ) ;
if ( file . empty ( ) )
{
throw config_error ( " empty file attribute " ) ;
}
2012-03-07 01:35:37 +01:00
optional < std : : string > base = sym . get_opt_attr < std : : string > ( " base " ) ;
2012-01-22 04:21:01 +01:00
2012-07-04 03:04:35 +02:00
if ( base )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
std : : map < std : : string , std : : string > : : const_iterator itr = file_sources_ . find ( * base ) ;
if ( itr ! = file_sources_ . end ( ) )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
file = itr - > second + " / " + file ;
2010-06-02 13:03:30 +02:00
}
}
2012-07-04 03:04:35 +02:00
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 ) )
2010-06-02 13:03:30 +02:00
{
2012-07-04 03:04:35 +02:00
throw mapnik : : config_error ( " Failed to parse path_expression ' " + file + " ' " ) ;
2010-06-02 13:03:30 +02:00
}
2012-07-04 03:04:35 +02:00
shield_symbol . set_filename ( expr ) ;
2012-07-06 02:10:00 +02:00
parse_symbolizer_base ( shield_symbol , sym ) ;
2012-01-22 04:21:01 +01:00
rule . append ( shield_symbol ) ;
2007-09-25 20:47:12 +02:00
}
2010-04-09 20:47:19 +02:00
catch ( const config_error & ex )
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in ShieldSymbolizer " , sym ) ;
2010-06-02 13:03:30 +02:00
throw ;
2010-04-09 20:47:19 +02:00
}
}
2007-09-25 20:47:12 +02:00
2012-07-28 04:21:46 +02:00
bool map_parser : : parse_stroke ( stroke & strk , xml_node const & sym )
2010-04-09 20:47:19 +02:00
{
2012-07-28 04:21:46 +02:00
bool result = false ;
2010-08-19 14:20:30 +02:00
// stroke color
2012-03-07 01:35:37 +01:00
optional < color > c = sym . get_opt_attr < color > ( " stroke " ) ;
2012-07-05 18:16:11 +02:00
if ( c )
{
2012-07-28 04:21:46 +02:00
result = true ;
2012-07-05 18:16:11 +02:00
strk . set_color ( * c ) ;
}
2011-05-17 02:33:24 +02:00
2010-08-19 14:20:30 +02:00
// stroke-width
2012-07-26 03:26:34 +02:00
optional < double > width = sym . get_opt_attr < double > ( " stroke-width " ) ;
2012-07-26 03:19:41 +02:00
if ( width )
2012-07-05 18:16:11 +02:00
{
2012-07-28 04:21:46 +02:00
result = true ;
2012-07-05 18:16:11 +02:00
strk . set_width ( * width ) ;
}
2011-05-17 02:33:24 +02:00
2010-08-19 14:20:30 +02:00
// stroke-opacity
2012-03-07 01:35:37 +01:00
optional < double > opacity = sym . get_opt_attr < double > ( " stroke-opacity " ) ;
2012-07-28 04:21:46 +02:00
if ( opacity )
{
result = true ;
strk . set_opacity ( * opacity ) ;
}
2011-05-17 02:33:24 +02:00
2010-08-19 14:20:30 +02:00
// stroke-linejoin
2012-03-07 01:35:37 +01:00
optional < line_join_e > line_join = sym . get_opt_attr < line_join_e > ( " stroke-linejoin " ) ;
2010-08-19 14:20:30 +02:00
if ( line_join ) strk . set_line_join ( * line_join ) ;
2011-05-17 02:33:24 +02:00
2010-08-19 14:20:30 +02:00
// stroke-linecap
2012-03-07 01:35:37 +01:00
optional < line_cap_e > line_cap = sym . get_opt_attr < line_cap_e > ( " stroke-linecap " ) ;
2010-08-19 14:20:30 +02:00
if ( line_cap ) strk . set_line_cap ( * line_cap ) ;
2011-05-17 02:33:24 +02:00
2011-02-02 02:46:14 +01:00
// stroke-gamma
2012-03-07 01:35:37 +01:00
optional < double > gamma = sym . get_opt_attr < double > ( " stroke-gamma " ) ;
2011-02-02 02:46:14 +01:00
if ( gamma ) strk . set_gamma ( * gamma ) ;
2011-05-17 02:33:24 +02:00
2012-01-13 18:20:03 +01:00
// stroke-gamma-method
2012-03-07 01:35:37 +01:00
optional < gamma_method_e > gamma_method = sym . get_opt_attr < gamma_method_e > ( " stroke-gamma-method " ) ;
2012-01-13 18:20:03 +01:00
if ( gamma_method ) strk . set_gamma_method ( * gamma_method ) ;
2011-09-13 16:51:51 +02:00
// stroke-dashoffset
2012-03-07 01:35:37 +01:00
optional < double > dash_offset = sym . get_opt_attr < double > ( " stroke-dashoffset " ) ;
2011-05-17 02:33:24 +02:00
if ( dash_offset ) strk . set_dash_offset ( * dash_offset ) ;
2010-08-19 14:20:30 +02:00
// stroke-dasharray
2012-03-07 01:35:37 +01:00
optional < std : : string > str = sym . get_opt_attr < std : : string > ( " stroke-dasharray " ) ;
2012-02-02 02:53:35 +01:00
if ( str )
2007-09-25 20:47:12 +02:00
{
2010-08-19 14:20:30 +02:00
std : : vector < double > dash_array ;
2012-03-23 12:56:23 +01:00
if ( util : : parse_dasharray ( ( * str ) . begin ( ) , ( * str ) . end ( ) , dash_array ) )
2010-06-02 13:03:30 +02:00
{
2012-03-23 12:56:23 +01:00
if ( ! dash_array . empty ( ) )
2010-08-19 14:20:30 +02:00
{
2012-03-23 12:56:23 +01:00
size_t size = dash_array . size ( ) ;
2012-04-05 18:04:11 +02:00
if ( size % 2 = = 1 )
2012-03-23 12:56:23 +01:00
dash_array . insert ( dash_array . end ( ) , dash_array . begin ( ) , dash_array . end ( ) ) ;
2012-04-05 18:04:11 +02:00
2012-03-23 12:56:23 +01:00
std : : vector < double > : : const_iterator pos = dash_array . begin ( ) ;
while ( pos ! = dash_array . end ( ) )
2010-06-02 13:03:30 +02:00
{
2012-04-05 18:04:11 +02:00
if ( * pos > 0.0 | | * ( pos + 1 ) > 0.0 ) // avoid both dash and gap eq 0.0
2012-03-23 12:56:23 +01:00
strk . add_dash ( * pos , * ( pos + 1 ) ) ;
pos + = 2 ;
2010-06-02 13:03:30 +02:00
}
2012-04-05 18:04:11 +02:00
}
2012-03-23 12:56:23 +01:00
}
else
{
throw config_error ( std : : string ( " Failed to parse dasharray " ) +
" '. Expected a " +
" list of floats or 'none' but got ' " + ( * str ) + " ' " ) ;
2010-06-02 13:03:30 +02:00
}
2010-08-19 14:20:30 +02:00
}
2012-07-05 18:16:11 +02:00
2012-05-02 18:04:24 +02:00
// stroke-miterlimit
optional < double > miterlimit = sym . get_opt_attr < double > ( " stroke-miterlimit " ) ;
if ( miterlimit ) strk . set_miterlimit ( * miterlimit ) ;
2012-07-28 04:21:46 +02:00
return result ;
2010-08-19 14:20:30 +02:00
}
2012-03-16 01:50:55 +01:00
void map_parser : : parse_line_symbolizer ( rule & rule , xml_node const & sym )
2010-08-19 14:20:30 +02:00
{
try
{
stroke strk ;
parse_stroke ( strk , sym ) ;
2010-08-10 14:03:45 +02:00
line_symbolizer symbol = line_symbolizer ( strk ) ;
2012-07-05 18:16:11 +02:00
2012-05-02 16:13:46 +02:00
// offset value
optional < double > offset = sym . get_opt_attr < double > ( " offset " ) ;
if ( offset ) symbol . set_offset ( * offset ) ;
2012-05-12 02:40:21 +02:00
line_rasterizer_e rasterizer = sym . get_attr < line_rasterizer_e > ( " rasterizer " , RASTERIZER_FULL ) ;
symbol . set_rasterizer ( rasterizer ) ;
2012-05-07 17:08:16 +02:00
parse_symbolizer_base ( symbol , sym ) ;
2010-08-10 14:03:45 +02:00
rule . append ( symbol ) ;
2007-09-25 20:47:12 +02:00
}
2010-04-09 20:47:19 +02:00
catch ( const config_error & ex )
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in LineSymbolizer " , sym ) ;
2010-06-02 13:03:30 +02:00
throw ;
2010-04-09 20:47:19 +02:00
}
}
2007-09-25 20:47:12 +02:00
2012-02-02 02:53:35 +01:00
2012-03-16 01:50:55 +01:00
void map_parser : : parse_polygon_symbolizer ( rule & rule , xml_node const & sym )
2010-04-09 20:47:19 +02:00
{
try
2007-09-25 20:47:12 +02:00
{
2010-06-02 13:03:30 +02:00
polygon_symbolizer poly_sym ;
// fill
2012-03-07 01:35:37 +01:00
optional < color > fill = sym . get_opt_attr < color > ( " fill " ) ;
2010-06-02 13:03:30 +02:00
if ( fill ) poly_sym . set_fill ( * fill ) ;
// fill-opacity
2012-03-07 01:35:37 +01:00
optional < double > opacity = sym . get_opt_attr < double > ( " fill-opacity " ) ;
2010-06-02 13:03:30 +02:00
if ( opacity ) poly_sym . set_opacity ( * opacity ) ;
// gamma
2012-03-07 01:35:37 +01:00
optional < double > gamma = sym . get_opt_attr < double > ( " gamma " ) ;
2010-06-02 13:03:30 +02:00
if ( gamma ) poly_sym . set_gamma ( * gamma ) ;
2012-01-12 16:58:10 +01:00
// gamma method
2012-03-07 01:35:37 +01:00
optional < gamma_method_e > gamma_method = sym . get_opt_attr < gamma_method_e > ( " gamma-method " ) ;
2012-01-13 18:20:03 +01:00
if ( gamma_method ) poly_sym . set_gamma_method ( * gamma_method ) ;
2012-07-05 18:16:11 +02:00
2012-05-07 17:08:16 +02:00
parse_symbolizer_base ( poly_sym , sym ) ;
2010-06-02 13:03:30 +02:00
rule . append ( poly_sym ) ;
2007-09-25 20:47:12 +02:00
}
2010-04-09 20:47:19 +02:00
catch ( const config_error & ex )
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in PolygonSymbolizer " , sym ) ;
2010-06-02 13:03:30 +02:00
throw ;
2010-04-09 20:47:19 +02:00
}
}
2012-03-16 01:50:55 +01:00
void map_parser : : parse_building_symbolizer ( rule & rule , xml_node const & sym )
2010-04-09 20:47:19 +02:00
{
2012-02-02 02:53:35 +01:00
try
2011-02-05 04:15:17 +01:00
{
2010-06-02 13:03:30 +02:00
building_symbolizer building_sym ;
// fill
2012-03-07 01:35:37 +01:00
optional < color > fill = sym . get_opt_attr < color > ( " fill " ) ;
2010-06-02 13:03:30 +02:00
if ( fill ) building_sym . set_fill ( * fill ) ;
// fill-opacity
2012-03-07 01:35:37 +01:00
optional < double > opacity = sym . get_opt_attr < double > ( " fill-opacity " ) ;
2010-06-02 13:03:30 +02:00
if ( opacity ) building_sym . set_opacity ( * opacity ) ;
// height
2012-03-11 23:24:28 +01:00
optional < expression_ptr > height = sym . get_opt_attr < expression_ptr > ( " height " ) ;
if ( height ) building_sym . set_height ( * height ) ;
2010-06-02 13:03:30 +02:00
2012-05-07 17:08:16 +02:00
parse_symbolizer_base ( building_sym , sym ) ;
2010-06-02 13:03:30 +02:00
rule . append ( building_sym ) ;
2010-04-09 20:47:19 +02:00
}
catch ( const config_error & ex )
2007-09-25 20:47:12 +02:00
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in BuildingSymbolizer " , sym ) ;
2010-06-02 13:03:30 +02:00
throw ;
Patch from David Eastcott :
1. Modified Text Symbolizer
a) corrected line fragment centering (for 2nd and subsequent lines, when line breaks occur).
b) adjusted vertical alignment calculation so that:
i) middle -> has the center of the text line(s) at the point origin
ii) bottom -> has the text line(s) below the point origin
iii) top -> has the text line(s) above the point origin
c) added new text_symbolizer attribute: 'wrap_before', value range: true/false, default == false
allows line breaks at first wrap_char before wrap_width as an alternative to the original
which was to create the line break at the first wrap_char after wrap_width
d) added new text_symbolizer attribute: 'horizontal_alignment', value range: left/middle/right, default == middle
i) left -> has all text line(s) to left of the point origin
ii) middle -> has all text line(s) centered on the the point origin
iii) right -> has all text line(s) to the right of the point origin
NOTE: dx, dy position adjustments are applied after alignments and before Justify.
e) added new text_symbolizer attribute: 'justify_alignment', value range: left/middle/right, default == middle
i) left -> after alignments, has all text line(s) are left justified (left to right reading)
ii) middle -> after alignments, has all text line(s) center justified
iii) right -> after alignments, has all text line(s) right justified (right to left reading)
f) added new text_symbolizer attribute: 'opacity', value range: 0.0 thru 1.0; 1.0 == fully opaque
g) modified positioning to compensate for both line_spacing and character_spacing, to ensure proper
centering of the text envelope. Also ensure that centering occurs correctly even if no wrapping
occurs. Line spacing is uniform and consistent and compensates for errors between text_size and
the actual size (ci.height is inconsistent, depending on case and character); fixes issue with
multi-line text where some lines have a slight gap and others are compressed together.
2. Modified shield_symbolizer
a) added the attributes:
i) allow_overlap
ii) vertical_alignment
iii) horizontal_alignment
iv) justify_alignment
v) wrap_width
vi) wrap_character
vii) wrap_before
viii) text_convert
ix) line_spacing
x) character_spacing
xi) opacity
b) added new shield_symbolizer attribute: 'unlock_image', value range: true/false, default == false
i) false == image and text placement behaviour same as before
ii) true == image placement independant of text, image is always centered at geometry point, text placed per attributes,
dx/dy only affect text.
Allows user to create point markers with text, but both the text and image rendering collision detection are done
as a pair (they come and go together - solves problem if using point_symbolizer and text_symbolizers where one or the
other are omitted due to overlaps, but not both)
c) extended choices for the attribute 'placement' to include vertex; effect is limited to the shield_symbolizer
Allows an attempted placement at every vertex available, gives additional shield placement volume when using line geometry
d) ensured that the text placement was not updating the detector unless a shield image was actually placed.
e) added new shield_symbolizer attribute: 'no_text', value range: true/false, default = false
When set true, the text for the feature is ignored ('space' subsituted) so that pure graphic symbols can be used
and no text is rendered over top of them.
2009-10-19 15:52:53 +02:00
}
2010-04-09 20:47:19 +02:00
}
2012-03-16 01:50:55 +01:00
void map_parser : : parse_raster_symbolizer ( rule & rule , xml_node const & sym )
2010-04-09 20:47:19 +02:00
{
try
{
2010-06-02 13:03:30 +02:00
raster_symbolizer raster_sym ;
// mode
2012-03-07 01:35:37 +01:00
optional < std : : string > mode = sym . get_opt_attr < std : : string > ( " mode " ) ;
2010-06-02 13:03:30 +02:00
if ( mode ) raster_sym . set_mode ( * mode ) ;
// scaling
2012-03-07 01:35:37 +01:00
optional < std : : string > scaling = sym . get_opt_attr < std : : string > ( " scaling " ) ;
2012-07-07 01:45:58 +02:00
if ( scaling )
{
std : : string scaling_method = * scaling ;
if ( scaling_method = = " fast " )
{
MAPNIK_LOG_ERROR ( raster_symbolizer ) < < " 'scaling' value of 'fast' is deprecated and will be removed in Mapnik 3.x, use 'near' with Mapnik >= 2.1.x " ;
raster_sym . set_scaling_method ( SCALING_NEAR ) ;
}
else
{
boost : : optional < scaling_method_e > method = scaling_method_from_string ( scaling_method ) ;
if ( method )
{
raster_sym . set_scaling_method ( * method ) ;
}
else
{
throw config_error ( " failed to parse 'scaling': ' " + * scaling + " ' " ) ;
}
}
}
2010-06-02 13:03:30 +02:00
// opacity
2012-03-07 01:35:37 +01:00
optional < double > opacity = sym . get_opt_attr < double > ( " opacity " ) ;
2010-06-02 13:03:30 +02:00
if ( opacity ) raster_sym . set_opacity ( * opacity ) ;
2011-01-27 04:47:54 +01:00
// filter factor
2012-03-07 01:35:37 +01:00
optional < double > filter_factor = sym . get_opt_attr < double > ( " filter-factor " ) ;
2011-01-27 04:47:54 +01:00
if ( filter_factor ) raster_sym . set_filter_factor ( * filter_factor ) ;
2011-09-16 14:21:21 +02:00
// mesh-size
2012-03-07 01:35:37 +01:00
optional < unsigned > mesh_size = sym . get_opt_attr < unsigned > ( " mesh-size " ) ;
2011-09-16 14:21:21 +02:00
if ( mesh_size ) raster_sym . set_mesh_size ( * mesh_size ) ;
2012-03-07 01:35:37 +01:00
xml_node : : const_iterator cssIter = sym . begin ( ) ;
xml_node : : const_iterator endCss = sym . end ( ) ;
2010-06-02 13:03:30 +02:00
for ( ; cssIter ! = endCss ; + + cssIter )
{
2012-03-07 01:35:37 +01:00
if ( cssIter - > is ( " RasterColorizer " ) )
2010-06-02 13:03:30 +02:00
{
2012-03-10 01:20:50 +01:00
raster_colorizer_ptr colorizer = boost : : make_shared < raster_colorizer > ( ) ;
2010-06-02 13:03:30 +02:00
raster_sym . set_colorizer ( colorizer ) ;
2012-03-07 01:35:37 +01:00
parse_raster_colorizer ( colorizer , * cssIter ) ;
2010-06-02 13:03:30 +02:00
}
}
2010-08-12 02:11:01 +02:00
//Note: raster_symbolizer doesn't support metawriters
2012-05-10 19:15:32 +02:00
parse_symbolizer_base ( raster_sym , sym ) ;
2010-06-02 13:03:30 +02:00
rule . append ( raster_sym ) ;
2010-04-09 20:47:19 +02:00
}
catch ( const config_error & ex )
2009-03-29 13:05:20 +02:00
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in RasterSymbolizer " , sym ) ;
2010-06-02 13:03:30 +02:00
throw ;
2010-03-12 15:49:34 +01:00
}
2010-04-09 20:47:19 +02:00
}
2010-03-19 12:19:43 +01:00
2010-04-09 20:47:19 +02:00
void map_parser : : parse_raster_colorizer ( raster_colorizer_ptr const & rc ,
2012-03-12 01:09:26 +01:00
xml_node const & node )
2010-04-09 20:47:19 +02:00
{
try
{
2011-05-04 02:20:17 +02:00
// mode
colorizer_mode default_mode =
2012-03-07 01:35:37 +01:00
node . get_attr < colorizer_mode > ( " default-mode " , COLORIZER_LINEAR ) ;
2012-02-02 02:53:35 +01:00
2011-05-04 02:20:17 +02:00
if ( default_mode = = COLORIZER_INHERIT ) {
throw config_error ( " RasterColorizer mode must not be INHERIT. " ) ;
}
2012-03-16 01:50:55 +01:00
rc - > set_default_mode ( default_mode ) ;
2010-06-02 13:03:30 +02:00
2011-05-04 02:20:17 +02:00
// default colour
2012-03-07 01:35:37 +01:00
optional < color > default_color = node . get_opt_attr < color > ( " default-color " ) ;
2012-02-02 02:53:35 +01:00
if ( default_color )
2010-06-02 13:03:30 +02:00
{
2012-03-16 01:50:55 +01:00
rc - > set_default_color ( * default_color ) ;
2011-05-04 02:20:17 +02:00
}
2012-02-02 02:53:35 +01:00
2011-05-04 02:20:17 +02:00
// epsilon
2012-03-07 01:35:37 +01:00
optional < float > eps = node . get_opt_attr < float > ( " epsilon " ) ;
2012-02-02 02:53:35 +01:00
if ( eps )
2011-05-04 02:20:17 +02:00
{
if ( * eps < 0 ) {
throw config_error ( " RasterColorizer epsilon must be > 0. " ) ;
}
2012-03-16 01:50:55 +01:00
rc - > set_epsilon ( * eps ) ;
2011-05-04 02:20:17 +02:00
}
2012-02-02 02:53:35 +01:00
2012-03-07 01:35:37 +01:00
xml_node : : const_iterator stopIter = node . begin ( ) ;
xml_node : : const_iterator endStop = node . end ( ) ;
2011-05-04 02:20:17 +02:00
float maximumValue = - std : : numeric_limits < float > : : max ( ) ;
2010-06-02 13:03:30 +02:00
2011-05-04 02:20:17 +02:00
for ( ; stopIter ! = endStop ; + + stopIter )
{
2012-03-07 01:35:37 +01:00
if ( stopIter - > is ( " stop " ) )
2010-06-02 13:03:30 +02:00
{
2011-05-04 02:20:17 +02:00
// colour is optional.
2012-03-07 01:35:37 +01:00
optional < color > stopcolor = stopIter - > get_opt_attr < color > ( " color " ) ;
2011-05-04 02:20:17 +02:00
if ( ! stopcolor ) {
* stopcolor = * default_color ;
}
// mode default to INHERIT
colorizer_mode mode =
2012-03-07 01:35:37 +01:00
stopIter - > get_attr < colorizer_mode > ( " mode " , COLORIZER_INHERIT ) ;
2011-05-04 02:20:17 +02:00
// value is required, and it must be bigger than the previous
optional < float > value =
2012-03-07 01:35:37 +01:00
stopIter - > get_opt_attr < float > ( " value " ) ;
2012-02-02 02:53:35 +01:00
2011-05-04 02:20:17 +02:00
if ( ! value ) {
throw config_error ( " stop tag missing value " ) ;
2010-06-02 13:03:30 +02:00
}
2012-02-02 02:53:35 +01:00
2011-05-04 02:20:17 +02:00
if ( value < maximumValue ) {
throw config_error ( " stop tag values must be in ascending order " ) ;
2010-06-02 13:03:30 +02:00
}
2011-05-04 02:20:17 +02:00
maximumValue = * value ;
2011-09-16 15:32:16 +02:00
optional < std : : string > label =
2012-03-13 15:56:11 +01:00
stopIter - > get_opt_attr < std : : string > ( " label " ) ;
2011-05-04 02:20:17 +02:00
//append the stop
colorizer_stop tmpStop ;
tmpStop . set_color ( * stopcolor ) ;
tmpStop . set_mode ( mode ) ;
tmpStop . set_value ( * value ) ;
2011-09-16 15:32:16 +02:00
if ( label )
tmpStop . set_label ( * label ) ;
2012-02-02 02:53:35 +01:00
2011-05-04 02:20:17 +02:00
rc - > add_stop ( tmpStop ) ;
2010-06-02 13:03:30 +02:00
}
2010-05-06 09:21:11 +02:00
}
2010-04-09 20:47:19 +02:00
}
catch ( const config_error & ex )
2007-09-25 20:47:12 +02:00
{
2012-03-12 01:09:26 +01:00
ex . append_context ( " in RasterColorizer " , node ) ;
2010-06-02 13:03:30 +02:00
throw ;
2007-09-25 20:47:12 +02:00
}
2010-04-09 20:47:19 +02:00
}
Patch from David Eastcott :
1. Modified Text Symbolizer
a) corrected line fragment centering (for 2nd and subsequent lines, when line breaks occur).
b) adjusted vertical alignment calculation so that:
i) middle -> has the center of the text line(s) at the point origin
ii) bottom -> has the text line(s) below the point origin
iii) top -> has the text line(s) above the point origin
c) added new text_symbolizer attribute: 'wrap_before', value range: true/false, default == false
allows line breaks at first wrap_char before wrap_width as an alternative to the original
which was to create the line break at the first wrap_char after wrap_width
d) added new text_symbolizer attribute: 'horizontal_alignment', value range: left/middle/right, default == middle
i) left -> has all text line(s) to left of the point origin
ii) middle -> has all text line(s) centered on the the point origin
iii) right -> has all text line(s) to the right of the point origin
NOTE: dx, dy position adjustments are applied after alignments and before Justify.
e) added new text_symbolizer attribute: 'justify_alignment', value range: left/middle/right, default == middle
i) left -> after alignments, has all text line(s) are left justified (left to right reading)
ii) middle -> after alignments, has all text line(s) center justified
iii) right -> after alignments, has all text line(s) right justified (right to left reading)
f) added new text_symbolizer attribute: 'opacity', value range: 0.0 thru 1.0; 1.0 == fully opaque
g) modified positioning to compensate for both line_spacing and character_spacing, to ensure proper
centering of the text envelope. Also ensure that centering occurs correctly even if no wrapping
occurs. Line spacing is uniform and consistent and compensates for errors between text_size and
the actual size (ci.height is inconsistent, depending on case and character); fixes issue with
multi-line text where some lines have a slight gap and others are compressed together.
2. Modified shield_symbolizer
a) added the attributes:
i) allow_overlap
ii) vertical_alignment
iii) horizontal_alignment
iv) justify_alignment
v) wrap_width
vi) wrap_character
vii) wrap_before
viii) text_convert
ix) line_spacing
x) character_spacing
xi) opacity
b) added new shield_symbolizer attribute: 'unlock_image', value range: true/false, default == false
i) false == image and text placement behaviour same as before
ii) true == image placement independant of text, image is always centered at geometry point, text placed per attributes,
dx/dy only affect text.
Allows user to create point markers with text, but both the text and image rendering collision detection are done
as a pair (they come and go together - solves problem if using point_symbolizer and text_symbolizers where one or the
other are omitted due to overlaps, but not both)
c) extended choices for the attribute 'placement' to include vertex; effect is limited to the shield_symbolizer
Allows an attempted placement at every vertex available, gives additional shield placement volume when using line geometry
d) ensured that the text placement was not updating the detector unless a shield image was actually placed.
e) added new shield_symbolizer attribute: 'no_text', value range: true/false, default = false
When set true, the text for the feature is ignored ('space' subsituted) so that pure graphic symbols can be used
and no text is rendered over top of them.
2009-10-19 15:52:53 +02:00
2012-03-16 01:50:55 +01:00
void map_parser : : ensure_font_face ( std : : string const & face_name )
2010-04-09 20:47:19 +02:00
{
2012-03-16 01:50:55 +01:00
if ( ! font_manager_ . get_face ( face_name ) )
2009-05-01 03:59:01 +02:00
{
2010-06-02 13:03:30 +02:00
throw config_error ( " Failed to find font face ' " +
face_name + " ' " ) ;
2010-04-09 20:47:19 +02:00
}
}
2012-03-16 01:50:55 +01:00
std : : string map_parser : : ensure_relative_to_xml ( boost : : optional < std : : string > opt_path )
2010-04-09 20:47:19 +02:00
{
2012-07-11 07:38:53 +02:00
if ( marker_cache : : is_uri ( * opt_path ) )
return * opt_path ;
2011-01-25 21:47:56 +01:00
if ( relative_to_xml_ )
2011-01-04 16:22:49 +01:00
{
2011-01-25 21:47:56 +01:00
boost : : filesystem : : path xml_path = filename_ ;
boost : : filesystem : : path rel_path = * opt_path ;
2012-03-16 01:50:55 +01:00
if ( ! rel_path . has_root_path ( ) )
2011-01-25 21:47:56 +01:00
{
2012-02-02 02:53:35 +01:00
# if (BOOST_FILESYSTEM_VERSION == 3)
2011-05-26 01:48:07 +02:00
// TODO - normalize is now deprecated, use make_preferred?
boost : : filesystem : : path full = boost : : filesystem : : absolute ( xml_path . parent_path ( ) / rel_path ) ;
2012-02-02 02:53:35 +01:00
# else // v2
2011-01-25 21:47:56 +01:00
boost : : filesystem : : path full = boost : : filesystem : : complete ( xml_path . branch_path ( ) / rel_path ) . normalize ( ) ;
2012-02-02 02:53:35 +01:00
# endif
2012-04-09 21:41:56 +02:00
MAPNIK_LOG_DEBUG ( load_map ) < < " map_parser: Modifying relative paths to be relative to xml... " ;
MAPNIK_LOG_DEBUG ( load_map ) < < " map_parser: -- Original base path= " < < * opt_path ;
MAPNIK_LOG_DEBUG ( load_map ) < < " map_parser: -- Relative base path= " < < full . string ( ) ;
2011-01-25 21:47:56 +01:00
return full . string ( ) ;
}
2009-05-01 03:59:01 +02:00
}
2010-04-09 20:47:19 +02:00
return * opt_path ;
}
2009-05-01 03:59:01 +02:00
2012-03-12 02:12:58 +01:00
void map_parser : : find_unused_nodes ( xml_node const & root )
2011-02-05 04:15:17 +01:00
{
2012-03-12 02:12:58 +01:00
std : : stringstream error_message ;
find_unused_nodes_recursive ( root , error_message ) ;
if ( ! error_message . str ( ) . empty ( ) )
2011-02-05 04:15:17 +01:00
{
2012-03-12 02:12:58 +01:00
throw config_error ( " The following nodes or attributes were not processed while parsing the xml file: " + error_message . str ( ) ) ;
}
}
void map_parser : : find_unused_nodes_recursive ( xml_node const & node , std : : stringstream & error_message )
{
if ( ! node . processed ( ) )
{
if ( node . is_text ( ) ) {
error_message < < " \n * text ' " < < node . text ( ) < < " ' " ;
} else {
error_message < < " \n * node ' " < < node . name ( ) < < " ' in line " < < node . line ( ) ;
2011-12-01 01:48:01 +01:00
}
2012-03-12 02:12:58 +01:00
return ; //All attributes and children are automatically unprocessed, too.
}
xml_node : : attribute_map const & attr = node . get_attributes ( ) ;
xml_node : : attribute_map : : const_iterator aitr = attr . begin ( ) ;
xml_node : : attribute_map : : const_iterator aend = attr . end ( ) ;
for ( ; aitr ! = aend ; aitr + + )
{
if ( ! aitr - > second . processed )
{
error_message < < " \n * attribute ' " < < aitr - > first < <
2012-03-13 15:56:11 +01:00
" ' with value ' " < < aitr - > second . value < <
" ' in line " < < node . line ( ) ;
2011-12-01 01:48:01 +01:00
}
}
2012-03-12 02:12:58 +01:00
xml_node : : const_iterator itr = node . begin ( ) ;
xml_node : : const_iterator end = node . end ( ) ;
for ( ; itr ! = end ; itr + + )
{
find_unused_nodes_recursive ( * itr , error_message ) ;
}
2011-02-05 04:15:17 +01:00
}
2007-09-25 20:47:12 +02:00
} // end of namespace mapnik