mirror of https://github.com/django/django.git
Fixed #25583 -- Allowed calling `transform` with `CoordTransform` even if SRID is invalid.
This commit is contained in:
parent
02ef96c5e5
commit
a7bb5af50b
|
@ -494,14 +494,18 @@ class GEOSGeometry(GEOSBase, ListMixin):
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
if (srid is None) or (srid < 0):
|
if isinstance(ct, gdal.CoordTransform):
|
||||||
|
# We don't care about SRID because CoordTransform presupposes
|
||||||
|
# source SRS.
|
||||||
|
srid = None
|
||||||
|
elif srid is None or srid < 0:
|
||||||
raise GEOSException("Calling transform() with no SRID set is not supported")
|
raise GEOSException("Calling transform() with no SRID set is not supported")
|
||||||
|
|
||||||
if not gdal.HAS_GDAL:
|
if not gdal.HAS_GDAL:
|
||||||
raise GEOSException("GDAL library is not available to transform() geometry.")
|
raise GEOSException("GDAL library is not available to transform() geometry.")
|
||||||
|
|
||||||
# Creating an OGR Geometry, which is then transformed.
|
# Creating an OGR Geometry, which is then transformed.
|
||||||
g = self.ogr
|
g = gdal.OGRGeometry(self.wkb, srid)
|
||||||
g.transform(ct)
|
g.transform(ct)
|
||||||
# Getting a new GEOS pointer
|
# Getting a new GEOS pointer
|
||||||
ptr = wkb_r().read(g.wkb)
|
ptr = wkb_r().read(g.wkb)
|
||||||
|
|
|
@ -553,6 +553,14 @@ is returned instead.
|
||||||
|
|
||||||
Requires GDAL. Raises :class:`~django.contrib.gis.geos.GEOSException` if
|
Requires GDAL. Raises :class:`~django.contrib.gis.geos.GEOSException` if
|
||||||
GDAL is not available or if the geometry's SRID is ``None`` or less than 0.
|
GDAL is not available or if the geometry's SRID is ``None`` or less than 0.
|
||||||
|
It doesn't impose any constraints on the geometry's SRID if called with a
|
||||||
|
:class:`~django.contrib.gis.gdal.CoordTransform` object.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.10
|
||||||
|
|
||||||
|
In previous versions, it required the geometry's SRID to be a positive
|
||||||
|
integer even if it was called with a
|
||||||
|
:class:`~django.contrib.gis.gdal.CoordTransform` object.
|
||||||
|
|
||||||
``Point``
|
``Point``
|
||||||
---------
|
---------
|
||||||
|
|
|
@ -656,9 +656,10 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
|
||||||
|
|
||||||
@skipUnless(HAS_GDAL, "GDAL is required.")
|
@skipUnless(HAS_GDAL, "GDAL is required.")
|
||||||
def test_custom_srid(self):
|
def test_custom_srid(self):
|
||||||
""" Test with a srid unknown from GDAL """
|
"""Test with a null srid and a srid unknown to GDAL."""
|
||||||
pnt = Point(111200, 220900, srid=999999)
|
for srid in [None, 999999]:
|
||||||
self.assertTrue(pnt.ewkt.startswith("SRID=999999;POINT (111200.0"))
|
pnt = Point(111200, 220900, srid=srid)
|
||||||
|
self.assertTrue(pnt.ewkt.startswith(("SRID=%s;" % srid if srid else '') + "POINT (111200.0"))
|
||||||
self.assertIsInstance(pnt.ogr, gdal.OGRGeometry)
|
self.assertIsInstance(pnt.ogr, gdal.OGRGeometry)
|
||||||
self.assertIsNone(pnt.srs)
|
self.assertIsNone(pnt.srs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue