+ add support to polygon_patter_symbolizer for global pattern alignment in addition to local/feature (default) alignment - closes #203

This commit is contained in:
Dane Springmeyer 2010-06-20 22:36:49 +00:00
parent 0e68514142
commit 0959f8ef16
9 changed files with 153 additions and 15 deletions

View file

@ -14,6 +14,8 @@ For a complete change history, see the SVN log.
Mapnik Trunk
------------
- Added support for setting global alignment of polygon pattern fills (#203)
- Added support for choosing OGR layer by index number using 'layer_by_index' parameter (r1904)
- Added support for reading jpeg images (in addition to png/tiff) for image symbolizers (#518)

View file

@ -658,9 +658,15 @@ __all__ = [
'TextSymbolizer',
'ViewTransform',
# enums
'aspect_fix_mode', 'label_placement',
'line_cap', 'line_join',
'text_convert', 'vertical_alignment',
'aspect_fix_mode',
'label_placement',
'line_cap',
'line_join',
'text_convert',
'vertical_alignment',
'horizontal_alignment',
'justify_alignment',
'pattern_alignment',
# functions
# datasources
'Datasource', 'CreateDatasource',

View file

@ -24,8 +24,10 @@
#include <boost/python.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/polygon_pattern_symbolizer.hpp>
#include "mapnik_enumeration.hpp"
#include <mapnik/parse_path.hpp>
using namespace mapnik;
using mapnik::polygon_pattern_symbolizer;
using mapnik::path_expression_ptr;
using mapnik::path_processor_type;
@ -39,13 +41,47 @@ struct polygon_pattern_symbolizer_pickle_suite : boost::python::pickle_suite
std::string filename = path_processor_type::to_string(*p.get_filename());
return boost::python::make_tuple(filename,guess_type(filename));
}
static boost::python::tuple
getstate(const polygon_pattern_symbolizer& p)
{
return boost::python::make_tuple(p.get_alignment());
}
static void
setstate (polygon_pattern_symbolizer& p, boost::python::tuple state)
{
using namespace boost::python;
if (len(state) != 1)
{
PyErr_SetObject(PyExc_ValueError,
("expected 1-item tuple in call to __setstate__; got %s"
% state).ptr()
);
throw_error_already_set();
}
p.set_alignment(extract<pattern_alignment_e>(state[0]));
}
};
void export_polygon_pattern_symbolizer()
{
using namespace boost::python;
enumeration_<pattern_alignment_e>("pattern_alignment")
.value("LOCAL",LOCAL_ALIGNMENT)
.value("GLOBAL",GLOBAL_ALIGNMENT)
;
class_<polygon_pattern_symbolizer>("PolygonPatternSymbolizer",
init<path_expression_ptr>("<path_expression_ptr>"))
.def_pickle(polygon_pattern_symbolizer_pickle_suite()) ;
.def_pickle(polygon_pattern_symbolizer_pickle_suite())
.add_property("pattern_alignment",
&polygon_pattern_symbolizer::get_alignment,
&polygon_pattern_symbolizer::set_alignment,
"Set/get the alignment of the pattern")
;
}

View file

@ -26,15 +26,32 @@
// mapnik
#include <mapnik/symbolizer.hpp>
#include <mapnik/stroke.hpp>
#include <mapnik/filter_factory.hpp>
namespace mapnik
{
enum pattern_alignment_enum {
LOCAL_ALIGNMENT,
GLOBAL_ALIGNMENT,
pattern_alignment_enum_MAX
};
DEFINE_ENUM( pattern_alignment_e, pattern_alignment_enum );
struct MAPNIK_DECL polygon_pattern_symbolizer :
public symbolizer_with_image
{
polygon_pattern_symbolizer(path_expression_ptr file);
polygon_pattern_symbolizer(polygon_pattern_symbolizer const& rhs);
pattern_alignment_e get_alignment() const;
void set_alignment(pattern_alignment_e align);
private:
pattern_alignment_e alignment_;
};
}

View file

@ -85,15 +85,24 @@ void agg_renderer<T>::process(polygon_pattern_symbolizer const& sym,
agg::row_accessor<agg::int8u>, agg::pixel32_type> pixf_pattern(pattern_rbuf);
img_source_type img_src(pixf_pattern);
double x0=0,y0=0;
unsigned num_geometries = feature.num_geometries();
if (num_geometries>0)
pattern_alignment_e align = sym.get_alignment();
unsigned offset_x=0;
unsigned offset_y=0;
if (align == LOCAL_ALIGNMENT)
{
path_type path(t_,feature.get_geometry(0),prj_trans);
path.vertex(&x0,&y0);
double x0=0,y0=0;
if (num_geometries>0)
{
path_type path(t_,feature.get_geometry(0),prj_trans);
path.vertex(&x0,&y0);
}
offset_x = unsigned(width_-x0);
offset_y = unsigned(height_-y0);
}
unsigned offset_x = unsigned(width_-x0);
unsigned offset_y = unsigned(height_-y0);
span_gen_type sg(img_src, offset_x, offset_y);
renderer_type rp(renb,sa, sg);
for (unsigned i=0;i<num_geometries;++i)

View file

@ -914,8 +914,13 @@ void map_parser::parse_polygon_pattern_symbolizer( rule_type & rule,
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
}
#endif
polygon_pattern_symbolizer symbol(parse_path(file));
// pattern alignment
pattern_alignment_e p_alignment = get_attr<pattern_alignment_e>(sym, "alignment",LOCAL_ALIGNMENT);
symbol.set_alignment(p_alignment);
rule.append(symbol);
}
catch (image_reader_exception const & ex )

View file

@ -26,14 +26,32 @@
namespace mapnik
{
static const char * pattern_alignment_strings[] = {
"local", // feature
"global", // map
""
};
IMPLEMENT_ENUM( pattern_alignment_e, pattern_alignment_strings );
polygon_pattern_symbolizer::polygon_pattern_symbolizer(path_expression_ptr file)
: symbolizer_with_image(file)
{
}
: symbolizer_with_image(file),
alignment_(LOCAL_ALIGNMENT) {}
polygon_pattern_symbolizer::polygon_pattern_symbolizer(polygon_pattern_symbolizer const& rhs)
: symbolizer_with_image(rhs) {}
: symbolizer_with_image(rhs),
alignment_(rhs.alignment_) {}
pattern_alignment_e polygon_pattern_symbolizer::get_alignment() const
{
return alignment_;
}
void polygon_pattern_symbolizer::set_alignment(pattern_alignment_e align)
{
alignment_ = align;
}
}

View file

@ -172,6 +172,12 @@ public:
ptree & sym_node = rule_.push_back(
ptree::value_type("PolygonPatternSymbolizer",
ptree()))->second;
polygon_pattern_symbolizer dfl(parse_path(""));
if ( sym.get_alignment() != dfl.get_alignment() || explicit_defaults_ )
{
set_attr( sym_node, "alignment", sym.get_alignment() );
}
add_image_attributes( sym_node, sym );
}

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Map srs="+proj=longlat +ellps=airy +datum=OSGB36 +no_defs">
<FileSource name="foo">../images/</FileSource>
<Style name="1">
<Rule>
<Filter>([EAS_ID]&lt;=170) and ([EAS_ID] &lt;&gt; 165)</Filter>
<!-- alignment="local" is default -->
<PolygonPatternSymbolizer
alignment="local"
file="../images/checker.jpg"
/>
<LineSymbolizer stroke="green" stroke-width="2"/>
<TextSymbolizer face_name="DejaVu Sans Book" size="10"
name="'local'" halo_radius="1" dy="20"/>
</Rule>
<Rule>
<ElseFilter />
<PolygonPatternSymbolizer
alignment="global"
file="../images/checker.jpg"
/>
<LineSymbolizer stroke="yellow" stroke-width=".5"/>
<TextSymbolizer face_name="DejaVu Sans Book" size="10"
name="'global'" halo_radius="1" dy="20"/>
</Rule>
</Style>
<Layer name="lay" srs="+proj=longlat +ellps=airy +datum=OSGB36 +no_defs ">
<StyleName>1</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="base">../../data/shp/</Parameter>
<Parameter name="file">poly.shp</Parameter>
</Datasource>
</Layer>
</Map>