1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Removed many HAS_GEOS conditional imports

This commit is contained in:
Claude Paroz
2015-04-24 17:24:07 +02:00
parent 61d09e61f5
commit d9bcba9b29
20 changed files with 78 additions and 145 deletions

View File

@@ -1,15 +1,5 @@
from django.core.exceptions import ImproperlyConfigured
# Want to get everything from the 'normal' models package.
from django.db.models import * # NOQA
from django.utils.version import get_docs_version
from django.contrib.gis.geos import HAS_GEOS
if not HAS_GEOS:
raise ImproperlyConfigured(
"GEOS is required and has not been detected. Are you sure it is installed? "
"See also https://docs.djangoproject.com/en/%s/ref/contrib/gis/install/geolibs/" % get_docs_version())
# Geographic aggregate functions
from django.contrib.gis.db.models.aggregates import * # NOQA

View File

@@ -3,29 +3,18 @@ The GeoDjango GEOS module. Please consult the GeoDjango documentation
for more details:
http://geodjango.org/docs/geos.html
"""
__all__ = ['HAS_GEOS']
from .collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon # NOQA
from .error import GEOSException, GEOSIndexError # NOQA
from .factory import fromfile, fromstr # NOQA
from .geometry import GEOSGeometry, wkt_regex, hex_regex # NOQA
from .io import WKTReader, WKTWriter, WKBReader, WKBWriter # NOQA
from .libgeos import geos_version, geos_version_info # NOQA
from .linestring import LineString, LinearRing # NOQA
from .point import Point # NOQA
from .polygon import Polygon # NOQA
try:
from .libgeos import geos_version, geos_version_info # NOQA: flake8 detects only the last __all__
geos_version_info()
HAS_GEOS = True
__all__ += ['geos_version', 'geos_version_info']
except ImportError:
HAS_GEOS = False
if HAS_GEOS:
from .geometry import GEOSGeometry, wkt_regex, hex_regex
from .point import Point
from .linestring import LineString, LinearRing
from .polygon import Polygon
from .collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon
from .error import GEOSException, GEOSIndexError
from .io import WKTReader, WKTWriter, WKBReader, WKBWriter
from .factory import fromfile, fromstr
__all__ += [
'GEOSGeometry', 'wkt_regex', 'hex_regex', 'Point', 'LineString',
'LinearRing', 'Polygon', 'GeometryCollection', 'MultiPoint',
'MultiLineString', 'MultiPolygon', 'GEOSException', 'GEOSIndexError',
'WKTReader', 'WKTWriter', 'WKBReader', 'WKBWriter', 'fromfile',
'fromstr',
]

View File

@@ -2,16 +2,6 @@ from ctypes import c_void_p
from django.contrib.gis.geos.error import GEOSException
# Trying to import GDAL libraries, if available. Have to place in
# try/except since this package may be used outside GeoDjango.
try:
from django.contrib.gis import gdal
except ImportError:
# A 'dummy' gdal module.
class GDALInfo(object):
HAS_GDAL = False
gdal = GDALInfo()
class GEOSBase(object):
"""

View File

@@ -6,10 +6,10 @@ from __future__ import unicode_literals
from ctypes import addressof, byref, c_double
from django.contrib.gis.gdal.error import SRSException
from django.contrib.gis import gdal
from django.contrib.gis.geometry.regex import hex_regex, json_regex, wkt_regex
from django.contrib.gis.geos import prototypes as capi
from django.contrib.gis.geos.base import GEOSBase, gdal
from django.contrib.gis.geos.base import GEOSBase
from django.contrib.gis.geos.coordseq import GEOSCoordSeq
from django.contrib.gis.geos.error import GEOSException, GEOSIndexError
from django.contrib.gis.geos.libgeos import GEOM_PTR
@@ -449,7 +449,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
if self.srid:
try:
return gdal.OGRGeometry(self.wkb, self.srid)
except SRSException:
except gdal.SRSException:
pass
return gdal.OGRGeometry(self.wkb)
@@ -461,7 +461,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
if self.srid:
try:
return gdal.SpatialReference(self.srid)
except SRSException:
except gdal.SRSException:
pass
return None