Skip to content

Commit 69d2fe2

Browse files
Clean-up use of delegated/impl in geometry/base.py
1 parent 4f28db9 commit 69d2fe2

5 files changed

Lines changed: 19 additions & 52 deletions

File tree

shapely/geometry/base.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from shapely.errors import ShapelyDeprecationWarning
2424
from shapely.geos import WKBWriter, WKTWriter
2525
from shapely.geos import lgeos
26-
from shapely.impl import DefaultImplementation, delegated
26+
from shapely.impl import DefaultImplementation
2727

2828
log = logging.getLogger(__name__)
2929

@@ -356,7 +356,6 @@ def centroid(self):
356356
"""Returns the geometric center of the object"""
357357
return pygeos.centroid(self)
358358

359-
@delegated
360359
def representative_point(self):
361360
"""Returns a point guaranteed to be within the object, cheaply."""
362361
return pygeos.point_on_surface(self)
@@ -506,7 +505,6 @@ def buffer(self, distance, resolution=16, quadsegs=None,
506505
single_sided=single_sided
507506
)
508507

509-
@delegated
510508
def simplify(self, tolerance, preserve_topology=True):
511509
"""Returns a simplified geometry produced by the Douglas-Peucker
512510
algorithm
@@ -657,22 +655,15 @@ def relate_pattern(self, other, pattern):
657655
# Linear referencing
658656
# ------------------
659657

660-
@delegated
661658
def project(self, other, normalized=False):
662659
"""Returns the distance along this geometry to a point nearest the
663660
specified point
664661
665662
If the normalized arg is True, return the distance normalized to the
666663
length of the linear geometry.
667664
"""
668-
if normalized:
669-
op = self.impl['project_normalized']
670-
else:
671-
op = self.impl['project']
672-
return op(self, other)
665+
return pygeos.line_locate_point(self, other, normalized=normalized)
673666

674-
@delegated
675-
@exceptNull
676667
def interpolate(self, distance, normalized=False):
677668
"""Return a point at the specified distance along a linear geometry
678669

tests/test_delegated.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/test_geos_err_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_error_handler_exception(tmpdir):
2828
assert "Expected number but encountered word: 'LOLWUT'" in log
2929

3030

31+
@shapely20_todo # logging is not yet implemented
3132
def test_error_handler(tmpdir):
3233
logger = logging.getLogger('shapely.geos')
3334
logfile = str(tmpdir.join('test_error.log'))

tests/test_linear_referencing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from shapely.geos import geos_version
33
from shapely.geometry import Point, LineString, MultiLineString
44

5+
import pygeos
6+
import pytest
7+
58

69
class LinearReferencingTestCase(unittest.TestCase):
710

@@ -32,7 +35,7 @@ def test_multiline_project(self):
3235

3336
@unittest.skipIf(geos_version < (3, 2, 0), 'GEOS 3.2.0 required')
3437
def test_not_supported_project(self):
35-
with self.assertRaises(TypeError):
38+
with pytest.raises(pygeos.GEOSException, match="IllegalArgumentException"):
3639
self.point.buffer(1.0).project(self.point)
3740

3841
@unittest.skipIf(geos_version < (3, 2, 0), 'GEOS 3.2.0 required')

tests/test_operations.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,18 @@ def test_interpolate(self):
8888
known_point = Point(1,1.5)
8989
interpolated_point = test_line.interpolate(.5, normalized=True)
9090
self.assertEqual(interpolated_point, known_point)
91-
92-
# Issue #653; should raise ValueError on exception
91+
92+
# Issue #653; should nog segfault for empty geometries
9393
empty_line = loads('LINESTRING EMPTY')
94-
assert(empty_line.is_empty)
95-
with pytest.raises(ValueError):
96-
empty_line.interpolate(.5, normalized=True)
97-
94+
assert empty_line.is_empty
95+
interpolated_point = empty_line.interpolate(.5, normalized=True)
96+
assert interpolated_point.is_empty
97+
98+
# invalid geometry should raise TypeError on exception
99+
polygon = loads('POLYGON EMPTY')
100+
with pytest.raises(TypeError, match="incorrect geometry type"):
101+
polygon.interpolate(.5, normalized=True)
102+
103+
98104
def test_suite():
99105
return unittest.TestLoader().loadTestsFromTestCase(OperationsTestCase)

0 commit comments

Comments
 (0)