Changeset 6596
- Timestamp:
- 10/22/07 18:37:26 (11 months ago)
- Files:
-
- django/branches/gis/django/contrib/gis/db/backend/oracle/field.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/db/backend/postgis/field.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/db/backend/util.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/geos/base.py (modified) (4 diffs)
- django/branches/gis/django/contrib/gis/tests/geoapp/tests.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/tests/test_gdal.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/tests/test_geos.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/db/backend/oracle/field.py
r6524 r6596 5 5 from django.db.models.fields import Field # Django base Field class 6 6 from django.contrib.gis.geos import GEOSGeometry 7 from django.contrib.gis.db.backend.util import GeoFieldSQL7 from django.contrib.gis.db.backend.util import get_srid, GeoFieldSQL 8 8 from django.contrib.gis.db.backend.oracle.adaptor import OracleSpatialAdaptor 9 9 from django.contrib.gis.db.backend.oracle.query import ORACLE_SPATIAL_TERMS, TRANSFORM … … 119 119 # Getting the SRID of the geometry, or defaulting to that of the field if 120 120 # it is None. 121 if value.srid is None: srid = self._srid 122 else: srid = value.srid 121 srid = get_srid(self, value) 123 122 124 123 # The adaptor will be used by psycopg2 for quoting the WKT. django/branches/gis/django/contrib/gis/db/backend/postgis/field.py
r6524 r6596 3 3 from django.db.models.fields import Field # Django base Field class 4 4 from django.contrib.gis.geos import GEOSGeometry, GEOSException 5 from django.contrib.gis.db.backend.util import GeoFieldSQL5 from django.contrib.gis.db.backend.util import get_srid, GeoFieldSQL 6 6 from django.contrib.gis.db.backend.postgis.adaptor import PostGISAdaptor 7 7 from django.contrib.gis.db.backend.postgis.query import POSTGIS_TERMS, TRANSFORM … … 110 110 # Getting the SRID of the geometry, or defaulting to that of the field if 111 111 # it is None. 112 if value.srid is None: srid = self._srid 113 else: srid = value.srid 112 srid = get_srid(self, value) 114 113 115 114 # The adaptor will be used by psycopg2 for quoting the WKB. django/branches/gis/django/contrib/gis/db/backend/util.py
r6508 r6596 7 7 self.where = where 8 8 self.params = params 9 10 def get_srid(field, geom): 11 """ 12 Gets the SRID depending on the value of the SRID setting of the field 13 and that of the given geometry. 14 """ 15 if geom.srid is None or (geom.srid == -1 and field._srid != -1): 16 return field._srid 17 else: 18 return geom.srid django/branches/gis/django/contrib/gis/geos/base.py
r6508 r6596 49 49 (SRID) number for this Geometry. If not set, the SRID will be None. 50 50 """ 51 from_hex = False52 51 if isinstance(geo_input, UnicodeType): 53 52 # Encoding to ASCII, WKT or HEXEWKB doesn't need any more. … … 56 55 if hex_regex.match(geo_input): 57 56 # If the regex matches, the geometry is in HEX form. 58 from_hex = True59 57 sz = c_size_t(len(geo_input)) 60 58 buf = create_string_buffer(geo_input) … … 87 85 if srid and isinstance(srid, int): self.srid = srid 88 86 89 # Exported HEX from other GEOS geometries will have -1 SRID --90 # set here to 0, when the SRID is not explicitly given.91 if not srid and from_hex: self.srid = 092 93 87 # Setting the class type (e.g., 'Point', 'Polygon', etc.) 94 88 self.__class__ = GEOS_CLASSES[self.geom_type] … … 423 417 -1 by default, even if the SRID is set. 424 418 """ 419 # A possible faster, all-python, implementation: 420 # str(self.wkb).encode('hex') 425 421 sz = c_size_t() 426 422 h = lgeos.GEOSGeomToHEX_buf(self._ptr(), byref(sz)) django/branches/gis/django/contrib/gis/tests/geoapp/tests.py
r6524 r6596 139 139 if not oracle: 140 140 h = City.objects.transform('point', srid=htown.srid).get(name='Houston') 141 self.assertEqual(3084, h.point.srid) 141 142 self.assertAlmostEqual(htown.x, h.point.x, 8) 142 143 self.assertAlmostEqual(htown.y, h.point.y, 8) 143 144 144 145 p = City.objects.transform('point', srid=ptown.srid).get(name='Pueblo') 146 self.assertEqual(2774, p.point.srid) 145 147 self.assertAlmostEqual(ptown.x, p.point.x, 7) 146 148 self.assertAlmostEqual(ptown.y, p.point.y, 7) django/branches/gis/django/contrib/gis/tests/test_gdal.py
r6436 r6596 1 """ 2 Module for executing all of the GDAL tests. None 3 of these tests require the use of the database. 4 """ 1 5 from unittest import TestSuite, TextTestRunner 2 6 … … 21 25 22 26 def run(verbosity=1): 23 "Runs the tests that do not require geographic (GEOS, GDAL, etc.) models."27 "Runs the GDAL tests." 24 28 TextTestRunner(verbosity=verbosity).run(suite()) django/branches/gis/django/contrib/gis/tests/test_geos.py
r6465 r6596 608 608 for i in range(len(gc)): self.assertEqual(32021, gc[i].srid) 609 609 610 # GEOS may get the SRID from HEXEWKB 611 # 'POINT(5 23)' at SRID=4326 in hex form -- obtained from PostGIS 612 # using `SELECT GeomFromText('POINT (5 23)', 4326);`. 613 hex = '0101000020E610000000000000000014400000000000003740' 614 p1 = fromstr(hex) 615 self.assertEqual(4326, p1.srid) 616 617 # However, when HEX is exported, the SRID information is lost 618 # and set to -1. Essentially, the 'E' of the EWKB is not 619 # encoded in HEX by the GEOS C library for some reason. 620 p2 = fromstr(p1.hex) 621 self.assertEqual(-1, p2.srid) 622 p3 = fromstr(p1.hex, srid=-1) # -1 is intended. 623 self.assertEqual(-1, p3.srid) 624 610 625 def test16_mutable_geometries(self): 611 626 "Testing the mutability of Polygons and Geometry Collections."
