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:
parent
b0291347db
commit
55ea575548
@ -325,11 +325,19 @@ class OGRGeometry(object):
|
|||||||
# Closing the open rings.
|
# Closing the open rings.
|
||||||
geom_close_rings(self._ptr)
|
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
|
Transforms this geometry to a different spatial reference system.
|
||||||
either a CoordTransform object or a SpatialReference object.
|
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):
|
if isinstance(coord_trans, CoordTransform):
|
||||||
geom_transform(self._ptr, coord_trans._ptr)
|
geom_transform(self._ptr, coord_trans._ptr)
|
||||||
elif isinstance(coord_trans, SpatialReference):
|
elif isinstance(coord_trans, SpatialReference):
|
||||||
@ -338,7 +346,7 @@ class OGRGeometry(object):
|
|||||||
sr = SpatialReference(coord_trans)
|
sr = SpatialReference(coord_trans)
|
||||||
geom_transform_to(self._ptr, sr._ptr)
|
geom_transform_to(self._ptr, sr._ptr)
|
||||||
else:
|
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):
|
def transform_to(self, srs):
|
||||||
"For backwards-compatibility."
|
"For backwards-compatibility."
|
||||||
|
@ -139,14 +139,6 @@ class SpatialReference(object):
|
|||||||
else:
|
else:
|
||||||
return self.attr_value(target)
|
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):
|
def __str__(self):
|
||||||
"The string representation uses 'pretty' WKT."
|
"The string representation uses 'pretty' WKT."
|
||||||
return self.pretty_wkt
|
return self.pretty_wkt
|
||||||
|
@ -281,8 +281,14 @@ class OGRGeomTest(unittest.TestCase):
|
|||||||
ct = CoordTransform(SpatialReference('WGS84'), SpatialReference(2774))
|
ct = CoordTransform(SpatialReference('WGS84'), SpatialReference(2774))
|
||||||
t3.transform(ct)
|
t3.transform(ct)
|
||||||
|
|
||||||
for p in (t1, t2, t3):
|
# 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
|
prec = 3
|
||||||
|
for p in (t1, t2, t3, k2):
|
||||||
self.assertAlmostEqual(trans.x, p.x, prec)
|
self.assertAlmostEqual(trans.x, p.x, prec)
|
||||||
self.assertAlmostEqual(trans.y, p.y, prec)
|
self.assertAlmostEqual(trans.y, p.y, prec)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user