Ticket #12312: 12312.diff
File 12312.diff, 5.6 KB (added by , 15 years ago) |
---|
-
django/contrib/gis/gdal/libgdal.py
65 65 "Returns only the GDAL version number information." 66 66 return _version_info('RELEASE_NAME') 67 67 68 GDAL_VERSION = map(int, gdal_version().split('.')[:2]) 69 68 70 def gdal_full_version(): 69 71 "Returns the full GDAL version information." 70 72 return _version_info('') -
django/contrib/gis/gdal/__init__.py
37 37 try: 38 38 from django.contrib.gis.gdal.driver import Driver 39 39 from django.contrib.gis.gdal.datasource import DataSource 40 from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, gdal_release_date 40 from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, gdal_release_date, GDAL_VERSION 41 41 from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform 42 42 from django.contrib.gis.gdal.geometries import OGRGeometry, GEOJSON 43 43 HAS_GDAL = True -
django/contrib/gis/gdal/prototypes/geom.py
1 1 from datetime import date 2 2 from ctypes import c_char, c_char_p, c_double, c_int, c_ubyte, c_void_p, POINTER 3 3 from django.contrib.gis.gdal.envelope import OGREnvelope 4 from django.contrib.gis.gdal.libgdal import lgdal, gdal_version4 from django.contrib.gis.gdal.libgdal import lgdal, GDAL_VERSION 5 5 from django.contrib.gis.gdal.prototypes.errcheck import check_bool, check_envelope 6 6 from django.contrib.gis.gdal.prototypes.generation import \ 7 7 const_string_output, double_output, geom_output, int_output, \ 8 8 srs_output, string_output, void_output 9 9 10 10 # Some prototypes need to be aware of what version GDAL we have. 11 major, minor = map(int, gdal_version().split('.')[:2]) 12 if major <= 1 and minor <= 4: 11 if GDAL_VERSION < (1, 5): 13 12 GEOJSON = False 14 13 else: 15 14 GEOJSON = True -
django/contrib/gis/gdal/geometries.py
53 53 # Getting the ctypes prototype functions that interface w/the GDAL C library. 54 54 from django.contrib.gis.gdal.prototypes import geom as capi, srs as srs_api 55 55 GEOJSON = capi.GEOJSON 56 GDAL_VERSION = capi.GDAL_VERSION 56 57 57 58 # For recognizing geometry input. 58 59 from django.contrib.gis.geometry.regex import hex_regex, wkt_regex, json_regex … … 400 401 # afterwards. This is done because of GDAL bug (in versions prior 401 402 # to 1.7) that turns geometries 3D after transformation, see: 402 403 # http://trac.osgeo.org/gdal/changeset/17792 403 orig_dim = self.coord_dim 404 if GDAL_VERSION < (1, 7): 405 orig_dim = self.coord_dim 404 406 405 407 # Depending on the input type, use the appropriate OGR routine 406 408 # to perform the transformation. … … 412 414 sr = SpatialReference(coord_trans) 413 415 capi.geom_transform_to(self.ptr, sr.ptr) 414 416 else: 415 raise TypeError('Transform only accepts CoordTransform, SpatialReference, string, and integer objects.') 417 raise TypeError('Transform only accepts CoordTransform, ' 418 'SpatialReference, string, and integer objects.') 416 419 417 420 # Setting with original dimension, see comment above. 418 if self.coord_dim != orig_dim: 419 self.coord_dim = orig_dim 421 if GDAL_VERSION < (1, 7): 422 if isinstance(self, GeometryCollection): 423 # With geometry collections have to set dimension on 424 # each internal geometry reference, as the collection 425 # dimension isn't affected. 426 for i in xrange(len(self)): 427 internal_ptr = capi.get_geom_ref(self.ptr, i) 428 if orig_dim != capi.get_coord_dim(internal_ptr): 429 capi.set_coord_dim(internal_ptr, orig_dim) 430 else: 431 if self.coord_dim != orig_dim: 432 self.coord_dim = orig_dim 420 433 421 434 def transform_to(self, srs): 422 435 "For backwards-compatibility." -
django/contrib/gis/gdal/tests/test_geom.py
455 455 self.assertEqual(g1, g2) 456 456 self.assertEqual(4326, g2.srs.srid) 457 457 self.assertEqual(g1.srs.wkt, g2.srs.wkt) 458 459 458 459 def test08_ogrgeometry_transform_wkt(self): 460 "Testing dimensions on WKT output of geometries transformed with OGRGeometry.transform" 461 wkt_2d = "MULTILINESTRING ((0 0,1 1,2 2))" 462 wkt_3d = "MULTILINESTRING ((0 0 0,1 1 1,2 2 2))" 463 srid = 4326 464 465 geom = OGRGeometry(wkt_2d, srid) 466 geom.transform(srid) 467 self.assertEqual(geom.coord_dim, 2) 468 self.assertEqual(geom.wkt, wkt_2d) 469 470 geom = OGRGeometry(wkt_3d, srid) 471 geom.transform(srid) 472 self.assertEqual(geom.coord_dim, 3) 473 self.assertEqual(geom.wkt, wkt_3d) 474 460 475 def suite(): 461 476 s = unittest.TestSuite() 462 477 s.addTest(unittest.makeSuite(OGRGeomTest))