def test_geojson_parsing_reversed(): path = mapnik.Path() path2 = mapnik.Path() count = 0 for idx, json in enumerate(geojson_reversed): count += json[0] path.add_geojson(json[1]) path2.add_geojson(geojson[idx][1]) eq_(path.to_geojson(), path2.to_geojson()) eq_(count, len(path))
def test_geojson_point_positions(): input_json = '{"type":"Point","coordinates":[30,10]}' path = mapnik.Path() path.add_geojson(input_json) eq_(path.to_geojson(), input_json) path = mapnik.Path() # should ignore all but the first two path.add_geojson('{"type":"Point","coordinates":[30,10,50,50,50,50]}') eq_(path.to_geojson(), input_json)
def test_geojson_point_positions(): input_json = '{"type":"LineString","coordinates":[[30,10],[10,30],[40,40]]}' path = mapnik.Path() path.add_geojson(input_json) eq_(path.to_geojson(), input_json) path = mapnik.Path() # should ignore all but the first two path.add_geojson( '{"type":"LineString","coordinates":[[30.0,10.0,0,0,0],[10.0,30.0,0,0,0],[40.0,40.0,0,0,0]]}' ) eq_(path.to_geojson(), input_json)
def compare_wkb_from_wkt(wkt,num=None): # create a Path from geometry(s) # easy api, but slower #paths = mapnik.Path.from_wkt(wkt) # fast api paths = reader.read(wkt); # add geometry(s) to feature from wkt f = mapnik.Feature(mapnik.Context(),1) f.add_geometries_from_wkt(wkt) # ensure both have same result # compare number of geometry parts if num: eq_(len(paths),num) eq_(len(f.geometries()),num) # compare collection off all geometries eq_(paths.to_wkb(mapnik.wkbByteOrder.XDR),f.geometries().to_wkb(mapnik.wkbByteOrder.XDR)) # compare all parts for idx,path in enumerate(paths): eq_(f.geometries()[idx].to_wkb(mapnik.wkbByteOrder.XDR),path.to_wkb(mapnik.wkbByteOrder.XDR)) # compare round trip paths2 = mapnik.Path() for path in paths: paths2.add_wkb(path.to_wkb(mapnik.wkbByteOrder.XDR)) # ensure result if num: eq_(len(paths2),num) eq_(paths2.to_wkb(mapnik.wkbByteOrder.XDR),paths.to_wkb(mapnik.wkbByteOrder.XDR)) for idx,path in enumerate(paths2): eq_(f.geometries()[idx].to_wkb(mapnik.wkbByteOrder.XDR),path.to_wkb(mapnik.wkbByteOrder.XDR))
def compare_wkt_from_wkt(wkt, num=None): paths = mapnik.Path.from_wkt(wkt) # add geometry(s) to feature from wkt f = mapnik.Feature(mapnik.Context(), 1) f.add_geometries_from_wkt(wkt) # compare to original, which may not have significant digits if '.' not in wkt: eq_(f.geometries().to_wkt().upper().replace('.0', ''), wkt) else: eq_(f.geometries().to_wkt().upper(), wkt) # ensure both have same result if num: eq_(len(paths), num) eq_(len(f.geometries()), num) eq_(paths.to_wkt(), f.geometries().to_wkt()) for idx, path in enumerate(paths): eq_(f.geometries()[idx].to_wkt(), path.to_wkt()) # compare round trip paths2 = mapnik.Path() for path in paths: paths2.add_wkt(path.to_wkt()) # ensure result if num: eq_(len(paths2), num) eq_(paths2.to_wkt(), paths.to_wkt()) for idx, path in enumerate(paths2): eq_(f.geometries()[idx].to_wkb(mapnik.wkbByteOrder.XDR), path.to_wkb(mapnik.wkbByteOrder.XDR))
def test_geojson_parsing(): path = mapnik.Path() count = 0 for json in geojson: count += json[0] path.add_geojson(json[1]) eq_(count, len(path))
def test_geojson_parsing(): path = mapnik.Path() count = 0 for json in geojson: count += json[0] try : path.add_geojson(json[1]) except RuntimeError: pass eq_(count,len(path))
def test_wkb_parsing(): path = mapnik.Path() count = 0 for wkb in wkbs: count += wkb[0] try : path.add_wkb(unhexlify(wkb[2])) except RuntimeError: pass eq_(count,len(path))
def test_wkb_parsing(): path = mapnik.Path() count = 0 for wkb in wkbs: count += wkb[0] try: path.add_wkb(unhexlify(wkb[2])) except RuntimeError, e: if 'EMPTY' in wkb[1]: pass else: raise e
def compare_wkb_from_wkt(wkt, num): f = mapnik.Feature(1) f.add_geometries_from_wkt(wkt) eq_(len(f.geometries()), num) paths = mapnik.Path.from_wkt(wkt) eq_(len(paths), num) eq_(f.geometries()[0].to_wkb(), paths[0].to_wkb()) paths2 = mapnik.Path() for path in paths: paths2.add_wkb(path.to_wkb()) eq_(len(paths2), num) eq_(f.geometries()[0].to_wkb(), paths2[0].to_wkb())
def test_path_geo_interface(): path = mapnik.Path() path.add_wkt('POINT(0 0)') eq_(path.__geo_interface__,{u'type': u'Point', u'coordinates': [0, 0]})