Skip to content

Commit 6727f11

Browse files
committed
Upgrade ogr and feature id unit tests
1 parent 2a92ab0 commit 6727f11

3 files changed

Lines changed: 143 additions & 298 deletions

File tree

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
#!/usr/bin/env python
2-
3-
import os
4-
5-
from nose.tools import eq_
6-
71
import mapnik
82

9-
from .utilities import execution_path, run_all
10-
113
try:
124
import itertools.izip as zip
135
except 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-
239
def 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

4327
def 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

4731
def 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

5135
def 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

6246
def 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
Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
#!/usr/bin/env python
2-
3-
import os
4-
5-
from nose.tools import eq_
6-
71
import mapnik
82

9-
from .utilities import execution_path, run_all
10-
113
try:
124
import itertools.izip as zip
135
except 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-
229
# TODO - fix truncation in shapefile...
2310
polys = ["POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))",
2411
"POLYGON ((35 10, 10 20, 15 40, 45 45, 35 10),(20 30, 35 35, 30 20, 20 30))",
@@ -37,17 +24,12 @@ def ensure_geometries_are_interpreted_equivalently(filename):
3724
count = 0
3825
for feat1, feat2 in zip(fs1, fs2):
3926
count += 1
40-
eq_(feat1.attributes, feat2.attributes)
41-
# TODO - revisit this: https://github.com/mapnik/mapnik/issues/1093
42-
# eq_(feat1.to_geojson(),feat2.to_geojson())
43-
# eq_(feat1.geometries().to_wkt(),feat2.geometries().to_wkt())
44-
# eq_(feat1.geometries().to_wkb(mapnik.wkbByteOrder.NDR),feat2.geometries().to_wkb(mapnik.wkbByteOrder.NDR))
45-
# eq_(feat1.geometries().to_wkb(mapnik.wkbByteOrder.XDR),feat2.geometries().to_wkb(mapnik.wkbByteOrder.XDR))
27+
assert feat1.attributes == feat2.attributes
28+
assert feat1.to_geojson() == feat2.to_geojson()
29+
assert feat1.geometry.to_wkt() == feat2.geometry.to_wkt()
30+
assert feat1.geometry.to_wkb(mapnik.wkbByteOrder.NDR) == feat2.geometry.to_wkb(mapnik.wkbByteOrder.NDR)
31+
assert feat1.geometry.to_wkb(mapnik.wkbByteOrder.XDR) == feat2.geometry.to_wkb(mapnik.wkbByteOrder.XDR)
4632

4733
def test_simple_polys():
4834
ensure_geometries_are_interpreted_equivalently(
49-
'../data/shp/wkt_poly.shp')
50-
51-
if __name__ == "__main__":
52-
setup()
53-
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
35+
'./test/data/shp/wkt_poly.shp')

0 commit comments

Comments
 (0)