Commit 9c1f501d authored by Claude Paroz's avatar Claude Paroz
Browse files

Fixed #24014 -- Unified OGRException and GDALException

Thanks Tim Graham for the review.
parent 4fb38b73
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ from django.template import loader, Context
from django.utils import six
from django.utils import translation

from django.contrib.gis.gdal import OGRException
from django.contrib.gis.gdal import GDALException
from django.contrib.gis.geos import GEOSGeometry, GEOSException

# Creating a template context that contains Django settings
@@ -68,7 +68,7 @@ class OpenLayersWidget(Textarea):
                    ogr = value.ogr
                    ogr.transform(srid)
                    wkt = ogr.wkt
                except OGRException as err:
                except GDALException as err:
                    logger.error(
                        "Error transforming geometry from srid '%s' to srid '%s' (%s)" % (
                            value.srid, srid, err)
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ class BaseGeometryWidget(Widget):
                    ogr = value.ogr
                    ogr.transform(self.map_srid)
                    value = ogr
                except gdal.OGRException as err:
                except gdal.GDALException as err:
                    logger.error(
                        "Error transforming geometry from srid '%s' to srid '%s' (%s)" % (
                            value.srid, self.map_srid, err)
+5 −4
Original line number Diff line number Diff line
@@ -31,12 +31,13 @@
 to a non-existent file location (e.g., `GDAL_LIBRARY_PATH='/null/path'`;
 setting to None/False/'' will not work as a string must be given).
"""
from django.contrib.gis.gdal.error import check_err, OGRException, OGRIndexError, SRSException  # NOQA
from django.contrib.gis.gdal.error import (check_err, GDALException,
    OGRException, OGRIndexError, SRSException)  # NOQA
from django.contrib.gis.gdal.geomtype import OGRGeomType  # NOQA

__all__ = [
    'check_err', 'OGRException', 'OGRIndexError', 'SRSException', 'OGRGeomType',
    'HAS_GDAL',
    'check_err', 'GDALException', 'OGRException', 'OGRIndexError',
    'SRSException', 'OGRGeomType', 'HAS_GDAL',
]

# Attempting to import objects that depend on the GDAL library.  The
@@ -53,7 +54,7 @@ try:
        'Driver', 'DataSource', 'gdal_version', 'gdal_full_version',
        'GDAL_VERSION', 'SpatialReference', 'CoordTransform', 'OGRGeometry',
    ]
except OGRException:
except GDALException:
    HAS_GDAL = False

try:
+5 −5
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ from ctypes import byref
# The GDAL C library, OGR exceptions, and the Layer object.
from django.contrib.gis.gdal.base import GDALBase
from django.contrib.gis.gdal.driver import Driver
from django.contrib.gis.gdal.error import OGRException, OGRIndexError
from django.contrib.gis.gdal.error import GDALException, OGRIndexError
from django.contrib.gis.gdal.layer import Layer

# Getting the ctypes prototypes for the DataSource.
@@ -75,21 +75,21 @@ class DataSource(GDALBase):
            try:
                # OGROpen will auto-detect the data source type.
                ds = capi.open_ds(force_bytes(ds_input), self._write, byref(ds_driver))
            except OGRException:
            except GDALException:
                # Making the error message more clear rather than something
                # like "Invalid pointer returned from OGROpen".
                raise OGRException('Could not open the datasource at "%s"' % ds_input)
                raise GDALException('Could not open the datasource at "%s"' % ds_input)
        elif isinstance(ds_input, self.ptr_type) and isinstance(ds_driver, Driver.ptr_type):
            ds = ds_input
        else:
            raise OGRException('Invalid data source input type: %s' % type(ds_input))
            raise GDALException('Invalid data source input type: %s' % type(ds_input))

        if ds:
            self.ptr = ds
            self.driver = Driver(ds_driver)
        else:
            # Raise an exception if the returned pointer is NULL
            raise OGRException('Invalid data source file "%s"' % ds_input)
            raise GDALException('Invalid data source file "%s"' % ds_input)

    def __del__(self):
        "Destroys this DataStructure object."
+3 −3
Original line number Diff line number Diff line
from ctypes import c_void_p
from django.contrib.gis.gdal.base import GDALBase
from django.contrib.gis.gdal.error import OGRException
from django.contrib.gis.gdal.error import GDALException
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi

from django.utils import six
@@ -61,11 +61,11 @@ class Driver(GDALBase):
        elif isinstance(dr_input, c_void_p):
            driver = dr_input
        else:
            raise OGRException('Unrecognized input type for GDAL/OGR Driver: %s' % str(type(dr_input)))
            raise GDALException('Unrecognized input type for GDAL/OGR Driver: %s' % str(type(dr_input)))

        # Making sure we get a valid pointer to the OGR Driver
        if not driver:
            raise OGRException('Could not initialize GDAL/OGR Driver on input: %s' % str(dr_input))
            raise GDALException('Could not initialize GDAL/OGR Driver on input: %s' % str(dr_input))
        self.ptr = driver

    def __str__(self):
Loading