1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +00:00

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
This commit is contained in:
Justin Bronn 2008-04-07 21:43:36 +00:00
parent b0291347db
commit 55ea575548
3 changed files with 21 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)