44from ctypes import byref , c_void_p , c_double
55from warnings import warn
66
7- from shapely .errors import ShapelyDeprecationWarning
7+ from shapely .errors import GeometryTypeError , ShapelyDeprecationWarning
88from shapely .prepared import prep
99from shapely .geos import lgeos
1010from shapely .geometry .base import geom_factory , BaseGeometry , BaseMultipartGeometry
@@ -322,7 +322,7 @@ def id_func(x, y, z=None):
322322 elif geom .type .startswith ('Multi' ) or geom .type == 'GeometryCollection' :
323323 return type (geom )([transform (func , part ) for part in geom .geoms ])
324324 else :
325- raise ValueError ('Type %r not recognized' % geom .type )
325+ raise GeometryTypeError ('Type %r not recognized' % geom .type )
326326
327327
328328def nearest_points (g1 , g2 ):
@@ -391,9 +391,9 @@ def shared_paths(g1, g2):
391391 The second geometry
392392 """
393393 if not isinstance (g1 , LineString ):
394- raise TypeError ("First geometry must be a LineString" )
394+ raise GeometryTypeError ("First geometry must be a LineString" )
395395 if not isinstance (g2 , LineString ):
396- raise TypeError ("Second geometry must be a LineString" )
396+ raise GeometryTypeError ("Second geometry must be a LineString" )
397397 return (geom_factory (lgeos .methods ['shared_paths' ](g1 ._geom , g2 ._geom )))
398398
399399
@@ -402,9 +402,10 @@ class SplitOp:
402402 @staticmethod
403403 def _split_polygon_with_line (poly , splitter ):
404404 """Split a Polygon with a LineString"""
405-
406- assert (isinstance (poly , Polygon ))
407- assert (isinstance (splitter , LineString ))
405+ if not isinstance (poly , Polygon ):
406+ raise GeometryTypeError ("First argument must be a Polygon" )
407+ if not isinstance (splitter , LineString ):
408+ raise GeometryTypeError ("Second argument must be a LineString" )
408409
409410 union = poly .boundary .union (splitter )
410411
@@ -426,8 +427,10 @@ def _split_line_with_line(line, splitter):
426427 if splitter .type in ('Polygon' , 'MultiPolygon' ):
427428 splitter = splitter .boundary
428429
429- assert (isinstance (line , LineString ))
430- assert (isinstance (splitter , LineString ) or isinstance (splitter , MultiLineString ))
430+ if not isinstance (line , LineString ):
431+ raise GeometryTypeError ("First argument must be a LineString" )
432+ if not isinstance (splitter , LineString ) and not isinstance (splitter , MultiLineString ):
433+ raise GeometryTypeError ("Second argument must be either a LineString or a MultiLineString" )
431434
432435 # | s\l | Interior | Boundary | Exterior |
433436 # |----------|----------|----------|----------|
@@ -448,9 +451,10 @@ def _split_line_with_line(line, splitter):
448451 @staticmethod
449452 def _split_line_with_point (line , splitter ):
450453 """Split a LineString with a Point"""
451-
452- assert (isinstance (line , LineString ))
453- assert (isinstance (splitter , Point ))
454+ if not isinstance (line , LineString ):
455+ raise GeometryTypeError ("First argument must be a LineString" )
456+ if not isinstance (splitter , Point ):
457+ raise GeometryTypeError ("Second argument must be a Point" )
454458
455459 # check if point is in the interior of the line
456460 if not line .relate_pattern (splitter , '0********' ):
@@ -494,8 +498,10 @@ def _split_line_with_point(line, splitter):
494498 def _split_line_with_multipoint (line , splitter ):
495499 """Split a LineString with a MultiPoint"""
496500
497- assert (isinstance (line , LineString ))
498- assert (isinstance (splitter , MultiPoint ))
501+ if not isinstance (line , LineString ):
502+ raise GeometryTypeError ("First argument must be a LineString" )
503+ if not isinstance (splitter , MultiPoint ):
504+ raise GeometryTypeError ("Second argument must be a MultiPoint" )
499505
500506 chunks = [line ]
501507 for pt in splitter .geoms :
@@ -549,16 +555,16 @@ def split(geom, splitter):
549555 elif splitter .type in ('MultiPoint' ):
550556 split_func = SplitOp ._split_line_with_multipoint
551557 else :
552- raise ValueError ("Splitting a LineString with a %s is not supported" % splitter .type )
558+ raise GeometryTypeError ("Splitting a LineString with a %s is not supported" % splitter .type )
553559
554560 elif geom .type == 'Polygon' :
555561 if splitter .type == 'LineString' :
556562 split_func = SplitOp ._split_polygon_with_line
557563 else :
558- raise ValueError ("Splitting a Polygon with a %s is not supported" % splitter .type )
564+ raise GeometryTypeError ("Splitting a Polygon with a %s is not supported" % splitter .type )
559565
560566 else :
561- raise ValueError ("Splitting %s geometry is not supported" % geom .type )
567+ raise GeometryTypeError ("Splitting %s geometry is not supported" % geom .type )
562568
563569 return GeometryCollection (split_func (geom , splitter ))
564570
@@ -625,7 +631,7 @@ def substring(geom, start_dist, end_dist, normalized=False):
625631 """
626632
627633 if not isinstance (geom , LineString ):
628- raise TypeError ("Can only calculate a substring of LineString geometries. A %s was provided." % geom .type )
634+ raise GeometryTypeError ("Can only calculate a substring of LineString geometries. A %s was provided." % geom .type )
629635
630636 # Filter out cases in which to return a point
631637 if start_dist == end_dist :
0 commit comments