Changeset 5760
- Timestamp:
- 07/25/07 20:55:37 (1 year ago)
- Files:
-
- django/branches/gis/django/contrib/gis/geos/base.py (modified) (4 diffs)
- django/branches/gis/django/contrib/gis/geos/collections.py (modified) (3 diffs)
- django/branches/gis/django/contrib/gis/geos/geometries.py (modified) (7 diffs)
- django/branches/gis/django/contrib/gis/geos/__init__.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/geos/libgeos.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/geos/base.py
r5749 r5760 13 13 import re 14 14 from warnings import warn 15 from django.contrib.gis.geos.libgeos import lgeos, GEOSPointer, HAS_NUMPY 15 from django.contrib.gis.geos.libgeos import lgeos, GEOSPointer, HAS_NUMPY, ISQLQuote 16 16 from django.contrib.gis.geos.error import GEOSException, GEOSGeometryIndexError 17 17 from django.contrib.gis.geos.coordseq import GEOSCoordSeq, create_cs … … 25 25 26 26 #### Python 'magic' routines #### 27 def __init__(self, geo_input, input_type=False, parent= False):27 def __init__(self, geo_input, input_type=False, parent=None, srid=None): 28 28 """The constructor for GEOS geometry objects. May take the following 29 29 strings as inputs, WKT ("wkt"), HEXEWKB ("hex", PostGIS-specific canonical form). … … 73 73 self._parent = GEOSPointer(0) 74 74 75 # Setting the SRID, if given. 76 if srid and isinstance(srid, int): self.srid = srid 77 75 78 # Setting the class type (e.g., 'Point', 'Polygon', etc.) 76 79 self.__class__ = GEOS_CLASSES[self.geom_type] … … 127 130 "Return the symmetric difference of this Geometry and the other." 128 131 return self.sym_difference(other) 132 133 #### Psycopg2 database adaptor routines #### 134 def __conform__(self, proto): 135 # Does the given protocol conform to what Psycopg2 expects? 136 if proto == ISQLQuote: 137 return self 138 else: 139 raise GEOSException, 'Error implementing psycopg2 protocol. Is psycopg2 installed?' 140 141 def getquoted(self): 142 "Returns a properly quoted string for use in PostgresSQL/PostGIS." 143 return "GeometryFromText('%s', %s)" % (self.wkt, self.srid or -1) 129 144 130 145 #### Coordinate Sequence Routines #### django/branches/gis/django/contrib/gis/geos/collections.py
r5742 r5760 29 29 _typeid = 7 30 30 31 def __init__(self, *args ):31 def __init__(self, *args, **kwargs): 32 32 self._ptr = GEOSPointer(0) # Initially NULL 33 33 self._geoms = {} … … 62 62 63 63 # Calling the parent class, using the pointer returned from GEOS createCollection() 64 super(GeometryCollection, self).__init__(lgeos.GEOSGeom_createCollection(c_int(self._typeid), byref(geoms), c_uint(ngeom)) )64 super(GeometryCollection, self).__init__(lgeos.GEOSGeom_createCollection(c_int(self._typeid), byref(geoms), c_uint(ngeom)), **kwargs) 65 65 66 66 def __del__(self): … … 86 86 # Checking the index and returning the corresponding GEOS geometry. 87 87 self._checkindex(index) 88 return GEOSGeometry(self._geoms[index], parent=self._ptr )88 return GEOSGeometry(self._geoms[index], parent=self._ptr, srid=self.srid) 89 89 90 90 def __iter__(self): django/branches/gis/django/contrib/gis/geos/geometries.py
r5742 r5760 15 15 class Point(GEOSGeometry): 16 16 17 def __init__(self, x, y=None, z=None ):17 def __init__(self, x, y=None, z=None, srid=None): 18 18 """The Point object may be initialized with either a tuple, or individual 19 19 parameters. For example: … … 57 57 58 58 # Initializing from the geometry, and getting a Python object 59 super(Point, self).__init__(lgeos.GEOSGeom_createPoint(cs) )59 super(Point, self).__init__(lgeos.GEOSGeom_createPoint(cs), srid=srid) 60 60 61 61 def __len__(self): … … 176 176 else: 177 177 func = lgeos.GEOSGeom_createLineString 178 179 # If SRID was passed in with the keyword arguments 180 srid = kwargs.get('srid', None) 178 181 179 182 # Calling the base geometry initialization with the returned pointer from the function. 180 super(LineString, self).__init__(func(cs._ptr.coordseq()) )183 super(LineString, self).__init__(func(cs._ptr.coordseq()), srid=srid) 181 184 182 185 def __getitem__(self, index): … … 236 239 # LinearRings are LineStrings used within Polygons. 237 240 class LinearRing(LineString): 238 def __init__(self, *args ):241 def __init__(self, *args, **kwargs): 239 242 "Overriding the initialization function to set the ring keyword." 240 kwargs = {'ring' : True}243 kwargs['ring'] = True # Setting the ring keyword argument to True 241 244 super(LinearRing, self).__init__(*args, **kwargs) 242 245 243 246 class Polygon(GEOSGeometry): 244 247 245 def __init__(self, *args ):248 def __init__(self, *args, **kwargs): 246 249 """Initializes on an exterior ring and a sequence of holes (both instances of LinearRings. 247 250 All LinearRing instances used for creation will become owned by this Polygon. … … 281 284 282 285 # Calling with the GEOS createPolygon factory. 283 super(Polygon, self).__init__(lgeos.GEOSGeom_createPolygon(shell, byref(holes), c_uint(nholes)) )286 super(Polygon, self).__init__(lgeos.GEOSGeom_createPolygon(shell, byref(holes), c_uint(nholes)), **kwargs) 284 287 285 288 def __del__(self): … … 341 344 # Returning the ring from the internal ring dictionary (have to 342 345 # add one to the index) 343 return GEOSGeometry(self._rings[ring_i+1], parent=self._ptr )346 return GEOSGeometry(self._rings[ring_i+1], parent=self._ptr, srid=self.srid) 344 347 345 348 #### Polygon Properties #### … … 357 360 def get_ext_ring(self): 358 361 "Gets the exterior ring of the Polygon." 359 return GEOSGeometry(self._rings[0], parent=self._ptr )362 return GEOSGeometry(self._rings[0], parent=self._ptr, srid=self.srid) 360 363 361 364 def set_ext_ring(self): django/branches/gis/django/contrib/gis/geos/__init__.py
r5742 r5760 35 35 from error import GEOSException, GEOSGeometryIndexError 36 36 37 def fromstr(wkt_or_hex ):37 def fromstr(wkt_or_hex, **kwargs): 38 38 "Given a string value (wkt or hex), returns a GEOSGeometry object." 39 return GEOSGeometry(wkt_or_hex )39 return GEOSGeometry(wkt_or_hex, **kwargs) 40 40 41 41 def hex_to_wkt(hex): django/branches/gis/django/contrib/gis/geos/libgeos.py
r5742 r5760 3 3 as the notice and error handler function callbacks (get called 4 4 when an error occurs in GEOS). 5 6 This module also houses GEOS Pointer utilities, including the 7 GEOSPointer class, get_pointer_arr(), GEOM_PTR, and init_from_geom(). 5 8 """ 6 9 … … 15 18 except ImportError: 16 19 HAS_NUMPY = False 20 21 # Psycopg2 supported? 22 try: 23 from psycopg2.extensions import ISQLQuote 24 except ImportError: 25 ISQLQuote = None 17 26 18 27 # Setting the appropriate name for the GEOS-C library, depending on which … … 119 128 else: return False 120 129 121 ### Coordinate Sequence properties ###130 ### Coordinate Sequence routines and properties ### 122 131 def coordseq(self): 123 132 "If the coordinate sequence pointer is NULL (0), an exception will be raised."
