diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py
index df396bd..ceb41aa 100644
a
|
b
|
from django.contrib.gis import memoryview
|
11 | 11 | # super-class for mutable list behavior |
12 | 12 | from django.contrib.gis.geos.mutable_list import ListMixin |
13 | 13 | |
| 14 | from django.contrib.gis.gdal.error import SRSException |
| 15 | |
14 | 16 | # GEOS-related dependencies. |
15 | 17 | from django.contrib.gis.geos.base import GEOSBase, gdal |
16 | 18 | from django.contrib.gis.geos.coordseq import GEOSCoordSeq |
… |
… |
class GEOSGeometry(GEOSBase, ListMixin):
|
460 | 462 | @property |
461 | 463 | def ogr(self): |
462 | 464 | "Returns the OGR Geometry for this Geometry." |
463 | | if gdal.HAS_GDAL: |
464 | | if self.srid: |
465 | | return gdal.OGRGeometry(self.wkb, self.srid) |
466 | | else: |
467 | | return gdal.OGRGeometry(self.wkb) |
468 | | else: |
| 465 | if not gdal.HAS_GDAL: |
469 | 466 | raise GEOSException('GDAL required to convert to an OGRGeometry.') |
| 467 | if self.srid: |
| 468 | try: |
| 469 | return gdal.OGRGeometry(self.wkb, self.srid) |
| 470 | except SRSException: |
| 471 | pass |
| 472 | return gdal.OGRGeometry(self.wkb) |
470 | 473 | |
471 | 474 | @property |
472 | 475 | def srs(self): |
473 | 476 | "Returns the OSR SpatialReference for SRID of this Geometry." |
474 | | if gdal.HAS_GDAL: |
475 | | if self.srid: |
476 | | return gdal.SpatialReference(self.srid) |
477 | | else: |
478 | | return None |
479 | | else: |
| 477 | if not gdal.HAS_GDAL: |
480 | 478 | raise GEOSException('GDAL required to return a SpatialReference object.') |
| 479 | if self.srid: |
| 480 | try: |
| 481 | return gdal.SpatialReference(self.srid) |
| 482 | except SRSException: |
| 483 | pass |
| 484 | return None |
481 | 485 | |
482 | 486 | @property |
483 | 487 | def crs(self): |
diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py
index 283daa4..ad1404f 100644
a
|
b
|
class GEOSTest(unittest.TestCase, TestDataMixin):
|
646 | 646 | p3 = fromstr(p1.hex, srid=-1) # -1 is intended. |
647 | 647 | self.assertEqual(-1, p3.srid) |
648 | 648 | |
| 649 | def test_custom_srid(self): |
| 650 | """ Test with a srid unknown from GDAL """ |
| 651 | pnt = Point(111200, 220900, srid=999999) |
| 652 | self.assertTrue(pnt.ewkt.startswith("SRID=999999;POINT (111200.0")) |
| 653 | self.assertIsInstance(pnt.ogr, gdal.OGRGeometry) |
| 654 | self.assertIsNone(pnt.srs) |
| 655 | |
| 656 | # Test conversion from custom to a known srid |
| 657 | c2w = gdal.CoordTransform( |
| 658 | gdal.SpatialReference('+proj=mill +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +R_A +ellps=WGS84 +datum=WGS84 +units=m +no_defs'), |
| 659 | gdal.SpatialReference(4326)) |
| 660 | new_pnt = pnt.transform(c2w, clone=True) |
| 661 | self.assertEqual(new_pnt.srid, 4326) |
| 662 | self.assertAlmostEqual(new_pnt.x, 1, 3) |
| 663 | self.assertAlmostEqual(new_pnt.y, 2, 3) |
| 664 | |
649 | 665 | def test_mutable_geometries(self): |
650 | 666 | "Testing the mutability of Polygons and Geometry Collections." |
651 | 667 | ### Testing the mutability of Polygons ### |