Removed many HAS_GEOS conditional imports
This commit is contained in:
parent
61d09e61f5
commit
d9bcba9b29
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
]
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||
from django.contrib.gis.db.models.functions import (
|
||||
Area, Distance, Length, Perimeter, Transform,
|
||||
)
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.geos import GEOSGeometry, LineString, Point
|
||||
from django.contrib.gis.measure import D # alias for Distance
|
||||
from django.db import connection
|
||||
from django.db.models import Q
|
||||
|
@ -11,12 +11,10 @@ from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
|
|||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
|
||||
from ..utils import no_oracle, oracle, postgis, spatialite
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.geos import GEOSGeometry, LineString, Point
|
||||
|
||||
from .models import (AustraliaCity, Interstate, SouthTexasInterstate,
|
||||
SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode)
|
||||
from .models import (
|
||||
AustraliaCity, CensusZipcode, Interstate, SouthTexasCity, SouthTexasCityFt,
|
||||
SouthTexasInterstate, SouthTexasZipcode,
|
||||
)
|
||||
|
||||
|
||||
@skipUnlessDBFeature("gis_enabled")
|
||||
|
|
|
@ -4,26 +4,25 @@ import os
|
|||
import re
|
||||
from unittest import skipUnless
|
||||
|
||||
from django.contrib.gis.db.models import Extent3D, Union
|
||||
from django.contrib.gis.db.models.functions import (
|
||||
AsGeoJSON, AsKML, Length, Perimeter, Scale, Translate,
|
||||
)
|
||||
from django.contrib.gis.gdal import HAS_GDAL
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon
|
||||
from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
|
||||
from django.utils._os import upath
|
||||
from django.utils.deprecation import (
|
||||
RemovedInDjango20Warning, RemovedInDjango21Warning,
|
||||
)
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.db.models import Union, Extent3D
|
||||
from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon
|
||||
from .models import (
|
||||
City3D, Interstate2D, Interstate3D, InterstateProj2D, InterstateProj3D,
|
||||
MultiPoint3D, Point2D, Point3D, Polygon2D, Polygon3D,
|
||||
)
|
||||
|
||||
from .models import (City3D, Interstate2D, Interstate3D, InterstateProj2D,
|
||||
InterstateProj3D, Point2D, Point3D, MultiPoint3D, Polygon2D, Polygon3D)
|
||||
|
||||
if HAS_GDAL:
|
||||
from django.contrib.gis.utils import LayerMapping, LayerMapError
|
||||
if HAS_GDAL:
|
||||
from django.contrib.gis.utils import LayerMapping, LayerMapError
|
||||
|
||||
|
||||
data_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), '..', 'data'))
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis import admin
|
||||
from django.contrib.gis.geos import Point
|
||||
from django.test import TestCase, override_settings, skipUnlessDBFeature
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis import admin
|
||||
from django.contrib.gis.geos import Point
|
||||
|
||||
from .admin import UnmodifiableAdmin
|
||||
from .models import site, City
|
||||
from .admin import UnmodifiableAdmin
|
||||
from .models import City, site
|
||||
|
||||
|
||||
@skipUnlessDBFeature("gis_enabled")
|
||||
|
|
|
@ -3,14 +3,12 @@ from __future__ import unicode_literals
|
|||
from xml.dom import minidom
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.sites.models import Site
|
||||
from django.test import (
|
||||
TestCase, modify_settings, override_settings, skipUnlessDBFeature,
|
||||
)
|
||||
|
||||
if HAS_GEOS:
|
||||
from .models import City
|
||||
from .models import City
|
||||
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.sites'})
|
||||
|
|
|
@ -2,21 +2,17 @@ from __future__ import unicode_literals
|
|||
|
||||
import re
|
||||
from decimal import Decimal
|
||||
from unittest import skipUnless
|
||||
|
||||
from django.contrib.gis.db.models import functions
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.geos import (
|
||||
LineString, Point, Polygon, fromstr, geos_version_info,
|
||||
)
|
||||
from django.db import connection
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
from django.utils import six
|
||||
|
||||
from ..utils import mysql, oracle, postgis, spatialite
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.geos import (
|
||||
LineString, Point, Polygon, fromstr, geos_version_info,
|
||||
)
|
||||
from .models import Country, City, State, Track
|
||||
from .models import City, Country, State, Track
|
||||
|
||||
|
||||
@skipUnlessDBFeature("gis_enabled")
|
||||
|
@ -385,8 +381,9 @@ class GISFunctionsTests(TestCase):
|
|||
)
|
||||
|
||||
@skipUnlessDBFeature("has_SymDifference_function")
|
||||
@skipUnless(HAS_GEOS and geos_version_info()['version'] >= '3.3.0', "GEOS >= 3.3 required")
|
||||
def test_sym_difference(self):
|
||||
if geos_version_info()['version'] < '3.3.0':
|
||||
self.skipTest("GEOS >= 3.3 required")
|
||||
geom = Point(5, 23, srid=4326)
|
||||
qs = Country.objects.annotate(sym_difference=functions.SymDifference('mpoly', geom))
|
||||
for country in qs:
|
||||
|
|
|
@ -3,16 +3,13 @@ from __future__ import unicode_literals
|
|||
|
||||
from datetime import datetime
|
||||
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.db.models import Extent
|
||||
from django.contrib.gis.shortcuts import render_to_kmz
|
||||
from django.db.models import Count, Min
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
|
||||
from ..utils import no_oracle
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.db.models import Extent
|
||||
from .models import City, PennsylvaniaCity, State, Truth
|
||||
from .models import City, PennsylvaniaCity, State, Truth
|
||||
|
||||
|
||||
@skipUnlessDBFeature("gis_enabled")
|
||||
|
|
|
@ -2,13 +2,11 @@ from __future__ import unicode_literals
|
|||
|
||||
import json
|
||||
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.geos import LinearRing, Point, Polygon
|
||||
from django.core import serializers
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.geos import LinearRing, Point, Polygon
|
||||
from .models import City, MultiFields, PennsylvaniaCity
|
||||
from .models import City, MultiFields, PennsylvaniaCity
|
||||
|
||||
|
||||
@skipUnlessDBFeature("gis_enabled")
|
||||
|
|
|
@ -5,7 +5,6 @@ from io import BytesIO
|
|||
from xml.dom import minidom
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.sites.models import Site
|
||||
from django.test import (
|
||||
TestCase, ignore_warnings, modify_settings, override_settings,
|
||||
|
@ -13,8 +12,7 @@ from django.test import (
|
|||
)
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
if HAS_GEOS:
|
||||
from .models import City, Country
|
||||
from .models import City, Country
|
||||
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.sites', 'django.contrib.sitemaps']})
|
||||
|
|
|
@ -4,7 +4,11 @@ import re
|
|||
import tempfile
|
||||
|
||||
from django.contrib.gis import gdal
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.db.models import Extent, MakeLine, Union
|
||||
from django.contrib.gis.geos import (
|
||||
GeometryCollection, GEOSGeometry, LinearRing, LineString, Point, Polygon,
|
||||
fromstr,
|
||||
)
|
||||
from django.core.management import call_command
|
||||
from django.db import connection
|
||||
from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
|
||||
|
@ -14,12 +18,10 @@ from django.utils.deprecation import (
|
|||
)
|
||||
|
||||
from ..utils import no_oracle, oracle, postgis, spatialite
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.db.models import Extent, MakeLine, Union
|
||||
from django.contrib.gis.geos import (fromstr, GEOSGeometry,
|
||||
Point, LineString, LinearRing, Polygon, GeometryCollection)
|
||||
from .models import Country, City, PennsylvaniaCity, State, Track, NonConcreteModel, Feature, MinusOneSRID
|
||||
from .models import (
|
||||
City, Country, Feature, MinusOneSRID, NonConcreteModel, PennsylvaniaCity,
|
||||
State, Track,
|
||||
)
|
||||
|
||||
|
||||
def postgis_bug_version():
|
||||
|
|
|
@ -8,16 +8,13 @@ from unittest import skipUnless
|
|||
|
||||
from django.contrib.gis.db.models.functions import Area, Distance
|
||||
from django.contrib.gis.gdal import HAS_GDAL
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.measure import D
|
||||
from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
|
||||
from django.utils._os import upath
|
||||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
|
||||
from ..utils import oracle, postgis
|
||||
|
||||
if HAS_GEOS:
|
||||
from .models import City, County, Zipcode
|
||||
from .models import City, County, Zipcode
|
||||
|
||||
|
||||
@skipUnlessDBFeature("gis_enabled")
|
||||
|
|
|
@ -8,8 +8,14 @@ from binascii import a2b_hex, b2a_hex
|
|||
from io import BytesIO
|
||||
from unittest import skipUnless
|
||||
|
||||
from django.contrib.gis import gdal
|
||||
from django.contrib.gis.gdal import HAS_GDAL
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.geos import (
|
||||
HAS_GEOS, GeometryCollection, GEOSException, GEOSGeometry, GEOSIndexError,
|
||||
LinearRing, LineString, MultiLineString, MultiPoint, MultiPolygon, Point,
|
||||
Polygon, fromfile, fromstr, geos_version_info,
|
||||
)
|
||||
from django.contrib.gis.geos.base import GEOSBase
|
||||
from django.contrib.gis.shortcuts import numpy
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_bytes
|
||||
|
@ -17,14 +23,6 @@ from django.utils.six.moves import range
|
|||
|
||||
from ..test_data import TestDataMixin
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.geos import (
|
||||
GEOSException, GEOSIndexError, GEOSGeometry, GeometryCollection, Point,
|
||||
MultiPoint, Polygon, MultiPolygon, LinearRing, LineString,
|
||||
MultiLineString, fromfile, fromstr, geos_version_info,
|
||||
)
|
||||
from django.contrib.gis.geos.base import gdal, GEOSBase
|
||||
|
||||
|
||||
@skipUnless(HAS_GEOS, "Geos is required.")
|
||||
class GEOSTest(unittest.TestCase, TestDataMixin):
|
||||
|
|
|
@ -5,18 +5,14 @@
|
|||
import unittest
|
||||
from unittest import skipUnless
|
||||
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.geos import (
|
||||
fromstr, LinearRing, LineString, MultiPoint, Point, Polygon,
|
||||
)
|
||||
from django.contrib.gis.geos.error import GEOSIndexError
|
||||
from django.contrib.gis.geos import (
|
||||
HAS_GEOS, LinearRing, LineString, MultiPoint, Point, Polygon, fromstr,
|
||||
)
|
||||
from django.contrib.gis.geos.error import GEOSIndexError
|
||||
|
||||
|
||||
if HAS_GEOS:
|
||||
def api_get_distance(x):
|
||||
return x.distance(Point(-200, -200))
|
||||
def api_get_distance(x):
|
||||
return x.distance(Point(-200, -200))
|
||||
|
||||
|
||||
def api_get_buffer(x):
|
||||
|
|
|
@ -4,14 +4,11 @@ import binascii
|
|||
import unittest
|
||||
from unittest import skipUnless
|
||||
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.geos import (
|
||||
HAS_GEOS, GEOSGeometry, WKBReader, WKBWriter, WKTReader, WKTWriter,
|
||||
)
|
||||
from django.utils.six import memoryview
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.geos import (
|
||||
GEOSGeometry, WKTReader, WKTWriter, WKBReader, WKBWriter,
|
||||
)
|
||||
|
||||
|
||||
@skipUnless(HAS_GEOS, "Geos is required.")
|
||||
class GEOSIOTest(unittest.TestCase):
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.db.models import F, Collect, Count, Extent, Union
|
||||
from django.contrib.gis.geometry.backend import Geometry
|
||||
from django.contrib.gis.geos import GEOSGeometry, MultiPoint, Point
|
||||
from django.db import connection
|
||||
from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
|
||||
from django.test.utils import override_settings
|
||||
|
@ -8,13 +10,9 @@ from django.utils import timezone
|
|||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
from ..utils import no_oracle
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.db.models import Collect, Count, Extent, F, Union
|
||||
from django.contrib.gis.geometry.backend import Geometry
|
||||
from django.contrib.gis.geos import GEOSGeometry, Point, MultiPoint
|
||||
|
||||
from .models import City, Location, DirectoryEntry, Parcel, Book, Author, Article, Event
|
||||
from .models import (
|
||||
Article, Author, Book, City, DirectoryEntry, Event, Location, Parcel,
|
||||
)
|
||||
|
||||
|
||||
@skipUnlessDBFeature("gis_enabled")
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
from unittest import skipUnless
|
||||
|
||||
from django.contrib.gis import forms
|
||||
from django.contrib.gis.gdal import HAS_GDAL
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.geos import GEOSGeometry
|
||||
from django.forms import ValidationError
|
||||
from django.test import SimpleTestCase, skipUnlessDBFeature
|
||||
from django.utils import six
|
||||
from django.utils.html import escape
|
||||
|
||||
if HAS_GEOS and HAS_GDAL:
|
||||
from django.contrib.gis import forms
|
||||
from django.contrib.gis.geos import GEOSGeometry
|
||||
|
||||
|
||||
@skipUnless(HAS_GDAL, "GeometryFieldTest needs GDAL support")
|
||||
@skipUnlessDBFeature("gis_enabled")
|
||||
|
|
|
@ -7,15 +7,12 @@ from unittest import skipUnless
|
|||
|
||||
from django.conf import settings
|
||||
from django.contrib.gis.geoip import HAS_GEOIP
|
||||
from django.contrib.gis.geos import HAS_GEOS
|
||||
from django.contrib.gis.geos import HAS_GEOS, GEOSGeometry
|
||||
from django.utils import six
|
||||
|
||||
if HAS_GEOIP:
|
||||
from django.contrib.gis.geoip import GeoIP, GeoIPException
|
||||
|
||||
if HAS_GEOS:
|
||||
from django.contrib.gis.geos import GEOSGeometry
|
||||
|
||||
|
||||
# Note: Requires use of both the GeoIP country and city datasets.
|
||||
# The GEOIP_DATA path should be the only setting set (the directory
|
||||
|
|
Loading…
Reference in New Issue