add test for grid generation, and make sure point_datasource feature id starts at 1 (as datasources should)

This commit is contained in:
Dane Springmeyer 2011-04-29 19:25:00 +00:00
parent da4893d8fe
commit ab94fd43d8
4 changed files with 45 additions and 3 deletions

View File

@ -79,6 +79,8 @@ public:
step_(step),
//feature_count_(0),
id_name_("__id__") {
// this only works if each datasource's
// feature count starts at 1
f_keys_[0] = "";
}

View File

@ -56,12 +56,13 @@ private:
class MAPNIK_DECL point_datasource : public memory_datasource {
public:
point_datasource() : feat_id_(0) {}
point_datasource() :
feature_id_(1) {}
void add_point(double x, double y, const char* key, const char* value);
inline int type() const { return datasource::Vector; }
private:
int feat_id_;
int feature_id_;
};
}

View File

@ -109,7 +109,8 @@ size_t memory_datasource::size() const
void point_datasource::add_point(double x, double y, const char* key, const char* value)
{
feature_ptr feature(feature_factory::create(feat_id_++));
feature_ptr feature(feature_factory::create(feature_id_));
++feature_id_;
geometry_type * pt = new geometry_type(Point);
pt->move_to(x,y);
feature->add_geometry(pt);

View File

@ -82,6 +82,43 @@ def test_render_from_serialization():
i,i2 = get_paired_images(100,100,'../data/good_maps/polygon_symbolizer.xml')
eq_(i.tostring(),i2.tostring())
grid_correct = {"keys": ["", "North West", "North East", "South West", "South East"], "data": {"South East": {"Name": "South East"}, "North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!! ### ", " !!!!! ##### ", " !!!!! ##### ", " !!! ### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$$ %%%%% ", " $$$$$ %%%%% ", " $$$ %%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
def test_render_grid():
places_ds = mapnik2.PointDatasource()
places_ds.add_point(143.10,-38.60,'Name','South East')
places_ds.add_point(142.48,-38.60,'Name','South West')
places_ds.add_point(142.48,-38.38,'Name','North West')
places_ds.add_point(143.10,-38.38,'Name','North East')
s = mapnik2.Style()
r = mapnik2.Rule()
#symb = mapnik2.PointSymbolizer()
symb = mapnik2.MarkersSymbolizer()
symb.allow_overlap = True
r.symbols.append(symb)
label = mapnik2.TextSymbolizer(mapnik2.Expression('[Name]'),
'DejaVu Sans Book',
10,
mapnik2.Color('black')
)
label.allow_overlap = True
label.displacement = (0,-10)
#r.symbols.append(label)
s.rules.append(r)
lyr = mapnik2.Layer('Places')
lyr.datasource = places_ds
lyr.styles.append('places_labels')
m = mapnik2.Map(256,256)
m.append_style('places_labels',s)
m.layers.append(lyr)
ul_lonlat = mapnik2.Coord(142.30,-38.20)
lr_lonlat = mapnik2.Coord(143.40,-38.80)
m.zoom_to_box(mapnik2.Box2d(ul_lonlat,lr_lonlat))
grid = mapnik2.render_grid(m,0,'Name',4,fields=['Name','__id__'])
eq_(grid,grid_correct)
def test_render_points():
if not mapnik2.has_cairo(): return
@ -124,3 +161,4 @@ def test_render_points():
num_points_rendered = svg.count('<image ')
eq_(num_points_present, num_points_rendered, "Not all points were rendered (%d instead of %d) at projection %s" % (num_points_rendered, num_points_present, projdescr))