diff options
| author | Justin Bronn <jbronn@gmail.com> | 2008-04-07 21:43:36 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2008-04-07 21:43:36 +0000 |
| commit | 55ea575548ffc382fb4885da5a6a6fa331945259 (patch) | |
| tree | 98119b638a270b17dc93f994f464825d528c37e8 | |
| parent | b0291347db0397ae429564b9e89ded2f0fcc5b36 (diff) | |
gis: gdal: Added the `clone` keyword to `OGRGeometry.transform`; removed unnecessary `__nonzero__` function from `SpatialReference`.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7406 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/contrib/gis/gdal/geometries.py | 18 | ||||
| -rw-r--r-- | django/contrib/gis/gdal/srs.py | 8 | ||||
| -rw-r--r-- | django/contrib/gis/tests/test_gdal_geom.py | 10 |
3 files changed, 21 insertions, 15 deletions
diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index a39838c6ce..39cc4f8023 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -325,11 +325,19 @@ class OGRGeometry(object): # Closing the open rings. geom_close_rings(self._ptr) - def transform(self, coord_trans): + def transform(self, coord_trans, clone=False): """ - Transforms this geometry to a different spatial reference system. May take - either a CoordTransform object or a SpatialReference object. + Transforms this geometry to a different spatial reference system. + May take a CoordTransform object, a SpatialReference object, string + WKT or PROJ.4, and/or an integer SRID. By default nothing is returned + and the geometry is transformed in-place. However, if the `clone` + keyword is set, then a transformed clone of this geometry will be + returned. """ + if clone: + klone = self.clone() + klone.transform(coord_trans) + return klone if isinstance(coord_trans, CoordTransform): geom_transform(self._ptr, coord_trans._ptr) elif isinstance(coord_trans, SpatialReference): @@ -338,7 +346,7 @@ class OGRGeometry(object): sr = SpatialReference(coord_trans) geom_transform_to(self._ptr, sr._ptr) else: - raise TypeError('Either a CoordTransform or a SpatialReference object required for transformation.') + raise TypeError('Transform only accepts CoordTransform, SpatialReference, string, and integer objects.') def transform_to(self, srs): "For backwards-compatibility." @@ -431,7 +439,7 @@ class OGRGeometry(object): def union(self, other): """ - Returns a new geometry consisting of the region which is the union of + Returns a new geometry consisting of the region which is the union of this geometry and the other. """ return self._geomgen(geom_union, other) diff --git a/django/contrib/gis/gdal/srs.py b/django/contrib/gis/gdal/srs.py index d90636fc0d..d70e71ebc7 100644 --- a/django/contrib/gis/gdal/srs.py +++ b/django/contrib/gis/gdal/srs.py @@ -139,14 +139,6 @@ class SpatialReference(object): else: return self.attr_value(target) - def __nonzero__(self): - "Returns True if this SpatialReference object is valid." - try: - self.validate() - return True - except OGRException: - return False - def __str__(self): "The string representation uses 'pretty' WKT." return self.pretty_wkt diff --git a/django/contrib/gis/tests/test_gdal_geom.py b/django/contrib/gis/tests/test_gdal_geom.py index 093ed31093..aa4e325116 100644 --- a/django/contrib/gis/tests/test_gdal_geom.py +++ b/django/contrib/gis/tests/test_gdal_geom.py @@ -281,8 +281,14 @@ class OGRGeomTest(unittest.TestCase): ct = CoordTransform(SpatialReference('WGS84'), SpatialReference(2774)) t3.transform(ct) - for p in (t1, t2, t3): - prec = 3 + # Testing use of the `clone` keyword. + k1 = orig.clone() + k2 = k1.transform(trans.srid, clone=True) + self.assertEqual(k1, orig) + self.assertNotEqual(k1, k2) + + prec = 3 + for p in (t1, t2, t3, k2): self.assertAlmostEqual(trans.x, p.x, prec) self.assertAlmostEqual(trans.y, p.y, prec) |
