1- #!/usr/bin/env python
2-
3- import os
4-
5- from nose .tools import eq_
6-
71import mapnik
82
9- from .utilities import execution_path , run_all
10-
113try :
124 import itertools .izip as zip
135except ImportError :
146 pass
157
168
17- def setup ():
18- # All of the paths used are relative, if we run the tests
19- # from another directory we need to chdir()
20- os .chdir (execution_path ('.' ))
21-
22-
239def compare_shape_between_mapnik_and_ogr (shapefile , query = None ):
2410 plugins = mapnik .DatasourceCache .plugin_names ()
2511 if 'shape' in plugins and 'ogr' in plugins :
@@ -34,47 +20,39 @@ def compare_shape_between_mapnik_and_ogr(shapefile, query=None):
3420 count = 0
3521 for feat1 , feat2 in zip (fs1 , fs2 ):
3622 count += 1
37- eq_ (feat1 .id (), feat2 .id (),
38- '%s : ogr feature id %s "%s" does not equal shapefile feature id %s "%s"'
39- % (count , feat1 .id (), str (feat1 .attributes ), feat2 .id (), str (feat2 .attributes )))
23+ assert feat1 .id () == feat2 .id (), '%s : ogr feature id %s "%s" does not equal shapefile feature id %s "%s"' % (count , feat1 .id (), str (feat1 .attributes ), feat2 .id (), str (feat2 .attributes ))
4024 return True
4125
4226
4327def test_shapefile_line_featureset_id ():
44- compare_shape_between_mapnik_and_ogr ('.. /data/shp/polylines.shp' )
28+ compare_shape_between_mapnik_and_ogr ('./test /data/shp/polylines.shp' )
4529
4630
4731def test_shapefile_polygon_featureset_id ():
48- compare_shape_between_mapnik_and_ogr ('.. /data/shp/poly.shp' )
32+ compare_shape_between_mapnik_and_ogr ('./test /data/shp/poly.shp' )
4933
5034
5135def test_shapefile_polygon_feature_query_id ():
5236 bbox = (15523428.2632 , 4110477.6323 , - 11218494.8310 , 7495720.7404 )
5337 query = mapnik .Query (mapnik .Box2d (* bbox ))
5438 if 'ogr' in mapnik .DatasourceCache .plugin_names ():
55- ds = mapnik .Ogr (file = '.. /data/shp/world_merc.shp' , layer_by_index = 0 )
39+ ds = mapnik .Ogr (file = './test /data/shp/world_merc.shp' , layer_by_index = 0 )
5640 for fld in ds .fields ():
5741 query .add_property_name (fld )
5842 compare_shape_between_mapnik_and_ogr (
59- '.. /data/shp/world_merc.shp' , query )
43+ './test /data/shp/world_merc.shp' , query )
6044
6145
6246def test_feature_hit_count ():
63- pass
64- #raise Todo("need to optimize multigeom bbox handling in shapeindex: https://github.com/mapnik/mapnik/issues/783")
6547 # results in different results between shp and ogr!
6648 #bbox = (-14284551.8434, 2074195.1992, -7474929.8687, 8140237.7628)
67- #bbox = (1113194.91,4512803.085,2226389.82,6739192.905)
68- #query = mapnik.Query(mapnik.Box2d(*bbox))
69- # if 'ogr' in mapnik.DatasourceCache.plugin_names():
70- # ds1 = mapnik.Ogr(file='../data/shp/world_merc.shp',layer_by_index=0)
71- # for fld in ds1.fields():
72- # query.add_property_name(fld)
73- # ds2 = mapnik.Shapefile(file='../data/shp/world_merc.shp')
74- # count1 = len(ds1.features(query).features)
75- # count2 = len(ds2.features(query).features)
76- # eq_(count1,count2,"Feature count differs between OGR driver (%s features) and Shapefile Driver (%s features) when querying the same bbox" % (count1,count2))
77-
78- if __name__ == "__main__" :
79- setup ()
80- exit (run_all (eval (x ) for x in dir () if x .startswith ("test_" )))
49+ bbox = (1113194.91 ,4512803.085 ,2226389.82 ,6739192.905 )
50+ query = mapnik .Query (mapnik .Box2d (* bbox ))
51+ if 'ogr' in mapnik .DatasourceCache .plugin_names ():
52+ ds1 = mapnik .Ogr (file = './test/data/shp/world_merc.shp' ,layer_by_index = 0 )
53+ for fld in ds1 .fields ():
54+ query .add_property_name (fld )
55+ ds2 = mapnik .Shapefile (file = './test/data/shp/world_merc.shp' )
56+ count1 = len (list (ds1 .features (query )))
57+ count2 = len (list (ds2 .features (query )))
58+ assert count1 < count2 # expected 17 and 20
0 commit comments