Ticket #12312: 12312.diff

File 12312.diff, 5.6 KB (added by jbronn, 6 years ago)

Extended GDAL bug workaround to geometry collections.

  • django/contrib/gis/gdal/libgdal.py

     
    6565    "Returns only the GDAL version number information."
    6666    return _version_info('RELEASE_NAME')
    6767
     68GDAL_VERSION = map(int, gdal_version().split('.')[:2])
     69
    6870def gdal_full_version():
    6971    "Returns the full GDAL version information."
    7072    return _version_info('')
  • django/contrib/gis/gdal/__init__.py

     
    3737try:
    3838    from django.contrib.gis.gdal.driver import Driver
    3939    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
    4141    from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
    4242    from django.contrib.gis.gdal.geometries import OGRGeometry, GEOJSON
    4343    HAS_GDAL = True
  • django/contrib/gis/gdal/prototypes/geom.py

     
    11from datetime import date
    22from ctypes import c_char, c_char_p, c_double, c_int, c_ubyte, c_void_p, POINTER
    33from django.contrib.gis.gdal.envelope import OGREnvelope
    4 from django.contrib.gis.gdal.libgdal import lgdal, gdal_version
     4from django.contrib.gis.gdal.libgdal import lgdal, GDAL_VERSION
    55from django.contrib.gis.gdal.prototypes.errcheck import check_bool, check_envelope
    66from django.contrib.gis.gdal.prototypes.generation import \
    77    const_string_output, double_output, geom_output, int_output, \
    88    srs_output, string_output, void_output
    99
    1010# 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:
     11if GDAL_VERSION < (1, 5):
    1312    GEOJSON = False
    1413else:
    1514    GEOJSON = True
  • django/contrib/gis/gdal/geometries.py

     
    5353# Getting the ctypes prototype functions that interface w/the GDAL C library.
    5454from django.contrib.gis.gdal.prototypes import geom as capi, srs as srs_api
    5555GEOJSON = capi.GEOJSON
     56GDAL_VERSION = capi.GDAL_VERSION
    5657
    5758# For recognizing geometry input.
    5859from django.contrib.gis.geometry.regex import hex_regex, wkt_regex, json_regex
     
    400401        # afterwards.  This is done because of GDAL bug (in versions prior
    401402        # to 1.7) that turns geometries 3D after transformation, see:
    402403        #  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
    404406
    405407        # Depending on the input type, use the appropriate OGR routine
    406408        # to perform the transformation.
     
    412414            sr = SpatialReference(coord_trans)
    413415            capi.geom_transform_to(self.ptr, sr.ptr)
    414416        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.')
    416419
    417420        # 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
    420433
    421434    def transform_to(self, srs):
    422435        "For backwards-compatibility."
  • django/contrib/gis/gdal/tests/test_geom.py

     
    455455        self.assertEqual(g1, g2)
    456456        self.assertEqual(4326, g2.srs.srid)
    457457        self.assertEqual(g1.srs.wkt, g2.srs.wkt)
    458        
    459458
     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
    460475def suite():
    461476    s = unittest.TestSuite()
    462477    s.addTest(unittest.makeSuite(OGRGeomTest))
Back to Top