diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2015-11-24 14:21:32 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-12-14 13:29:38 -0500 |
| commit | 5146e2cf984a83c2eb9d8102ea73ee0792a9528b (patch) | |
| tree | b464f59550d16d03a227eed0aab7adeb6dbcfca9 /django | |
| parent | 8035cee92293f3319919c8248c7787ba43c05917 (diff) | |
Fixed #25662 -- Allowed creation of empty GEOS geometries.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/gis/geos/collections.py | 3 | ||||
| -rw-r--r-- | django/contrib/gis/geos/linestring.py | 10 | ||||
| -rw-r--r-- | django/contrib/gis/geos/mutable_list.py | 2 | ||||
| -rw-r--r-- | django/contrib/gis/geos/point.py | 14 | ||||
| -rw-r--r-- | django/contrib/gis/geos/polygon.py | 6 | ||||
| -rw-r--r-- | django/contrib/gis/geos/prototypes/__init__.py | 11 | ||||
| -rw-r--r-- | django/contrib/gis/geos/prototypes/geom.py | 1 |
7 files changed, 28 insertions, 19 deletions
diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py index 0f27d2bcf9..becc6b0ce3 100644 --- a/django/contrib/gis/geos/collections.py +++ b/django/contrib/gis/geos/collections.py @@ -25,9 +25,6 @@ class GeometryCollection(GEOSGeometry): "Initializes a Geometry Collection from a sequence of Geometry objects." # Checking the arguments - if not args: - raise TypeError('Must provide at least one Geometry to initialize %s.' % self.__class__.__name__) - if len(args) == 1: # If only one geometry provided or a list of geometries is provided # in the first argument. diff --git a/django/contrib/gis/geos/linestring.py b/django/contrib/gis/geos/linestring.py index d0edd631ce..cf74aad7fa 100644 --- a/django/contrib/gis/geos/linestring.py +++ b/django/contrib/gis/geos/linestring.py @@ -35,7 +35,14 @@ class LineString(ProjectInterpolateMixin, GEOSGeometry): if not (isinstance(coords, (tuple, list)) or numpy and isinstance(coords, numpy.ndarray)): raise TypeError('Invalid initialization input for LineStrings.') + # If SRID was passed in with the keyword arguments + srid = kwargs.get('srid') + ncoords = len(coords) + if not ncoords: + super(LineString, self).__init__(self._init_func(None), srid=srid) + return + if ncoords < self._minlength: raise ValueError( '%s requires at least %d points, got %s.' % ( @@ -80,9 +87,6 @@ class LineString(ProjectInterpolateMixin, GEOSGeometry): else: cs[i] = coords[i] - # If SRID was passed in with the keyword arguments - srid = kwargs.get('srid') - # Calling the base geometry initialization with the returned pointer # from the function. super(LineString, self).__init__(self._init_func(cs.ptr), srid=srid) diff --git a/django/contrib/gis/geos/mutable_list.py b/django/contrib/gis/geos/mutable_list.py index 3fe9a4fbb6..8a613600c0 100644 --- a/django/contrib/gis/geos/mutable_list.py +++ b/django/contrib/gis/geos/mutable_list.py @@ -229,7 +229,7 @@ class ListMixin(object): # ### Private routines ### def _rebuild(self, newLen, newItems): - if newLen < self._minlength: + if newLen and newLen < self._minlength: raise ValueError('Must have at least %d items' % self._minlength) if self._maxlength is not None and newLen > self._maxlength: raise ValueError('Cannot have more than %d items' % self._maxlength) diff --git a/django/contrib/gis/geos/point.py b/django/contrib/gis/geos/point.py index 34a955e924..46972629d8 100644 --- a/django/contrib/gis/geos/point.py +++ b/django/contrib/gis/geos/point.py @@ -14,7 +14,7 @@ class Point(GEOSGeometry): _maxlength = 3 has_cs = True - def __init__(self, x, y=None, z=None, srid=None): + def __init__(self, x=None, y=None, z=None, srid=None): """ The Point object may be initialized with either a tuple, or individual parameters. @@ -23,22 +23,21 @@ class Point(GEOSGeometry): >>> p = Point((5, 23)) # 2D point, passed in as a tuple >>> p = Point(5, 23, 8) # 3D point, passed in with individual parameters """ - if isinstance(x, (tuple, list)): + if x is None: + coords = [] + elif isinstance(x, (tuple, list)): # Here a tuple or list was passed in under the `x` parameter. - ndim = len(x) coords = x elif isinstance(x, six.integer_types + (float,)) and isinstance(y, six.integer_types + (float,)): # Here X, Y, and (optionally) Z were passed in individually, as parameters. if isinstance(z, six.integer_types + (float,)): - ndim = 3 coords = [x, y, z] else: - ndim = 2 coords = [x, y] else: raise TypeError('Invalid parameters given for Point initialization.') - point = self._create_point(ndim, coords) + point = self._create_point(len(coords), coords) # Initializing using the address returned from the GEOS # createPoint factory. @@ -48,6 +47,9 @@ class Point(GEOSGeometry): """ Create a coordinate sequence, set X, Y, [Z], and create point """ + if not ndim: + return capi.create_point(None) + if ndim < 2 or ndim > 3: raise TypeError('Invalid point dimension: %s' % str(ndim)) diff --git a/django/contrib/gis/geos/polygon.py b/django/contrib/gis/geos/polygon.py index fdf7515bed..067730063f 100644 --- a/django/contrib/gis/geos/polygon.py +++ b/django/contrib/gis/geos/polygon.py @@ -29,7 +29,8 @@ class Polygon(GEOSGeometry): ... ((4, 4), (4, 6), (6, 6), (6, 4), (4, 4))) """ if not args: - raise TypeError('Must provide at least one LinearRing, or a tuple, to initialize a Polygon.') + super(Polygon, self).__init__(self._create_polygon(0, None), **kwargs) + return # Getting the ext_ring and init_holes parameters from the argument list ext_ring = args[0] @@ -73,6 +74,9 @@ class Polygon(GEOSGeometry): # _construct_ring will throw a TypeError if a parameter isn't a valid ring # If we cloned the pointers here, we wouldn't be able to clean up # in case of error. + if not length: + return capi.create_empty_polygon() + rings = [] for r in items: if isinstance(r, GEOM_PTR): diff --git a/django/contrib/gis/geos/prototypes/__init__.py b/django/contrib/gis/geos/prototypes/__init__.py index 595555897d..32073749d8 100644 --- a/django/contrib/gis/geos/prototypes/__init__.py +++ b/django/contrib/gis/geos/prototypes/__init__.py @@ -9,11 +9,12 @@ from django.contrib.gis.geos.prototypes.coordseq import ( # NOQA cs_gety, cs_getz, cs_setordinate, cs_setx, cs_sety, cs_setz, get_cs, ) from django.contrib.gis.geos.prototypes.geom import ( # NOQA - create_collection, create_linearring, create_linestring, create_point, - create_polygon, destroy_geom, from_hex, from_wkb, from_wkt, geom_clone, - geos_get_srid, geos_normalize, geos_set_srid, geos_type, geos_typeid, - get_dims, get_extring, get_geomn, get_intring, get_nrings, get_num_coords, - get_num_geoms, to_hex, to_wkb, to_wkt, + create_collection, create_empty_polygon, create_linearring, + create_linestring, create_point, create_polygon, destroy_geom, from_hex, + from_wkb, from_wkt, geom_clone, geos_get_srid, geos_normalize, + geos_set_srid, geos_type, geos_typeid, get_dims, get_extring, get_geomn, + get_intring, get_nrings, get_num_coords, get_num_geoms, to_hex, to_wkb, + to_wkt, ) from django.contrib.gis.geos.prototypes.misc import * # NOQA from django.contrib.gis.geos.prototypes.predicates import ( # NOQA diff --git a/django/contrib/gis/geos/prototypes/geom.py b/django/contrib/gis/geos/prototypes/geom.py index e4bd0b0a51..9e14f214dc 100644 --- a/django/contrib/gis/geos/prototypes/geom.py +++ b/django/contrib/gis/geos/prototypes/geom.py @@ -94,6 +94,7 @@ create_linearring = GeomOutput('GEOSGeom_createLinearRing', [CS_PTR]) # Polygon and collection creation routines are special and will not # have their argument types defined. create_polygon = GeomOutput('GEOSGeom_createPolygon', None) +create_empty_polygon = GeomOutput('GEOSGeom_createEmptyPolygon', None) create_collection = GeomOutput('GEOSGeom_createCollection', None) # Ring routines |
