summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2015-11-05 13:25:44 +0500
committerTim Graham <timograham@gmail.com>2015-11-18 18:36:10 -0500
commit1e35dd1a053b620f065101c02069c8e142ebf8ec (patch)
treea54b454c66f20d3f52bbf292748f65571f5005f2 /django
parent7a452c5ce295679307bd81dd9b5f37b3cf762acf (diff)
Fixed #25663 -- Added checking of the number of points for LinearRing and LineString.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/gis/geos/linestring.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/django/contrib/gis/geos/linestring.py b/django/contrib/gis/geos/linestring.py
index df2a8145c7..7b74f7700a 100644
--- a/django/contrib/gis/geos/linestring.py
+++ b/django/contrib/gis/geos/linestring.py
@@ -36,16 +36,24 @@ class LineString(ProjectInterpolateMixin, GEOSGeometry):
# Getting the number of coords and the number of dimensions -- which
# must stay the same, e.g., no LineString((1, 2), (1, 2, 3)).
ncoords = len(coords)
- if coords:
- ndim = len(coords[0])
- else:
- raise TypeError('Cannot initialize on empty sequence.')
- self._checkdim(ndim)
+ if ncoords < self._minlength:
+ raise TypeError(
+ '%s requires at least %d points, got %s.' % (
+ self.__class__.__name__,
+ self._minlength,
+ ncoords,
+ )
+ )
+ ndim = None
# Incrementing through each of the coordinates and verifying
- for i in range(1, ncoords):
- if not isinstance(coords[i], (tuple, list, Point)):
- raise TypeError('each coordinate should be a sequence (list or tuple)')
- if len(coords[i]) != ndim:
+ for coord in coords:
+ if not isinstance(coord, (tuple, list, Point)):
+ raise TypeError('Each coordinate should be a sequence (list or tuple)')
+
+ if ndim is None:
+ ndim = len(coord)
+ self._checkdim(ndim)
+ elif len(coord) != ndim:
raise TypeError('Dimension mismatch.')
numpy_coords = False
elif numpy and isinstance(coords, numpy.ndarray):