def addFeatures(self, item, extent): for polygon_el in item.findall('polygon'): feature = mapnik.Feature(self.ids.next()) for k in polygon_el.keys(): feature[k] = polygon_el.get(k) feature.add_geometries_from_wkb( shapely.geometry.Polygon([(extent[0], extent[1]), (extent[2], extent[1]), (extent[2], extent[3]), (extent[0], extent[3]), (extent[0], extent[1])]).wkb) self.datasource.add_feature(feature) for line_el in item.findall('line'): feature = mapnik.Feature(self.ids.next()) for k in line_el.keys(): feature[k] = line_el.get(k) feature.add_geometries_from_wkb( shapely.geometry.LineString([(extent[0], 0), (0, 0), (extent[2], 0)]).wkb) self.datasource.add_feature(feature) for point_el in item.findall('point'): feature = mapnik.Feature(self.ids.next()) for k in point_el.keys(): feature[k] = point_el.get(k) feature.add_geometries_from_wkb(shapely.geometry.Point(0, 0).wkb) self.datasource.add_feature(feature)
def test_unicode_regex_replace(): f = mapnik2.Feature(0) f["name"] = 'Québec' expr = mapnik2.Expression("[name].replace('(\B)|( )','$1 ')") eq_(expr.evaluate(f), 'Q u é b e c')
def test_unicode_regex_match(): f = mapnik2.Feature(0) f["name"] = 'Québec' expr = mapnik2.Expression("[name].match('Québec')") eq_(expr.evaluate(f), '1') # 1 == True