mirror of https://github.com/django/django.git
Fixed regression introduced in r13755 that prevented the running of the GEOS/GDAL test suites without configuring Django settings; moved reference geometry data from Python module to compressed JSON fixture; put in workaround in tests for GDAL bug #3783.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14414 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
34e545a938
commit
315ae1ce6e
|
@ -1,20 +1,7 @@
|
||||||
import os, os.path, unittest
|
import os, os.path, unittest
|
||||||
from django.contrib.gis.gdal import DataSource, Envelope, OGRGeometry, OGRException, OGRIndexError
|
from django.contrib.gis.gdal import DataSource, Envelope, OGRGeometry, OGRException, OGRIndexError, GDAL_VERSION
|
||||||
from django.contrib.gis.gdal.field import OFTReal, OFTInteger, OFTString
|
from django.contrib.gis.gdal.field import OFTReal, OFTInteger, OFTString
|
||||||
from django.contrib import gis
|
from django.contrib.gis.geometry.test_data import get_ds_file, TestDS
|
||||||
|
|
||||||
# Path for SHP files
|
|
||||||
data_path = os.path.join(os.path.dirname(gis.__file__), 'tests' + os.sep + 'data')
|
|
||||||
def get_ds_file(name, ext):
|
|
||||||
return os.sep.join([data_path, name, name + '.%s' % ext])
|
|
||||||
|
|
||||||
# Test SHP data source object
|
|
||||||
class TestDS:
|
|
||||||
def __init__(self, name, **kwargs):
|
|
||||||
ext = kwargs.pop('ext', 'shp')
|
|
||||||
self.ds = get_ds_file(name, ext)
|
|
||||||
for key, value in kwargs.items():
|
|
||||||
setattr(self, key, value)
|
|
||||||
|
|
||||||
# List of acceptable data sources.
|
# List of acceptable data sources.
|
||||||
ds_list = (TestDS('test_point', nfeat=5, nfld=3, geom='POINT', gtype=1, driver='ESRI Shapefile',
|
ds_list = (TestDS('test_point', nfeat=5, nfld=3, geom='POINT', gtype=1, driver='ESRI Shapefile',
|
||||||
|
@ -85,11 +72,17 @@ class DataSourceTest(unittest.TestCase):
|
||||||
self.assertEqual(source.nfld, len(layer.fields))
|
self.assertEqual(source.nfld, len(layer.fields))
|
||||||
|
|
||||||
# Testing the layer's extent (an Envelope), and it's properties
|
# Testing the layer's extent (an Envelope), and it's properties
|
||||||
self.assertEqual(True, isinstance(layer.extent, Envelope))
|
if source.driver == 'VRT' and (GDAL_VERSION > (1, 7, 0) and GDAL_VERSION < (1, 7, 3)):
|
||||||
self.assertAlmostEqual(source.extent[0], layer.extent.min_x, 5)
|
# There's a known GDAL regression with retrieving the extent
|
||||||
self.assertAlmostEqual(source.extent[1], layer.extent.min_y, 5)
|
# of a VRT layer in versions 1.7.0-1.7.2:
|
||||||
self.assertAlmostEqual(source.extent[2], layer.extent.max_x, 5)
|
# http://trac.osgeo.org/gdal/ticket/3783
|
||||||
self.assertAlmostEqual(source.extent[3], layer.extent.max_y, 5)
|
pass
|
||||||
|
else:
|
||||||
|
self.assertEqual(True, isinstance(layer.extent, Envelope))
|
||||||
|
self.assertAlmostEqual(source.extent[0], layer.extent.min_x, 5)
|
||||||
|
self.assertAlmostEqual(source.extent[1], layer.extent.min_y, 5)
|
||||||
|
self.assertAlmostEqual(source.extent[2], layer.extent.max_x, 5)
|
||||||
|
self.assertAlmostEqual(source.extent[3], layer.extent.max_y, 5)
|
||||||
|
|
||||||
# Now checking the field names.
|
# Now checking the field names.
|
||||||
flds = layer.fields
|
flds = layer.fields
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
from django.contrib.gis.gdal import OGRGeometry, OGRGeomType, \
|
from django.contrib.gis.gdal import OGRGeometry, OGRGeomType, \
|
||||||
OGRException, OGRIndexError, SpatialReference, CoordTransform, \
|
OGRException, OGRIndexError, SpatialReference, CoordTransform, \
|
||||||
gdal_version
|
gdal_version
|
||||||
from django.contrib.gis.tests.geometries import *
|
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
from django.contrib.gis.geometry.test_data import TestDataMixin
|
||||||
|
|
||||||
|
class OGRGeomTest(unittest.TestCase, TestDataMixin):
|
||||||
class OGRGeomTest(unittest.TestCase):
|
|
||||||
"This tests the OGR Geometry."
|
"This tests the OGR Geometry."
|
||||||
|
|
||||||
def test00a_geomtype(self):
|
def test00a_geomtype(self):
|
||||||
|
@ -56,7 +55,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
|
|
||||||
def test01a_wkt(self):
|
def test01a_wkt(self):
|
||||||
"Testing WKT output."
|
"Testing WKT output."
|
||||||
for g in wkt_out:
|
for g in self.geometries.wkt_out:
|
||||||
geom = OGRGeometry(g.wkt)
|
geom = OGRGeometry(g.wkt)
|
||||||
self.assertEqual(g.wkt, geom.wkt)
|
self.assertEqual(g.wkt, geom.wkt)
|
||||||
|
|
||||||
|
@ -73,13 +72,13 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
|
|
||||||
def test01b_gml(self):
|
def test01b_gml(self):
|
||||||
"Testing GML output."
|
"Testing GML output."
|
||||||
for g in wkt_out:
|
for g in self.geometries.wkt_out:
|
||||||
geom = OGRGeometry(g.wkt)
|
geom = OGRGeometry(g.wkt)
|
||||||
self.assertEqual(g.gml, geom.gml)
|
self.assertEqual(g.gml, geom.gml)
|
||||||
|
|
||||||
def test01c_hex(self):
|
def test01c_hex(self):
|
||||||
"Testing HEX input/output."
|
"Testing HEX input/output."
|
||||||
for g in hex_wkt:
|
for g in self.geometries.hex_wkt:
|
||||||
geom1 = OGRGeometry(g.wkt)
|
geom1 = OGRGeometry(g.wkt)
|
||||||
self.assertEqual(g.hex, geom1.hex)
|
self.assertEqual(g.hex, geom1.hex)
|
||||||
# Constructing w/HEX
|
# Constructing w/HEX
|
||||||
|
@ -89,7 +88,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
def test01d_wkb(self):
|
def test01d_wkb(self):
|
||||||
"Testing WKB input/output."
|
"Testing WKB input/output."
|
||||||
from binascii import b2a_hex
|
from binascii import b2a_hex
|
||||||
for g in hex_wkt:
|
for g in self.geometries.hex_wkt:
|
||||||
geom1 = OGRGeometry(g.wkt)
|
geom1 = OGRGeometry(g.wkt)
|
||||||
wkb = geom1.wkb
|
wkb = geom1.wkb
|
||||||
self.assertEqual(b2a_hex(wkb).upper(), g.hex)
|
self.assertEqual(b2a_hex(wkb).upper(), g.hex)
|
||||||
|
@ -101,7 +100,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
"Testing GeoJSON input/output."
|
"Testing GeoJSON input/output."
|
||||||
from django.contrib.gis.gdal.prototypes.geom import GEOJSON
|
from django.contrib.gis.gdal.prototypes.geom import GEOJSON
|
||||||
if not GEOJSON: return
|
if not GEOJSON: return
|
||||||
for g in json_geoms:
|
for g in self.geometries.json_geoms:
|
||||||
geom = OGRGeometry(g.wkt)
|
geom = OGRGeometry(g.wkt)
|
||||||
if not hasattr(g, 'not_equal'):
|
if not hasattr(g, 'not_equal'):
|
||||||
self.assertEqual(g.json, geom.json)
|
self.assertEqual(g.json, geom.json)
|
||||||
|
@ -112,7 +111,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
"Testing Point objects."
|
"Testing Point objects."
|
||||||
|
|
||||||
prev = OGRGeometry('POINT(0 0)')
|
prev = OGRGeometry('POINT(0 0)')
|
||||||
for p in points:
|
for p in self.geometries.points:
|
||||||
if not hasattr(p, 'z'): # No 3D
|
if not hasattr(p, 'z'): # No 3D
|
||||||
pnt = OGRGeometry(p.wkt)
|
pnt = OGRGeometry(p.wkt)
|
||||||
self.assertEqual(1, pnt.geom_type)
|
self.assertEqual(1, pnt.geom_type)
|
||||||
|
@ -123,8 +122,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
|
|
||||||
def test03_multipoints(self):
|
def test03_multipoints(self):
|
||||||
"Testing MultiPoint objects."
|
"Testing MultiPoint objects."
|
||||||
|
for mp in self.geometries.multipoints:
|
||||||
for mp in multipoints:
|
|
||||||
mgeom1 = OGRGeometry(mp.wkt) # First one from WKT
|
mgeom1 = OGRGeometry(mp.wkt) # First one from WKT
|
||||||
self.assertEqual(4, mgeom1.geom_type)
|
self.assertEqual(4, mgeom1.geom_type)
|
||||||
self.assertEqual('MULTIPOINT', mgeom1.geom_name)
|
self.assertEqual('MULTIPOINT', mgeom1.geom_name)
|
||||||
|
@ -135,38 +133,38 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
mgeom3.add(g.wkt) # should take WKT as well
|
mgeom3.add(g.wkt) # should take WKT as well
|
||||||
self.assertEqual(mgeom1, mgeom2) # they should equal
|
self.assertEqual(mgeom1, mgeom2) # they should equal
|
||||||
self.assertEqual(mgeom1, mgeom3)
|
self.assertEqual(mgeom1, mgeom3)
|
||||||
self.assertEqual(mp.points, mgeom2.tuple)
|
self.assertEqual(mp.coords, mgeom2.coords)
|
||||||
self.assertEqual(mp.n_p, mgeom2.point_count)
|
self.assertEqual(mp.n_p, mgeom2.point_count)
|
||||||
|
|
||||||
def test04_linestring(self):
|
def test04_linestring(self):
|
||||||
"Testing LineString objects."
|
"Testing LineString objects."
|
||||||
prev = OGRGeometry('POINT(0 0)')
|
prev = OGRGeometry('POINT(0 0)')
|
||||||
for ls in linestrings:
|
for ls in self.geometries.linestrings:
|
||||||
linestr = OGRGeometry(ls.wkt)
|
linestr = OGRGeometry(ls.wkt)
|
||||||
self.assertEqual(2, linestr.geom_type)
|
self.assertEqual(2, linestr.geom_type)
|
||||||
self.assertEqual('LINESTRING', linestr.geom_name)
|
self.assertEqual('LINESTRING', linestr.geom_name)
|
||||||
self.assertEqual(ls.n_p, linestr.point_count)
|
self.assertEqual(ls.n_p, linestr.point_count)
|
||||||
self.assertEqual(ls.tup, linestr.tuple)
|
self.assertEqual(ls.coords, linestr.tuple)
|
||||||
self.assertEqual(True, linestr == OGRGeometry(ls.wkt))
|
self.assertEqual(True, linestr == OGRGeometry(ls.wkt))
|
||||||
self.assertEqual(True, linestr != prev)
|
self.assertEqual(True, linestr != prev)
|
||||||
self.assertRaises(OGRIndexError, linestr.__getitem__, len(linestr))
|
self.assertRaises(OGRIndexError, linestr.__getitem__, len(linestr))
|
||||||
prev = linestr
|
prev = linestr
|
||||||
|
|
||||||
# Testing the x, y properties.
|
# Testing the x, y properties.
|
||||||
x = [tmpx for tmpx, tmpy in ls.tup]
|
x = [tmpx for tmpx, tmpy in ls.coords]
|
||||||
y = [tmpy for tmpx, tmpy in ls.tup]
|
y = [tmpy for tmpx, tmpy in ls.coords]
|
||||||
self.assertEqual(x, linestr.x)
|
self.assertEqual(x, linestr.x)
|
||||||
self.assertEqual(y, linestr.y)
|
self.assertEqual(y, linestr.y)
|
||||||
|
|
||||||
def test05_multilinestring(self):
|
def test05_multilinestring(self):
|
||||||
"Testing MultiLineString objects."
|
"Testing MultiLineString objects."
|
||||||
prev = OGRGeometry('POINT(0 0)')
|
prev = OGRGeometry('POINT(0 0)')
|
||||||
for mls in multilinestrings:
|
for mls in self.geometries.multilinestrings:
|
||||||
mlinestr = OGRGeometry(mls.wkt)
|
mlinestr = OGRGeometry(mls.wkt)
|
||||||
self.assertEqual(5, mlinestr.geom_type)
|
self.assertEqual(5, mlinestr.geom_type)
|
||||||
self.assertEqual('MULTILINESTRING', mlinestr.geom_name)
|
self.assertEqual('MULTILINESTRING', mlinestr.geom_name)
|
||||||
self.assertEqual(mls.n_p, mlinestr.point_count)
|
self.assertEqual(mls.n_p, mlinestr.point_count)
|
||||||
self.assertEqual(mls.tup, mlinestr.tuple)
|
self.assertEqual(mls.coords, mlinestr.tuple)
|
||||||
self.assertEqual(True, mlinestr == OGRGeometry(mls.wkt))
|
self.assertEqual(True, mlinestr == OGRGeometry(mls.wkt))
|
||||||
self.assertEqual(True, mlinestr != prev)
|
self.assertEqual(True, mlinestr != prev)
|
||||||
prev = mlinestr
|
prev = mlinestr
|
||||||
|
@ -178,7 +176,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
def test06_linearring(self):
|
def test06_linearring(self):
|
||||||
"Testing LinearRing objects."
|
"Testing LinearRing objects."
|
||||||
prev = OGRGeometry('POINT(0 0)')
|
prev = OGRGeometry('POINT(0 0)')
|
||||||
for rr in linearrings:
|
for rr in self.geometries.linearrings:
|
||||||
lr = OGRGeometry(rr.wkt)
|
lr = OGRGeometry(rr.wkt)
|
||||||
#self.assertEqual(101, lr.geom_type.num)
|
#self.assertEqual(101, lr.geom_type.num)
|
||||||
self.assertEqual('LINEARRING', lr.geom_name)
|
self.assertEqual('LINEARRING', lr.geom_name)
|
||||||
|
@ -196,7 +194,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
self.assertEqual(bbox, p.extent)
|
self.assertEqual(bbox, p.extent)
|
||||||
|
|
||||||
prev = OGRGeometry('POINT(0 0)')
|
prev = OGRGeometry('POINT(0 0)')
|
||||||
for p in polygons:
|
for p in self.geometries.polygons:
|
||||||
poly = OGRGeometry(p.wkt)
|
poly = OGRGeometry(p.wkt)
|
||||||
self.assertEqual(3, poly.geom_type)
|
self.assertEqual(3, poly.geom_type)
|
||||||
self.assertEqual('POLYGON', poly.geom_name)
|
self.assertEqual('POLYGON', poly.geom_name)
|
||||||
|
@ -250,7 +248,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
def test08_multipolygons(self):
|
def test08_multipolygons(self):
|
||||||
"Testing MultiPolygon objects."
|
"Testing MultiPolygon objects."
|
||||||
prev = OGRGeometry('POINT(0 0)')
|
prev = OGRGeometry('POINT(0 0)')
|
||||||
for mp in multipolygons:
|
for mp in self.geometries.multipolygons:
|
||||||
mpoly = OGRGeometry(mp.wkt)
|
mpoly = OGRGeometry(mp.wkt)
|
||||||
self.assertEqual(6, mpoly.geom_type)
|
self.assertEqual(6, mpoly.geom_type)
|
||||||
self.assertEqual('MULTIPOLYGON', mpoly.geom_name)
|
self.assertEqual('MULTIPOLYGON', mpoly.geom_name)
|
||||||
|
@ -265,7 +263,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
|
|
||||||
def test09a_srs(self):
|
def test09a_srs(self):
|
||||||
"Testing OGR Geometries with Spatial Reference objects."
|
"Testing OGR Geometries with Spatial Reference objects."
|
||||||
for mp in multipolygons:
|
for mp in self.geometries.multipolygons:
|
||||||
# Creating a geometry w/spatial reference
|
# Creating a geometry w/spatial reference
|
||||||
sr = SpatialReference('WGS84')
|
sr = SpatialReference('WGS84')
|
||||||
mpoly = OGRGeometry(mp.wkt, sr)
|
mpoly = OGRGeometry(mp.wkt, sr)
|
||||||
|
@ -283,8 +281,8 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
self.assertEqual(sr.wkt, ring.srs.wkt)
|
self.assertEqual(sr.wkt, ring.srs.wkt)
|
||||||
|
|
||||||
# Ensuring SRS propagate in topological ops.
|
# Ensuring SRS propagate in topological ops.
|
||||||
a, b = topology_geoms[0]
|
a = OGRGeometry(self.geometries.topology_geoms[0].wkt_a, sr)
|
||||||
a, b = OGRGeometry(a.wkt, sr), OGRGeometry(b.wkt, sr)
|
b = OGRGeometry(self.geometries.topology_geoms[0].wkt_b, sr)
|
||||||
diff = a.difference(b)
|
diff = a.difference(b)
|
||||||
union = a.union(b)
|
union = a.union(b)
|
||||||
self.assertEqual(sr.wkt, diff.srs.wkt)
|
self.assertEqual(sr.wkt, diff.srs.wkt)
|
||||||
|
@ -352,11 +350,10 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
|
|
||||||
def test10_difference(self):
|
def test10_difference(self):
|
||||||
"Testing difference()."
|
"Testing difference()."
|
||||||
for i in xrange(len(topology_geoms)):
|
for i in xrange(len(self.geometries.topology_geoms)):
|
||||||
g_tup = topology_geoms[i]
|
a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
|
||||||
a = OGRGeometry(g_tup[0].wkt)
|
b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
|
||||||
b = OGRGeometry(g_tup[1].wkt)
|
d1 = OGRGeometry(self.geometries.diff_geoms[i].wkt)
|
||||||
d1 = OGRGeometry(diff_geoms[i].wkt)
|
|
||||||
d2 = a.difference(b)
|
d2 = a.difference(b)
|
||||||
self.assertEqual(d1, d2)
|
self.assertEqual(d1, d2)
|
||||||
self.assertEqual(d1, a - b) # __sub__ is difference operator
|
self.assertEqual(d1, a - b) # __sub__ is difference operator
|
||||||
|
@ -365,11 +362,10 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
|
|
||||||
def test11_intersection(self):
|
def test11_intersection(self):
|
||||||
"Testing intersects() and intersection()."
|
"Testing intersects() and intersection()."
|
||||||
for i in xrange(len(topology_geoms)):
|
for i in xrange(len(self.geometries.topology_geoms)):
|
||||||
g_tup = topology_geoms[i]
|
a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
|
||||||
a = OGRGeometry(g_tup[0].wkt)
|
b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
|
||||||
b = OGRGeometry(g_tup[1].wkt)
|
i1 = OGRGeometry(self.geometries.intersect_geoms[i].wkt)
|
||||||
i1 = OGRGeometry(intersect_geoms[i].wkt)
|
|
||||||
self.assertEqual(True, a.intersects(b))
|
self.assertEqual(True, a.intersects(b))
|
||||||
i2 = a.intersection(b)
|
i2 = a.intersection(b)
|
||||||
self.assertEqual(i1, i2)
|
self.assertEqual(i1, i2)
|
||||||
|
@ -379,11 +375,10 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
|
|
||||||
def test12_symdifference(self):
|
def test12_symdifference(self):
|
||||||
"Testing sym_difference()."
|
"Testing sym_difference()."
|
||||||
for i in xrange(len(topology_geoms)):
|
for i in xrange(len(self.geometries.topology_geoms)):
|
||||||
g_tup = topology_geoms[i]
|
a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
|
||||||
a = OGRGeometry(g_tup[0].wkt)
|
b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
|
||||||
b = OGRGeometry(g_tup[1].wkt)
|
d1 = OGRGeometry(self.geometries.sdiff_geoms[i].wkt)
|
||||||
d1 = OGRGeometry(sdiff_geoms[i].wkt)
|
|
||||||
d2 = a.sym_difference(b)
|
d2 = a.sym_difference(b)
|
||||||
self.assertEqual(d1, d2)
|
self.assertEqual(d1, d2)
|
||||||
self.assertEqual(d1, a ^ b) # __xor__ is symmetric difference operator
|
self.assertEqual(d1, a ^ b) # __xor__ is symmetric difference operator
|
||||||
|
@ -392,11 +387,10 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
|
|
||||||
def test13_union(self):
|
def test13_union(self):
|
||||||
"Testing union()."
|
"Testing union()."
|
||||||
for i in xrange(len(topology_geoms)):
|
for i in xrange(len(self.geometries.topology_geoms)):
|
||||||
g_tup = topology_geoms[i]
|
a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
|
||||||
a = OGRGeometry(g_tup[0].wkt)
|
b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
|
||||||
b = OGRGeometry(g_tup[1].wkt)
|
u1 = OGRGeometry(self.geometries.union_geoms[i].wkt)
|
||||||
u1 = OGRGeometry(union_geoms[i].wkt)
|
|
||||||
u2 = a.union(b)
|
u2 = a.union(b)
|
||||||
self.assertEqual(u1, u2)
|
self.assertEqual(u1, u2)
|
||||||
self.assertEqual(u1, a | b) # __or__ is union operator
|
self.assertEqual(u1, a | b) # __or__ is union operator
|
||||||
|
@ -412,7 +406,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
|
|
||||||
# GeometryCollection.add may take an OGRGeometry (if another collection
|
# GeometryCollection.add may take an OGRGeometry (if another collection
|
||||||
# of the same type all child geoms will be added individually) or WKT.
|
# of the same type all child geoms will be added individually) or WKT.
|
||||||
for mp in multipolygons:
|
for mp in self.geometries.multipolygons:
|
||||||
mpoly = OGRGeometry(mp.wkt)
|
mpoly = OGRGeometry(mp.wkt)
|
||||||
mp1 = OGRGeometry('MultiPolygon')
|
mp1 = OGRGeometry('MultiPolygon')
|
||||||
mp2 = OGRGeometry('MultiPolygon')
|
mp2 = OGRGeometry('MultiPolygon')
|
||||||
|
@ -430,7 +424,7 @@ class OGRGeomTest(unittest.TestCase):
|
||||||
mp = OGRGeometry('MULTIPOINT(5 23, 0 0, 10 50)')
|
mp = OGRGeometry('MULTIPOINT(5 23, 0 0, 10 50)')
|
||||||
self.assertEqual((0.0, 0.0, 10.0, 50.0), mp.extent)
|
self.assertEqual((0.0, 0.0, 10.0, 50.0), mp.extent)
|
||||||
# Testing on the 'real world' Polygon.
|
# Testing on the 'real world' Polygon.
|
||||||
poly = OGRGeometry(polygons[3].wkt)
|
poly = OGRGeometry(self.geometries.polygons[3].wkt)
|
||||||
ring = poly.shell
|
ring = poly.shell
|
||||||
x, y = ring.x, ring.y
|
x, y = ring.x, ring.y
|
||||||
xmin, ymin = min(x), min(y)
|
xmin, ymin = min(x), min(y)
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
"""
|
||||||
|
This module has the mock object definitions used to hold reference geometry
|
||||||
|
for the GEOS and GDAL tests.
|
||||||
|
"""
|
||||||
|
import gzip
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.contrib import gis
|
||||||
|
from django.utils import simplejson
|
||||||
|
|
||||||
|
|
||||||
|
# This global used to store reference geometry data.
|
||||||
|
GEOMETRIES = None
|
||||||
|
|
||||||
|
# Path where reference test data is located.
|
||||||
|
TEST_DATA = os.path.join(os.path.dirname(gis.__file__), 'tests', 'data')
|
||||||
|
|
||||||
|
|
||||||
|
def tuplize(seq):
|
||||||
|
"Turn all nested sequences to tuples in given sequence."
|
||||||
|
if isinstance(seq, (list, tuple)):
|
||||||
|
return tuple([tuplize(i) for i in seq])
|
||||||
|
return seq
|
||||||
|
|
||||||
|
|
||||||
|
def get_ds_file(name, ext):
|
||||||
|
return os.path.join(TEST_DATA,
|
||||||
|
name,
|
||||||
|
name + '.%s' % ext
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestObj(object):
|
||||||
|
"""
|
||||||
|
Base testing object, turns keyword args into attributes.
|
||||||
|
"""
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
|
||||||
|
class TestDS(TestObj):
|
||||||
|
"""
|
||||||
|
Object for testing GDAL data sources.
|
||||||
|
"""
|
||||||
|
def __init__(self, name, **kwargs):
|
||||||
|
# Shapefile is default extension, unless specified otherwise.
|
||||||
|
ext = kwargs.pop('ext', 'shp')
|
||||||
|
self.ds = get_ds_file(name, ext)
|
||||||
|
super(TestDS, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class TestGeom(TestObj):
|
||||||
|
"""
|
||||||
|
Testing object used for wrapping reference geometry data
|
||||||
|
in GEOS/GDAL tests.
|
||||||
|
"""
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
# Converting lists to tuples of certain keyword args
|
||||||
|
# so coordinate test cases will match (JSON has no
|
||||||
|
# concept of tuple).
|
||||||
|
coords = kwargs.pop('coords', None)
|
||||||
|
if coords:
|
||||||
|
self.coords = tuplize(coords)
|
||||||
|
|
||||||
|
centroid = kwargs.pop('centroid', None)
|
||||||
|
if centroid:
|
||||||
|
self.centroid = tuple(centroid)
|
||||||
|
|
||||||
|
ext_ring_cs = kwargs.pop('ext_ring_cs', None)
|
||||||
|
if ext_ring_cs:
|
||||||
|
ext_ring_cs = tuplize(ext_ring_cs)
|
||||||
|
self.ext_ring_cs = ext_ring_cs
|
||||||
|
|
||||||
|
super(TestGeom, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class TestGeomSet(object):
|
||||||
|
"""
|
||||||
|
Each attribute of this object is a list of `TestGeom` instances.
|
||||||
|
"""
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
setattr(self, key, [TestGeom(**kwargs) for kwargs in value])
|
||||||
|
|
||||||
|
|
||||||
|
class TestDataMixin(object):
|
||||||
|
"""
|
||||||
|
Mixin used for GEOS/GDAL test cases that defines a `geometries`
|
||||||
|
property, which returns and/or loads the reference geometry data.
|
||||||
|
"""
|
||||||
|
@property
|
||||||
|
def geometries(self):
|
||||||
|
global GEOMETRIES
|
||||||
|
if GEOMETRIES is None:
|
||||||
|
# Load up the test geometry data from fixture into global.
|
||||||
|
gzf = gzip.GzipFile(os.path.join(TEST_DATA, 'geometries.json.gz'))
|
||||||
|
geometries = simplejson.loads(gzf.read())
|
||||||
|
GEOMETRIES = TestGeomSet(**geometries)
|
||||||
|
return GEOMETRIES
|
|
@ -1,9 +1,9 @@
|
||||||
import ctypes, random, unittest, sys
|
import ctypes, random, unittest, sys
|
||||||
from django.contrib.gis.geos import *
|
from django.contrib.gis.geos import *
|
||||||
from django.contrib.gis.geos.base import gdal, numpy, GEOSBase
|
from django.contrib.gis.geos.base import gdal, numpy, GEOSBase
|
||||||
from django.contrib.gis.tests.geometries import *
|
from django.contrib.gis.geometry.test_data import TestDataMixin
|
||||||
|
|
||||||
class GEOSTest(unittest.TestCase):
|
class GEOSTest(unittest.TestCase, TestDataMixin):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def null_srid(self):
|
def null_srid(self):
|
||||||
|
@ -61,13 +61,13 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
def test01a_wkt(self):
|
def test01a_wkt(self):
|
||||||
"Testing WKT output."
|
"Testing WKT output."
|
||||||
for g in wkt_out:
|
for g in self.geometries.wkt_out:
|
||||||
geom = fromstr(g.wkt)
|
geom = fromstr(g.wkt)
|
||||||
self.assertEqual(g.ewkt, geom.wkt)
|
self.assertEqual(g.ewkt, geom.wkt)
|
||||||
|
|
||||||
def test01b_hex(self):
|
def test01b_hex(self):
|
||||||
"Testing HEX output."
|
"Testing HEX output."
|
||||||
for g in hex_wkt:
|
for g in self.geometries.hex_wkt:
|
||||||
geom = fromstr(g.wkt)
|
geom = fromstr(g.wkt)
|
||||||
self.assertEqual(g.hex, geom.hex)
|
self.assertEqual(g.hex, geom.hex)
|
||||||
|
|
||||||
|
@ -75,6 +75,13 @@ class GEOSTest(unittest.TestCase):
|
||||||
"Testing (HEX)EWKB output."
|
"Testing (HEX)EWKB output."
|
||||||
from binascii import a2b_hex
|
from binascii import a2b_hex
|
||||||
|
|
||||||
|
# For testing HEX(EWKB).
|
||||||
|
ogc_hex = '01010000000000000000000000000000000000F03F'
|
||||||
|
# `SELECT ST_AsHEXEWKB(ST_GeomFromText('POINT(0 1)', 4326));`
|
||||||
|
hexewkb_2d = '0101000020E61000000000000000000000000000000000F03F'
|
||||||
|
# `SELECT ST_AsHEXEWKB(ST_GeomFromEWKT('SRID=4326;POINT(0 1 2)'));`
|
||||||
|
hexewkb_3d = '01010000A0E61000000000000000000000000000000000F03F0000000000000040'
|
||||||
|
|
||||||
pnt_2d = Point(0, 1, srid=4326)
|
pnt_2d = Point(0, 1, srid=4326)
|
||||||
pnt_3d = Point(0, 1, 2, srid=4326)
|
pnt_3d = Point(0, 1, 2, srid=4326)
|
||||||
|
|
||||||
|
@ -116,7 +123,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
def test01c_kml(self):
|
def test01c_kml(self):
|
||||||
"Testing KML output."
|
"Testing KML output."
|
||||||
for tg in wkt_out:
|
for tg in self.geometries.wkt_out:
|
||||||
geom = fromstr(tg.wkt)
|
geom = fromstr(tg.wkt)
|
||||||
kml = getattr(tg, 'kml', False)
|
kml = getattr(tg, 'kml', False)
|
||||||
if kml: self.assertEqual(kml, geom.kml)
|
if kml: self.assertEqual(kml, geom.kml)
|
||||||
|
@ -125,7 +132,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
"Testing the Error handlers."
|
"Testing the Error handlers."
|
||||||
# string-based
|
# string-based
|
||||||
print "\nBEGIN - expecting GEOS_ERROR; safe to ignore.\n"
|
print "\nBEGIN - expecting GEOS_ERROR; safe to ignore.\n"
|
||||||
for err in errors:
|
for err in self.geometries.errors:
|
||||||
try:
|
try:
|
||||||
g = fromstr(err.wkt)
|
g = fromstr(err.wkt)
|
||||||
except (GEOSException, ValueError):
|
except (GEOSException, ValueError):
|
||||||
|
@ -147,14 +154,14 @@ class GEOSTest(unittest.TestCase):
|
||||||
def test01e_wkb(self):
|
def test01e_wkb(self):
|
||||||
"Testing WKB output."
|
"Testing WKB output."
|
||||||
from binascii import b2a_hex
|
from binascii import b2a_hex
|
||||||
for g in hex_wkt:
|
for g in self.geometries.hex_wkt:
|
||||||
geom = fromstr(g.wkt)
|
geom = fromstr(g.wkt)
|
||||||
wkb = geom.wkb
|
wkb = geom.wkb
|
||||||
self.assertEqual(b2a_hex(wkb).upper(), g.hex)
|
self.assertEqual(b2a_hex(wkb).upper(), g.hex)
|
||||||
|
|
||||||
def test01f_create_hex(self):
|
def test01f_create_hex(self):
|
||||||
"Testing creation from HEX."
|
"Testing creation from HEX."
|
||||||
for g in hex_wkt:
|
for g in self.geometries.hex_wkt:
|
||||||
geom_h = GEOSGeometry(g.hex)
|
geom_h = GEOSGeometry(g.hex)
|
||||||
# we need to do this so decimal places get normalised
|
# we need to do this so decimal places get normalised
|
||||||
geom_t = fromstr(g.wkt)
|
geom_t = fromstr(g.wkt)
|
||||||
|
@ -163,7 +170,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
def test01g_create_wkb(self):
|
def test01g_create_wkb(self):
|
||||||
"Testing creation from WKB."
|
"Testing creation from WKB."
|
||||||
from binascii import a2b_hex
|
from binascii import a2b_hex
|
||||||
for g in hex_wkt:
|
for g in self.geometries.hex_wkt:
|
||||||
wkb = buffer(a2b_hex(g.hex))
|
wkb = buffer(a2b_hex(g.hex))
|
||||||
geom_h = GEOSGeometry(wkb)
|
geom_h = GEOSGeometry(wkb)
|
||||||
# we need to do this so decimal places get normalised
|
# we need to do this so decimal places get normalised
|
||||||
|
@ -173,7 +180,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
def test01h_ewkt(self):
|
def test01h_ewkt(self):
|
||||||
"Testing EWKT."
|
"Testing EWKT."
|
||||||
srid = 32140
|
srid = 32140
|
||||||
for p in polygons:
|
for p in self.geometries.polygons:
|
||||||
ewkt = 'SRID=%d;%s' % (srid, p.wkt)
|
ewkt = 'SRID=%d;%s' % (srid, p.wkt)
|
||||||
poly = fromstr(ewkt)
|
poly = fromstr(ewkt)
|
||||||
self.assertEqual(srid, poly.srid)
|
self.assertEqual(srid, poly.srid)
|
||||||
|
@ -183,7 +190,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
def test01i_json(self):
|
def test01i_json(self):
|
||||||
"Testing GeoJSON input/output (via GDAL)."
|
"Testing GeoJSON input/output (via GDAL)."
|
||||||
if not gdal or not gdal.GEOJSON: return
|
if not gdal or not gdal.GEOJSON: return
|
||||||
for g in json_geoms:
|
for g in self.geometries.json_geoms:
|
||||||
geom = GEOSGeometry(g.wkt)
|
geom = GEOSGeometry(g.wkt)
|
||||||
if not hasattr(g, 'not_equal'):
|
if not hasattr(g, 'not_equal'):
|
||||||
self.assertEqual(g.json, geom.json)
|
self.assertEqual(g.json, geom.json)
|
||||||
|
@ -225,7 +232,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
def test02a_points(self):
|
def test02a_points(self):
|
||||||
"Testing Point objects."
|
"Testing Point objects."
|
||||||
prev = fromstr('POINT(0 0)')
|
prev = fromstr('POINT(0 0)')
|
||||||
for p in points:
|
for p in self.geometries.points:
|
||||||
# Creating the point from the WKT
|
# Creating the point from the WKT
|
||||||
pnt = fromstr(p.wkt)
|
pnt = fromstr(p.wkt)
|
||||||
self.assertEqual(pnt.geom_type, 'Point')
|
self.assertEqual(pnt.geom_type, 'Point')
|
||||||
|
@ -279,7 +286,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
def test02b_multipoints(self):
|
def test02b_multipoints(self):
|
||||||
"Testing MultiPoint objects."
|
"Testing MultiPoint objects."
|
||||||
for mp in multipoints:
|
for mp in self.geometries.multipoints:
|
||||||
mpnt = fromstr(mp.wkt)
|
mpnt = fromstr(mp.wkt)
|
||||||
self.assertEqual(mpnt.geom_type, 'MultiPoint')
|
self.assertEqual(mpnt.geom_type, 'MultiPoint')
|
||||||
self.assertEqual(mpnt.geom_typeid, 4)
|
self.assertEqual(mpnt.geom_typeid, 4)
|
||||||
|
@ -289,7 +296,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
self.assertRaises(GEOSIndexError, mpnt.__getitem__, len(mpnt))
|
self.assertRaises(GEOSIndexError, mpnt.__getitem__, len(mpnt))
|
||||||
self.assertEqual(mp.centroid, mpnt.centroid.tuple)
|
self.assertEqual(mp.centroid, mpnt.centroid.tuple)
|
||||||
self.assertEqual(mp.points, tuple(m.tuple for m in mpnt))
|
self.assertEqual(mp.coords, tuple(m.tuple for m in mpnt))
|
||||||
for p in mpnt:
|
for p in mpnt:
|
||||||
self.assertEqual(p.geom_type, 'Point')
|
self.assertEqual(p.geom_type, 'Point')
|
||||||
self.assertEqual(p.geom_typeid, 0)
|
self.assertEqual(p.geom_typeid, 0)
|
||||||
|
@ -299,7 +306,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
def test03a_linestring(self):
|
def test03a_linestring(self):
|
||||||
"Testing LineString objects."
|
"Testing LineString objects."
|
||||||
prev = fromstr('POINT(0 0)')
|
prev = fromstr('POINT(0 0)')
|
||||||
for l in linestrings:
|
for l in self.geometries.linestrings:
|
||||||
ls = fromstr(l.wkt)
|
ls = fromstr(l.wkt)
|
||||||
self.assertEqual(ls.geom_type, 'LineString')
|
self.assertEqual(ls.geom_type, 'LineString')
|
||||||
self.assertEqual(ls.geom_typeid, 1)
|
self.assertEqual(ls.geom_typeid, 1)
|
||||||
|
@ -325,7 +332,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
def test03b_multilinestring(self):
|
def test03b_multilinestring(self):
|
||||||
"Testing MultiLineString objects."
|
"Testing MultiLineString objects."
|
||||||
prev = fromstr('POINT(0 0)')
|
prev = fromstr('POINT(0 0)')
|
||||||
for l in multilinestrings:
|
for l in self.geometries.multilinestrings:
|
||||||
ml = fromstr(l.wkt)
|
ml = fromstr(l.wkt)
|
||||||
self.assertEqual(ml.geom_type, 'MultiLineString')
|
self.assertEqual(ml.geom_type, 'MultiLineString')
|
||||||
self.assertEqual(ml.geom_typeid, 5)
|
self.assertEqual(ml.geom_typeid, 5)
|
||||||
|
@ -348,7 +355,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
def test04_linearring(self):
|
def test04_linearring(self):
|
||||||
"Testing LinearRing objects."
|
"Testing LinearRing objects."
|
||||||
for rr in linearrings:
|
for rr in self.geometries.linearrings:
|
||||||
lr = fromstr(rr.wkt)
|
lr = fromstr(rr.wkt)
|
||||||
self.assertEqual(lr.geom_type, 'LinearRing')
|
self.assertEqual(lr.geom_type, 'LinearRing')
|
||||||
self.assertEqual(lr.geom_typeid, 2)
|
self.assertEqual(lr.geom_typeid, 2)
|
||||||
|
@ -371,7 +378,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
self.assertEqual(bbox, p.extent)
|
self.assertEqual(bbox, p.extent)
|
||||||
|
|
||||||
prev = fromstr('POINT(0 0)')
|
prev = fromstr('POINT(0 0)')
|
||||||
for p in polygons:
|
for p in self.geometries.polygons:
|
||||||
# Creating the Polygon, testing its properties.
|
# Creating the Polygon, testing its properties.
|
||||||
poly = fromstr(p.wkt)
|
poly = fromstr(p.wkt)
|
||||||
self.assertEqual(poly.geom_type, 'Polygon')
|
self.assertEqual(poly.geom_type, 'Polygon')
|
||||||
|
@ -430,7 +437,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
"Testing MultiPolygon objects."
|
"Testing MultiPolygon objects."
|
||||||
print "\nBEGIN - expecting GEOS_NOTICE; safe to ignore.\n"
|
print "\nBEGIN - expecting GEOS_NOTICE; safe to ignore.\n"
|
||||||
prev = fromstr('POINT (0 0)')
|
prev = fromstr('POINT (0 0)')
|
||||||
for mp in multipolygons:
|
for mp in self.geometries.multipolygons:
|
||||||
mpoly = fromstr(mp.wkt)
|
mpoly = fromstr(mp.wkt)
|
||||||
self.assertEqual(mpoly.geom_type, 'MultiPolygon')
|
self.assertEqual(mpoly.geom_type, 'MultiPolygon')
|
||||||
self.assertEqual(mpoly.geom_typeid, 6)
|
self.assertEqual(mpoly.geom_typeid, 6)
|
||||||
|
@ -456,7 +463,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
# These tests are needed to ensure sanity with writable geometries.
|
# These tests are needed to ensure sanity with writable geometries.
|
||||||
|
|
||||||
# Getting a polygon with interior rings, and pulling out the interior rings
|
# Getting a polygon with interior rings, and pulling out the interior rings
|
||||||
poly = fromstr(polygons[1].wkt)
|
poly = fromstr(self.geometries.polygons[1].wkt)
|
||||||
ring1 = poly[0]
|
ring1 = poly[0]
|
||||||
ring2 = poly[1]
|
ring2 = poly[1]
|
||||||
|
|
||||||
|
@ -472,12 +479,9 @@ class GEOSTest(unittest.TestCase):
|
||||||
# Access to these rings is OK since they are clones.
|
# Access to these rings is OK since they are clones.
|
||||||
s1, s2 = str(ring1), str(ring2)
|
s1, s2 = str(ring1), str(ring2)
|
||||||
|
|
||||||
# The previous hijinks tests are now moot because only clones are
|
|
||||||
# now used =)
|
|
||||||
|
|
||||||
def test08_coord_seq(self):
|
def test08_coord_seq(self):
|
||||||
"Testing Coordinate Sequence objects."
|
"Testing Coordinate Sequence objects."
|
||||||
for p in polygons:
|
for p in self.geometries.polygons:
|
||||||
if p.ext_ring_cs:
|
if p.ext_ring_cs:
|
||||||
# Constructing the polygon and getting the coordinate sequence
|
# Constructing the polygon and getting the coordinate sequence
|
||||||
poly = fromstr(p.wkt)
|
poly = fromstr(p.wkt)
|
||||||
|
@ -506,22 +510,18 @@ class GEOSTest(unittest.TestCase):
|
||||||
"Testing relate() and relate_pattern()."
|
"Testing relate() and relate_pattern()."
|
||||||
g = fromstr('POINT (0 0)')
|
g = fromstr('POINT (0 0)')
|
||||||
self.assertRaises(GEOSException, g.relate_pattern, 0, 'invalid pattern, yo')
|
self.assertRaises(GEOSException, g.relate_pattern, 0, 'invalid pattern, yo')
|
||||||
for i in xrange(len(relate_geoms)):
|
for rg in self.geometries.relate_geoms:
|
||||||
g_tup = relate_geoms[i]
|
a = fromstr(rg.wkt_a)
|
||||||
a = fromstr(g_tup[0].wkt)
|
b = fromstr(rg.wkt_b)
|
||||||
b = fromstr(g_tup[1].wkt)
|
self.assertEqual(rg.result, a.relate_pattern(b, rg.pattern))
|
||||||
pat = g_tup[2]
|
self.assertEqual(rg.pattern, a.relate(b))
|
||||||
result = g_tup[3]
|
|
||||||
self.assertEqual(result, a.relate_pattern(b, pat))
|
|
||||||
self.assertEqual(pat, a.relate(b))
|
|
||||||
|
|
||||||
def test10_intersection(self):
|
def test10_intersection(self):
|
||||||
"Testing intersects() and intersection()."
|
"Testing intersects() and intersection()."
|
||||||
for i in xrange(len(topology_geoms)):
|
for i in xrange(len(self.geometries.topology_geoms)):
|
||||||
g_tup = topology_geoms[i]
|
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
|
||||||
a = fromstr(g_tup[0].wkt)
|
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
|
||||||
b = fromstr(g_tup[1].wkt)
|
i1 = fromstr(self.geometries.intersect_geoms[i].wkt)
|
||||||
i1 = fromstr(intersect_geoms[i].wkt)
|
|
||||||
self.assertEqual(True, a.intersects(b))
|
self.assertEqual(True, a.intersects(b))
|
||||||
i2 = a.intersection(b)
|
i2 = a.intersection(b)
|
||||||
self.assertEqual(i1, i2)
|
self.assertEqual(i1, i2)
|
||||||
|
@ -531,11 +531,10 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
def test11_union(self):
|
def test11_union(self):
|
||||||
"Testing union()."
|
"Testing union()."
|
||||||
for i in xrange(len(topology_geoms)):
|
for i in xrange(len(self.geometries.topology_geoms)):
|
||||||
g_tup = topology_geoms[i]
|
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
|
||||||
a = fromstr(g_tup[0].wkt)
|
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
|
||||||
b = fromstr(g_tup[1].wkt)
|
u1 = fromstr(self.geometries.union_geoms[i].wkt)
|
||||||
u1 = fromstr(union_geoms[i].wkt)
|
|
||||||
u2 = a.union(b)
|
u2 = a.union(b)
|
||||||
self.assertEqual(u1, u2)
|
self.assertEqual(u1, u2)
|
||||||
self.assertEqual(u1, a | b) # __or__ is union operator
|
self.assertEqual(u1, a | b) # __or__ is union operator
|
||||||
|
@ -544,11 +543,10 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
def test12_difference(self):
|
def test12_difference(self):
|
||||||
"Testing difference()."
|
"Testing difference()."
|
||||||
for i in xrange(len(topology_geoms)):
|
for i in xrange(len(self.geometries.topology_geoms)):
|
||||||
g_tup = topology_geoms[i]
|
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
|
||||||
a = fromstr(g_tup[0].wkt)
|
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
|
||||||
b = fromstr(g_tup[1].wkt)
|
d1 = fromstr(self.geometries.diff_geoms[i].wkt)
|
||||||
d1 = fromstr(diff_geoms[i].wkt)
|
|
||||||
d2 = a.difference(b)
|
d2 = a.difference(b)
|
||||||
self.assertEqual(d1, d2)
|
self.assertEqual(d1, d2)
|
||||||
self.assertEqual(d1, a - b) # __sub__ is difference operator
|
self.assertEqual(d1, a - b) # __sub__ is difference operator
|
||||||
|
@ -557,11 +555,10 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
def test13_symdifference(self):
|
def test13_symdifference(self):
|
||||||
"Testing sym_difference()."
|
"Testing sym_difference()."
|
||||||
for i in xrange(len(topology_geoms)):
|
for i in xrange(len(self.geometries.topology_geoms)):
|
||||||
g_tup = topology_geoms[i]
|
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
|
||||||
a = fromstr(g_tup[0].wkt)
|
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
|
||||||
b = fromstr(g_tup[1].wkt)
|
d1 = fromstr(self.geometries.sdiff_geoms[i].wkt)
|
||||||
d1 = fromstr(sdiff_geoms[i].wkt)
|
|
||||||
d2 = a.sym_difference(b)
|
d2 = a.sym_difference(b)
|
||||||
self.assertEqual(d1, d2)
|
self.assertEqual(d1, d2)
|
||||||
self.assertEqual(d1, a ^ b) # __xor__ is symmetric difference operator
|
self.assertEqual(d1, a ^ b) # __xor__ is symmetric difference operator
|
||||||
|
@ -570,18 +567,19 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
def test14_buffer(self):
|
def test14_buffer(self):
|
||||||
"Testing buffer()."
|
"Testing buffer()."
|
||||||
for i in xrange(len(buffer_geoms)):
|
for bg in self.geometries.buffer_geoms:
|
||||||
g_tup = buffer_geoms[i]
|
g = fromstr(bg.wkt)
|
||||||
g = fromstr(g_tup[0].wkt)
|
|
||||||
|
|
||||||
# The buffer we expect
|
# The buffer we expect
|
||||||
exp_buf = fromstr(g_tup[1].wkt)
|
exp_buf = fromstr(bg.buffer_wkt)
|
||||||
|
quadsegs = bg.quadsegs
|
||||||
|
width = bg.width
|
||||||
|
|
||||||
# Can't use a floating-point for the number of quadsegs.
|
# Can't use a floating-point for the number of quadsegs.
|
||||||
self.assertRaises(ctypes.ArgumentError, g.buffer, g_tup[2], float(g_tup[3]))
|
self.assertRaises(ctypes.ArgumentError, g.buffer, width, float(quadsegs))
|
||||||
|
|
||||||
# Constructing our buffer
|
# Constructing our buffer
|
||||||
buf = g.buffer(g_tup[2], g_tup[3])
|
buf = g.buffer(width, quadsegs)
|
||||||
self.assertEqual(exp_buf.num_coords, buf.num_coords)
|
self.assertEqual(exp_buf.num_coords, buf.num_coords)
|
||||||
self.assertEqual(len(exp_buf), len(buf))
|
self.assertEqual(len(exp_buf), len(buf))
|
||||||
|
|
||||||
|
@ -605,7 +603,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
self.assertRaises(ctypes.ArgumentError, pnt.set_srid, '4326')
|
self.assertRaises(ctypes.ArgumentError, pnt.set_srid, '4326')
|
||||||
|
|
||||||
# Testing SRID keyword on fromstr(), and on Polygon rings.
|
# Testing SRID keyword on fromstr(), and on Polygon rings.
|
||||||
poly = fromstr(polygons[1].wkt, srid=4269)
|
poly = fromstr(self.geometries.polygons[1].wkt, srid=4269)
|
||||||
self.assertEqual(4269, poly.srid)
|
self.assertEqual(4269, poly.srid)
|
||||||
for ring in poly: self.assertEqual(4269, ring.srid)
|
for ring in poly: self.assertEqual(4269, ring.srid)
|
||||||
poly.srid = 4326
|
poly.srid = 4326
|
||||||
|
@ -636,7 +634,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
def test16_mutable_geometries(self):
|
def test16_mutable_geometries(self):
|
||||||
"Testing the mutability of Polygons and Geometry Collections."
|
"Testing the mutability of Polygons and Geometry Collections."
|
||||||
### Testing the mutability of Polygons ###
|
### Testing the mutability of Polygons ###
|
||||||
for p in polygons:
|
for p in self.geometries.polygons:
|
||||||
poly = fromstr(p.wkt)
|
poly = fromstr(p.wkt)
|
||||||
|
|
||||||
# Should only be able to use __setitem__ with LinearRing geometries.
|
# Should only be able to use __setitem__ with LinearRing geometries.
|
||||||
|
@ -655,7 +653,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
self.assertEqual(poly[0], new_shell)
|
self.assertEqual(poly[0], new_shell)
|
||||||
|
|
||||||
### Testing the mutability of Geometry Collections
|
### Testing the mutability of Geometry Collections
|
||||||
for tg in multipoints:
|
for tg in self.geometries.multipoints:
|
||||||
mp = fromstr(tg.wkt)
|
mp = fromstr(tg.wkt)
|
||||||
for i in range(len(mp)):
|
for i in range(len(mp)):
|
||||||
# Creating a random point.
|
# Creating a random point.
|
||||||
|
@ -670,7 +668,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
|
|
||||||
# MultiPolygons involve much more memory management because each
|
# MultiPolygons involve much more memory management because each
|
||||||
# Polygon w/in the collection has its own rings.
|
# Polygon w/in the collection has its own rings.
|
||||||
for tg in multipolygons:
|
for tg in self.geometries.multipolygons:
|
||||||
mpoly = fromstr(tg.wkt)
|
mpoly = fromstr(tg.wkt)
|
||||||
for i in xrange(len(mpoly)):
|
for i in xrange(len(mpoly)):
|
||||||
poly = mpoly[i]
|
poly = mpoly[i]
|
||||||
|
@ -791,10 +789,10 @@ class GEOSTest(unittest.TestCase):
|
||||||
"Testing GeometryCollection handling of other collections."
|
"Testing GeometryCollection handling of other collections."
|
||||||
# Creating a GeometryCollection WKT string composed of other
|
# Creating a GeometryCollection WKT string composed of other
|
||||||
# collections and polygons.
|
# collections and polygons.
|
||||||
coll = [mp.wkt for mp in multipolygons if mp.valid]
|
coll = [mp.wkt for mp in self.geometries.multipolygons if mp.valid]
|
||||||
coll.extend([mls.wkt for mls in multilinestrings])
|
coll.extend([mls.wkt for mls in self.geometries.multilinestrings])
|
||||||
coll.extend([p.wkt for p in polygons])
|
coll.extend([p.wkt for p in self.geometries.polygons])
|
||||||
coll.extend([mp.wkt for mp in multipoints])
|
coll.extend([mp.wkt for mp in self.geometries.multipoints])
|
||||||
gc_wkt = 'GEOMETRYCOLLECTION(%s)' % ','.join(coll)
|
gc_wkt = 'GEOMETRYCOLLECTION(%s)' % ','.join(coll)
|
||||||
|
|
||||||
# Should construct ok from WKT
|
# Should construct ok from WKT
|
||||||
|
@ -862,7 +860,7 @@ class GEOSTest(unittest.TestCase):
|
||||||
# Extent of points is just the point itself repeated.
|
# Extent of points is just the point itself repeated.
|
||||||
self.assertEqual((5.23, 17.8, 5.23, 17.8), pnt.extent)
|
self.assertEqual((5.23, 17.8, 5.23, 17.8), pnt.extent)
|
||||||
# Testing on the 'real world' Polygon.
|
# Testing on the 'real world' Polygon.
|
||||||
poly = fromstr(polygons[3].wkt)
|
poly = fromstr(self.geometries.polygons[3].wkt)
|
||||||
ring = poly.shell
|
ring = poly.shell
|
||||||
x, y = ring.x, ring.y
|
x, y = ring.x, ring.y
|
||||||
xmin, ymin = min(x), min(y)
|
xmin, ymin = min(x), min(y)
|
||||||
|
@ -878,10 +876,10 @@ class GEOSTest(unittest.TestCase):
|
||||||
# and setting the SRID on some of them.
|
# and setting the SRID on some of them.
|
||||||
def get_geoms(lst, srid=None):
|
def get_geoms(lst, srid=None):
|
||||||
return [GEOSGeometry(tg.wkt, srid) for tg in lst]
|
return [GEOSGeometry(tg.wkt, srid) for tg in lst]
|
||||||
tgeoms = get_geoms(points)
|
tgeoms = get_geoms(self.geometries.points)
|
||||||
tgeoms.extend(get_geoms(multilinestrings, 4326))
|
tgeoms.extend(get_geoms(self.geometries.multilinestrings, 4326))
|
||||||
tgeoms.extend(get_geoms(polygons, 3084))
|
tgeoms.extend(get_geoms(self.geometries.polygons, 3084))
|
||||||
tgeoms.extend(get_geoms(multipolygons, 900913))
|
tgeoms.extend(get_geoms(self.geometries.multipolygons, 900913))
|
||||||
|
|
||||||
# The SRID won't be exported in GEOS 3.0 release candidates.
|
# The SRID won't be exported in GEOS 3.0 release candidates.
|
||||||
no_srid = self.null_srid == -1
|
no_srid = self.null_srid == -1
|
||||||
|
|
Binary file not shown.
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue