Skip to content

Commit

Permalink
test: Update comparisons for different WKT point orders
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Dec 10, 2023
1 parent fff54c9 commit 193e969
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
10 changes: 8 additions & 2 deletions boundaries/tests/test_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,11 @@ def test_unary_union(self):
boundary = Boundary(shape='MULTIPOLYGON (((0 0,0 5,2.5 5.0001,5 5,0 0)))')
boundary.unary_union(Geometry(OGRGeometry('MULTIPOLYGON (((0 0,5 0,5 5,0 0)))')))

self.assertEqual(boundary.shape.ogr.wkt, 'MULTIPOLYGON (((5 5,5 0,0 0,0 5,2.5 5.0001,5 5)))')
self.assertEqual(boundary.simple_shape.ogr.wkt, 'MULTIPOLYGON (((5 5,5 0,0 0,0 5,5 5)))')
self.assertEqual(
boundary.shape.ogr.difference(OGRGeometry('MULTIPOLYGON (((5 5,5 0,0 0,0 5,2.5 5.0001,5 5)))')).wkt,
'POLYGON EMPTY',
)
self.assertEqual(
boundary.simple_shape.ogr.difference(OGRGeometry('MULTIPOLYGON (((5 5,5 0,0 0,0 5,5 5)))')).wkt,
'POLYGON EMPTY',
)
5 changes: 4 additions & 1 deletion boundaries/tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def test_unary_union(self):
geometry = Geometry(OGRGeometry('MULTIPOLYGON (((0 0,0 5,5 5,0 0)),((0 0,5 0,5 5,0 0)))')).unary_union()
self.assertIsInstance(geometry, Geometry)
self.assertEqual(geometry.geometry.geom_name, 'MULTIPOLYGON')
self.assertEqual(geometry.wkt, 'MULTIPOLYGON (((0 0,0 5,5 5,5 0,0 0)))')
self.assertEqual(
geometry.geometry.difference(OGRGeometry('MULTIPOLYGON (((0 0,0 5,5 5,5 0,0 0)))')).wkt,
'POLYGON EMPTY',
)

def test_merge_with_ogrgeometry(self):
other = OGRGeometry('MULTIPOLYGON (((5 0,5 3,2 0,5 0)))')
Expand Down
10 changes: 4 additions & 6 deletions boundaries/tests/test_loadshapefiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import date
from zipfile import BadZipfile

from django.contrib.gis.gdal import OGRGeometry
from django.core.management import call_command
from django.test import TestCase
from testfixtures import LogCapture
Expand Down Expand Up @@ -196,12 +197,9 @@ def test_union_merge_strategy(self):
Command().load_boundary(self.feature, 'invalid')

boundary = Command().load_boundary(self.feature, 'union')
try: # Django < 2.2
self.assertEqual(boundary.shape.ogr.wkt, 'MULTIPOLYGON (((0.0001 0.0001,0 5,0 5,0 5,5 5,5 5,0.0001 0.0001)))')
self.assertEqual(boundary.simple_shape.ogr.wkt, 'MULTIPOLYGON (((0.0001 0.0001,0 5,5 5,5 5,0.0001 0.0001)))')
except AssertionError:
self.assertEqual(boundary.shape.ogr.wkt, 'MULTIPOLYGON (((0.0001 0.0001,0 5,5 5,0.0001 0.0001)))')
self.assertEqual(boundary.simple_shape.ogr.wkt, 'MULTIPOLYGON (((0.0001 0.0001,0 5,5 5,0.0001 0.0001)))')
expected = OGRGeometry('MULTIPOLYGON (((0.0001 0.0001,0 5,5 5,0.0001 0.0001)))')
self.assertEqual(boundary.shape.ogr.difference(expected).wkt, 'POLYGON EMPTY')
self.assertEqual(boundary.simple_shape.ogr.difference(expected).wkt, 'POLYGON EMPTY')
self.assertRegex(boundary.centroid.ogr.wkt, r'\APOINT \(1\.6667 3\.3333666666666+7\)\Z')
self.assertEqual(boundary.extent, (0.0, 0.0001, 5.0, 5.0))

Expand Down

0 comments on commit 193e969

Please sign in to comment.