1.1 --- a/django/contrib/gis/geos/linestring.py Thu Jan 29 15:02:43 2009 -0600
1.2 +++ b/django/contrib/gis/geos/linestring.py Sat Jan 31 15:18:50 2009 -0600
1.3 @@ -5,6 +5,9 @@
1.4 from django.contrib.gis.geos import prototypes as capi
1.5
1.6 class LineString(GEOSGeometry):
1.7 + _init_func = capi.create_linestring
1.8 + _canSetSingle = True
1.9 + _assignExtendedSlice = GEOSGeometry._assignExtendedSlice_no_rebuild
1.10
1.11 #### Python 'magic' routines ####
1.12 def __init__(self, *args, **kwargs):
1.13 @@ -55,25 +58,38 @@
1.14 elif isinstance(coords[i], Point): cs[i] = coords[i].tuple
1.15 else: cs[i] = coords[i]
1.16
1.17 - # Getting the correct initialization function
1.18 - if kwargs.get('ring', False):
1.19 - func = capi.create_linearring
1.20 - else:
1.21 - func = capi.create_linestring
1.22 -
1.23 # If SRID was passed in with the keyword arguments
1.24 srid = kwargs.get('srid', None)
1.25
1.26 # Calling the base geometry initialization with the returned pointer
1.27 # from the function.
1.28 - super(LineString, self).__init__(func(cs.ptr), srid=srid)
1.29 + super(LineString, self).__init__(self._init_func(cs.ptr), srid=srid)
1.30
1.31 - def __getitem__(self, index):
1.32 - "Gets the point at the specified index."
1.33 + def _getItemExternal(self, index):
1.34 + self._checkindex(index)
1.35 return self._cs[index]
1.36 + _getItemInternal = _getItemExternal
1.37
1.38 - def __setitem__(self, index, value):
1.39 - "Sets the point at the specified index, e.g., line_str[0] = (1, 2)."
1.40 + def _setCollection(self, length, items):
1.41 + ndim = self._cs.dims #
1.42 + hasz = self._cs.hasz # I don't understand why these are different
1.43 +
1.44 + # create a new coordinate sequence and populate accordingly
1.45 + cs = GEOSCoordSeq(capi.create_cs(length, ndim), z=hasz)
1.46 + for i, c in enumerate(items):
1.47 + cs[i] = c
1.48 +
1.49 + ptr = self._init_func(cs.ptr)
1.50 + if ptr:
1.51 + capi.destroy_geom(self.ptr)
1.52 + self._ptr = ptr
1.53 + self._post_init(self.srid)
1.54 + else:
1.55 + # can this happen?
1.56 + raise GEOSException('Geometry resulting from slice deletion was invalid.')
1.57 +
1.58 + def _setSingle(self, index, value):
1.59 + self._checkindex(index)
1.60 self._cs[index] = value
1.61
1.62 def __iter__(self):
1.63 @@ -127,7 +143,4 @@
1.64
1.65 # LinearRings are LineStrings used within Polygons.
1.66 class LinearRing(LineString):
1.67 - def __init__(self, *args, **kwargs):
1.68 - "Overriding the initialization function to set the ring keyword."
1.69 - kwargs['ring'] = True # Setting the ring keyword argument to True
1.70 - super(LinearRing, self).__init__(*args, **kwargs)
1.71 + _init_func = capi.create_linearring