more wkb/wkt tests
This commit is contained in:
parent
b925c79e4d
commit
8ce9da421f
1 changed files with 67 additions and 10 deletions
|
@ -1,10 +1,16 @@
|
||||||
#encoding: utf8
|
#encoding: utf8
|
||||||
|
|
||||||
from nose.tools import *
|
from nose.tools import *
|
||||||
import os
|
import os,sys
|
||||||
from utilities import execution_path
|
from utilities import execution_path
|
||||||
|
from utilities import Todo
|
||||||
import mapnik
|
import mapnik
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
# All of the paths used are relative, if we run the tests
|
||||||
|
# from another directory we need to chdir()
|
||||||
|
os.chdir(execution_path('.'))
|
||||||
|
|
||||||
wkts = [
|
wkts = [
|
||||||
[1,"POINT(30 10)"],
|
[1,"POINT(30 10)"],
|
||||||
[1,"POINT(30.0 10.0)"],
|
[1,"POINT(30.0 10.0)"],
|
||||||
|
@ -20,7 +26,7 @@ wkts = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def compare_wkb_from_wkt(wkt,num):
|
def compare_wkb_from_wkt(wkt,num=None):
|
||||||
|
|
||||||
# create a Path from geometry(s)
|
# create a Path from geometry(s)
|
||||||
paths = mapnik.Path.from_wkt(wkt)
|
paths = mapnik.Path.from_wkt(wkt)
|
||||||
|
@ -31,8 +37,9 @@ def compare_wkb_from_wkt(wkt,num):
|
||||||
|
|
||||||
# ensure both have same result
|
# ensure both have same result
|
||||||
# compare number of geometry parts
|
# compare number of geometry parts
|
||||||
eq_(len(paths),num)
|
if num:
|
||||||
eq_(len(f.geometries()),num)
|
eq_(len(paths),num)
|
||||||
|
eq_(len(f.geometries()),num)
|
||||||
# compare collection off all geometries
|
# compare collection off all geometries
|
||||||
eq_(paths.to_wkb(mapnik.wkbByteOrder.XDR),f.geometries().to_wkb(mapnik.wkbByteOrder.XDR))
|
eq_(paths.to_wkb(mapnik.wkbByteOrder.XDR),f.geometries().to_wkb(mapnik.wkbByteOrder.XDR))
|
||||||
# compare all parts
|
# compare all parts
|
||||||
|
@ -45,12 +52,13 @@ def compare_wkb_from_wkt(wkt,num):
|
||||||
paths2.add_wkb(path.to_wkb(mapnik.wkbByteOrder.XDR))
|
paths2.add_wkb(path.to_wkb(mapnik.wkbByteOrder.XDR))
|
||||||
|
|
||||||
# ensure result
|
# ensure result
|
||||||
eq_(len(paths2),num)
|
if num:
|
||||||
|
eq_(len(paths2),num)
|
||||||
eq_(paths2.to_wkb(mapnik.wkbByteOrder.XDR),paths.to_wkb(mapnik.wkbByteOrder.XDR))
|
eq_(paths2.to_wkb(mapnik.wkbByteOrder.XDR),paths.to_wkb(mapnik.wkbByteOrder.XDR))
|
||||||
for idx,path in enumerate(paths2):
|
for idx,path in enumerate(paths2):
|
||||||
eq_(f.geometries()[idx].to_wkb(mapnik.wkbByteOrder.XDR),path.to_wkb(mapnik.wkbByteOrder.XDR))
|
eq_(f.geometries()[idx].to_wkb(mapnik.wkbByteOrder.XDR),path.to_wkb(mapnik.wkbByteOrder.XDR))
|
||||||
|
|
||||||
def compare_wkt_from_wkt(wkt,num):
|
def compare_wkt_from_wkt(wkt,num=None):
|
||||||
# create a Path from geometry(s)
|
# create a Path from geometry(s)
|
||||||
paths = mapnik.Path.from_wkt(wkt)
|
paths = mapnik.Path.from_wkt(wkt)
|
||||||
|
|
||||||
|
@ -59,14 +67,15 @@ def compare_wkt_from_wkt(wkt,num):
|
||||||
f.add_geometries_from_wkt(wkt)
|
f.add_geometries_from_wkt(wkt)
|
||||||
|
|
||||||
# compare to original, which may not have significant digits
|
# compare to original, which may not have significant digits
|
||||||
if '.0' not in wkt:
|
if '.' not in wkt:
|
||||||
eq_(f.geometries().to_wkt().upper().replace('.0',''),wkt)
|
eq_(f.geometries().to_wkt().upper().replace('.0',''),wkt)
|
||||||
else:
|
else:
|
||||||
eq_(f.geometries().to_wkt().upper(),wkt)
|
eq_(f.geometries().to_wkt().upper(),wkt)
|
||||||
|
|
||||||
# ensure both have same result
|
# ensure both have same result
|
||||||
eq_(len(paths),num)
|
if num:
|
||||||
eq_(len(f.geometries()),num)
|
eq_(len(paths),num)
|
||||||
|
eq_(len(f.geometries()),num)
|
||||||
eq_(paths.to_wkt(),f.geometries().to_wkt())
|
eq_(paths.to_wkt(),f.geometries().to_wkt())
|
||||||
for idx,path in enumerate(paths):
|
for idx,path in enumerate(paths):
|
||||||
eq_(f.geometries()[idx].to_wkt(),path.to_wkt())
|
eq_(f.geometries()[idx].to_wkt(),path.to_wkt())
|
||||||
|
@ -77,7 +86,8 @@ def compare_wkt_from_wkt(wkt,num):
|
||||||
paths2.add_wkt(path.to_wkt())
|
paths2.add_wkt(path.to_wkt())
|
||||||
|
|
||||||
# ensure result
|
# ensure result
|
||||||
eq_(len(paths2),num)
|
if num:
|
||||||
|
eq_(len(paths2),num)
|
||||||
eq_(paths2.to_wkt(),paths.to_wkt())
|
eq_(paths2.to_wkt(),paths.to_wkt())
|
||||||
for idx,path in enumerate(paths2):
|
for idx,path in enumerate(paths2):
|
||||||
eq_(f.geometries()[idx].to_wkb(mapnik.wkbByteOrder.XDR),path.to_wkb(mapnik.wkbByteOrder.XDR))
|
eq_(f.geometries()[idx].to_wkb(mapnik.wkbByteOrder.XDR),path.to_wkb(mapnik.wkbByteOrder.XDR))
|
||||||
|
@ -96,5 +106,52 @@ def test_wkb_simple():
|
||||||
except RuntimeError, e:
|
except RuntimeError, e:
|
||||||
raise RuntimeError('%s %s' % (e, wkt))
|
raise RuntimeError('%s %s' % (e, wkt))
|
||||||
|
|
||||||
|
@raises(IndexError)
|
||||||
|
def test_geometry_index_error():
|
||||||
|
wkt = 'Point (0 0)'
|
||||||
|
paths = mapnik.Path.from_wkt(wkt)
|
||||||
|
paths[3]
|
||||||
|
f = mapnik.Feature(1)
|
||||||
|
f.add_geometries_from_wkt(wkt)
|
||||||
|
f.geometries()[3]
|
||||||
|
|
||||||
|
@raises(IndexError)
|
||||||
|
def test_geometry_index_error2():
|
||||||
|
wkt = 'Point (0 0)'
|
||||||
|
f = mapnik.Feature(1)
|
||||||
|
f.add_geometries_from_wkt(wkt)
|
||||||
|
f.geometries()[3]
|
||||||
|
|
||||||
|
def test_wkt_rounding():
|
||||||
|
raise Todo("fixme or remove test")
|
||||||
|
# currently fails because we use output precision of 6 - should we make configurable? https://github.com/mapnik/mapnik/issues/1009
|
||||||
|
# if precision is set to 15 still fails due to very subtle rounding issues
|
||||||
|
wkt = "POLYGON((7.904185417583761 54.180426336712856,7.89918053477129 54.178168035931542,7.897715691021261 54.182318426556606,7.893565300396205 54.183111883587891,7.89039147227129 54.187567449994106,7.885874870708761 54.190680242962827,7.879893425396261 54.193915106244049,7.894541862896233 54.194647528119134,7.900645378521233 54.190680242962827,7.904185417583761 54.180426336712856))"
|
||||||
|
compare_wkt_from_wkt(wkt,1)
|
||||||
|
|
||||||
|
def test_wkt_collection_flattening():
|
||||||
|
raise Todo("fixme or remove test")
|
||||||
|
# currently fails as the MULTIPOLYGON inside will be returned as multiple polygons - not a huge deal - should we worry?
|
||||||
|
wkt = "GEOMETRYCOLLECTION(POLYGON((1 1,2 1,2 2,1 2,1 1)),MULTIPOLYGON(((40 40,20 45,45 30,40 40)),((20 35,45 20,30 5,10 10,10 30,20 35),(30 20,20 25,20 15,30 20))),LINESTRING(2 3,3 4))"
|
||||||
|
compare_wkt_from_wkt(wkt,4)
|
||||||
|
|
||||||
|
# skip since this data is not checked into tests
|
||||||
|
#def test_wkt_natural_earth():
|
||||||
|
# '''
|
||||||
|
# wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/10m-land.zip
|
||||||
|
# unzip 10m-land.zip
|
||||||
|
# ogr2ogr -F CSV -lco GEOMETRY=AS_WKT 10m-land.csv 10m_land.shp
|
||||||
|
# mv 10m-land.csv tests/data/csv/
|
||||||
|
# '''
|
||||||
|
# lines = open('../data/csv/10m-land.csv').readlines()
|
||||||
|
# for line in lines:
|
||||||
|
# wkt = lines[1][lines[1].index('"',0)+1:lines[1].index('"',1)]
|
||||||
|
# wkt = wkt.replace(' (','(',1)
|
||||||
|
# try:
|
||||||
|
# compare_wkb_from_wkt(wkt)
|
||||||
|
# except RuntimeError, e:
|
||||||
|
# raise RuntimeError('%s %s' % (e, wkt))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
setup()
|
||||||
[eval(run)() for run in dir() if 'test_' in run]
|
[eval(run)() for run in dir() if 'test_' in run]
|
||||||
|
|
Loading…
Reference in a new issue