Loading django/contrib/gis/geos/__init__.py +2 −2 Original line number Diff line number Diff line Loading @@ -6,9 +6,9 @@ for more details: __all__ = ['HAS_GEOS'] try: from .libgeos import geos_version, geos_version_info, GEOS_PREPARE # NOQA: flake8 detects only the last __all__ from .libgeos import geos_version, geos_version_info # NOQA: flake8 detects only the last __all__ HAS_GEOS = True __all__ += ['geos_version', 'geos_version_info', 'GEOS_PREPARE'] __all__ += ['geos_version', 'geos_version_info'] except ImportError: HAS_GEOS = False Loading django/contrib/gis/geos/collections.py +2 −6 Original line number Diff line number Diff line Loading @@ -3,9 +3,8 @@ GeometryCollection, MultiPoint, MultiLineString, and MultiPolygon """ from ctypes import c_int, c_uint, byref from django.contrib.gis.geos.error import GEOSException from django.contrib.gis.geos.geometry import GEOSGeometry from django.contrib.gis.geos.libgeos import get_pointer_arr, GEOS_PREPARE from django.contrib.gis.geos.libgeos import get_pointer_arr from django.contrib.gis.geos.linestring import LineString, LinearRing from django.contrib.gis.geos.point import Point from django.contrib.gis.geos.polygon import Polygon Loading Loading @@ -119,10 +118,7 @@ class MultiPolygon(GeometryCollection): @property def cascaded_union(self): "Returns a cascaded union of this MultiPolygon." if GEOS_PREPARE: return GEOSGeometry(capi.geos_cascaded_union(self.ptr), self.srid) else: raise GEOSException('The cascaded union operation requires GEOS 3.1+.') # Setting the allowed types here since GeometryCollection is defined before # its subclasses. Loading django/contrib/gis/geos/geometry.py +13 −26 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ from django.contrib.gis.gdal.error import SRSException from django.contrib.gis.geos.base import GEOSBase, gdal 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, GEOS_PREPARE from django.contrib.gis.geos.libgeos import GEOM_PTR # All other functions in this module come from the ctypes # prototypes module -- which handles all interaction with Loading Loading @@ -289,8 +289,6 @@ class GEOSGeometry(GEOSBase, ListMixin): """ Returns a string containing the reason for any invalidity. """ if not GEOS_PREPARE: raise GEOSException('Upgrade GEOS to 3.1 to get validity reason.') return capi.geos_isvalidreason(self.ptr).decode() #### Binary predicates. #### Loading Loading @@ -411,9 +409,6 @@ class GEOSGeometry(GEOSBase, ListMixin): extension of the WKB specification that includes SRID value that are a part of this geometry. """ if self.hasz and not GEOS_PREPARE: # See: http://trac.osgeo.org/geos/ticket/216 raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D HEXEWKB.') return ewkb_w(3 if self.hasz else 2).write_hex(self) @property Loading Loading @@ -443,9 +438,6 @@ class GEOSGeometry(GEOSBase, ListMixin): This is an extension of the WKB specification that includes any SRID value that are a part of this geometry. """ if self.hasz and not GEOS_PREPARE: # See: http://trac.osgeo.org/geos/ticket/216 raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D EWKB.') return ewkb_w(3 if self.hasz else 2).write(self) @property Loading @@ -460,10 +452,7 @@ class GEOSGeometry(GEOSBase, ListMixin): Returns a PreparedGeometry corresponding to this geometry -- it is optimized for the contains, intersects, and covers operations. """ if GEOS_PREPARE: return PreparedGeometry(self) else: raise GEOSException('GEOS 3.1+ required for prepared geometry support.') #### GDAL-specific output routines #### @property Loading Loading @@ -707,7 +696,9 @@ from django.contrib.gis.geos.linestring import LineString, LinearRing from django.contrib.gis.geos.point import Point from django.contrib.gis.geos.polygon import Polygon from django.contrib.gis.geos.collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon GEOS_CLASSES = {0: Point, from django.contrib.gis.geos.prepared import PreparedGeometry GEOS_CLASSES = { 0: Point, 1: LineString, 2: LinearRing, 3: Polygon, Loading @@ -716,7 +707,3 @@ GEOS_CLASSES = {0: Point, 6: MultiPolygon, 7: GeometryCollection, } # If supported, import the PreparedGeometry class. if GEOS_PREPARE: from django.contrib.gis.geos.prepared import PreparedGeometry django/contrib/gis/geos/libgeos.py +7 −19 Original line number Diff line number Diff line Loading @@ -155,22 +155,10 @@ GEOS_MINOR_VERSION = int(_verinfo['minor']) GEOS_SUBMINOR_VERSION = int(_verinfo['subminor']) del _verinfo GEOS_VERSION = (GEOS_MAJOR_VERSION, GEOS_MINOR_VERSION, GEOS_SUBMINOR_VERSION) GEOS_PREPARE = GEOS_VERSION >= (3, 1, 0) if GEOS_PREPARE: # Here we set up the prototypes for the initGEOS_r and finishGEOS_r # routines. These functions aren't actually called until they are # attached to a GEOS context handle -- this actually occurs in # geos/prototypes/threadsafe.py. lgeos.initGEOS_r.restype = CONTEXT_PTR lgeos.finishGEOS_r.argtypes = [CONTEXT_PTR] else: # When thread-safety isn't available, the initGEOS routine must be called # first. This function takes the notice and error functions, defined # as Python callbacks above, as parameters. Here is the C code that is # wrapped: # extern void GEOS_DLL initGEOS(GEOSMessageHandler notice_function, GEOSMessageHandler error_function); lgeos.initGEOS(notice_h, error_h) # Calling finishGEOS() upon exit of the interpreter. import atexit atexit.register(lgeos.finishGEOS) django/contrib/gis/geos/prototypes/misc.py +6 −10 Original line number Diff line number Diff line Loading @@ -3,13 +3,13 @@ ones that return the area, distance, and length. """ from ctypes import c_int, c_double, POINTER from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOS_PREPARE from django.contrib.gis.geos.libgeos import GEOM_PTR from django.contrib.gis.geos.prototypes.errcheck import check_dbl, check_string from django.contrib.gis.geos.prototypes.geom import geos_char_p from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc from django.utils.six.moves import xrange __all__ = ['geos_area', 'geos_distance', 'geos_length'] __all__ = ['geos_area', 'geos_distance', 'geos_length', 'geos_isvalidreason'] ### ctypes generator function ### Loading @@ -31,11 +31,7 @@ def dbl_from_geom(func, num_geom=1): geos_area = dbl_from_geom(GEOSFunc('GEOSArea')) geos_distance = dbl_from_geom(GEOSFunc('GEOSDistance'), num_geom=2) geos_length = dbl_from_geom(GEOSFunc('GEOSLength')) # Validity reason; only in GEOS 3.1+ if GEOS_PREPARE: geos_isvalidreason = GEOSFunc('GEOSisValidReason') geos_isvalidreason.argtypes = [GEOM_PTR] geos_isvalidreason.restype = geos_char_p geos_isvalidreason.errcheck = check_string __all__.append('geos_isvalidreason') Loading
django/contrib/gis/geos/__init__.py +2 −2 Original line number Diff line number Diff line Loading @@ -6,9 +6,9 @@ for more details: __all__ = ['HAS_GEOS'] try: from .libgeos import geos_version, geos_version_info, GEOS_PREPARE # NOQA: flake8 detects only the last __all__ from .libgeos import geos_version, geos_version_info # NOQA: flake8 detects only the last __all__ HAS_GEOS = True __all__ += ['geos_version', 'geos_version_info', 'GEOS_PREPARE'] __all__ += ['geos_version', 'geos_version_info'] except ImportError: HAS_GEOS = False Loading
django/contrib/gis/geos/collections.py +2 −6 Original line number Diff line number Diff line Loading @@ -3,9 +3,8 @@ GeometryCollection, MultiPoint, MultiLineString, and MultiPolygon """ from ctypes import c_int, c_uint, byref from django.contrib.gis.geos.error import GEOSException from django.contrib.gis.geos.geometry import GEOSGeometry from django.contrib.gis.geos.libgeos import get_pointer_arr, GEOS_PREPARE from django.contrib.gis.geos.libgeos import get_pointer_arr from django.contrib.gis.geos.linestring import LineString, LinearRing from django.contrib.gis.geos.point import Point from django.contrib.gis.geos.polygon import Polygon Loading Loading @@ -119,10 +118,7 @@ class MultiPolygon(GeometryCollection): @property def cascaded_union(self): "Returns a cascaded union of this MultiPolygon." if GEOS_PREPARE: return GEOSGeometry(capi.geos_cascaded_union(self.ptr), self.srid) else: raise GEOSException('The cascaded union operation requires GEOS 3.1+.') # Setting the allowed types here since GeometryCollection is defined before # its subclasses. Loading
django/contrib/gis/geos/geometry.py +13 −26 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ from django.contrib.gis.gdal.error import SRSException from django.contrib.gis.geos.base import GEOSBase, gdal 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, GEOS_PREPARE from django.contrib.gis.geos.libgeos import GEOM_PTR # All other functions in this module come from the ctypes # prototypes module -- which handles all interaction with Loading Loading @@ -289,8 +289,6 @@ class GEOSGeometry(GEOSBase, ListMixin): """ Returns a string containing the reason for any invalidity. """ if not GEOS_PREPARE: raise GEOSException('Upgrade GEOS to 3.1 to get validity reason.') return capi.geos_isvalidreason(self.ptr).decode() #### Binary predicates. #### Loading Loading @@ -411,9 +409,6 @@ class GEOSGeometry(GEOSBase, ListMixin): extension of the WKB specification that includes SRID value that are a part of this geometry. """ if self.hasz and not GEOS_PREPARE: # See: http://trac.osgeo.org/geos/ticket/216 raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D HEXEWKB.') return ewkb_w(3 if self.hasz else 2).write_hex(self) @property Loading Loading @@ -443,9 +438,6 @@ class GEOSGeometry(GEOSBase, ListMixin): This is an extension of the WKB specification that includes any SRID value that are a part of this geometry. """ if self.hasz and not GEOS_PREPARE: # See: http://trac.osgeo.org/geos/ticket/216 raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D EWKB.') return ewkb_w(3 if self.hasz else 2).write(self) @property Loading @@ -460,10 +452,7 @@ class GEOSGeometry(GEOSBase, ListMixin): Returns a PreparedGeometry corresponding to this geometry -- it is optimized for the contains, intersects, and covers operations. """ if GEOS_PREPARE: return PreparedGeometry(self) else: raise GEOSException('GEOS 3.1+ required for prepared geometry support.') #### GDAL-specific output routines #### @property Loading Loading @@ -707,7 +696,9 @@ from django.contrib.gis.geos.linestring import LineString, LinearRing from django.contrib.gis.geos.point import Point from django.contrib.gis.geos.polygon import Polygon from django.contrib.gis.geos.collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon GEOS_CLASSES = {0: Point, from django.contrib.gis.geos.prepared import PreparedGeometry GEOS_CLASSES = { 0: Point, 1: LineString, 2: LinearRing, 3: Polygon, Loading @@ -716,7 +707,3 @@ GEOS_CLASSES = {0: Point, 6: MultiPolygon, 7: GeometryCollection, } # If supported, import the PreparedGeometry class. if GEOS_PREPARE: from django.contrib.gis.geos.prepared import PreparedGeometry
django/contrib/gis/geos/libgeos.py +7 −19 Original line number Diff line number Diff line Loading @@ -155,22 +155,10 @@ GEOS_MINOR_VERSION = int(_verinfo['minor']) GEOS_SUBMINOR_VERSION = int(_verinfo['subminor']) del _verinfo GEOS_VERSION = (GEOS_MAJOR_VERSION, GEOS_MINOR_VERSION, GEOS_SUBMINOR_VERSION) GEOS_PREPARE = GEOS_VERSION >= (3, 1, 0) if GEOS_PREPARE: # Here we set up the prototypes for the initGEOS_r and finishGEOS_r # routines. These functions aren't actually called until they are # attached to a GEOS context handle -- this actually occurs in # geos/prototypes/threadsafe.py. lgeos.initGEOS_r.restype = CONTEXT_PTR lgeos.finishGEOS_r.argtypes = [CONTEXT_PTR] else: # When thread-safety isn't available, the initGEOS routine must be called # first. This function takes the notice and error functions, defined # as Python callbacks above, as parameters. Here is the C code that is # wrapped: # extern void GEOS_DLL initGEOS(GEOSMessageHandler notice_function, GEOSMessageHandler error_function); lgeos.initGEOS(notice_h, error_h) # Calling finishGEOS() upon exit of the interpreter. import atexit atexit.register(lgeos.finishGEOS)
django/contrib/gis/geos/prototypes/misc.py +6 −10 Original line number Diff line number Diff line Loading @@ -3,13 +3,13 @@ ones that return the area, distance, and length. """ from ctypes import c_int, c_double, POINTER from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOS_PREPARE from django.contrib.gis.geos.libgeos import GEOM_PTR from django.contrib.gis.geos.prototypes.errcheck import check_dbl, check_string from django.contrib.gis.geos.prototypes.geom import geos_char_p from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc from django.utils.six.moves import xrange __all__ = ['geos_area', 'geos_distance', 'geos_length'] __all__ = ['geos_area', 'geos_distance', 'geos_length', 'geos_isvalidreason'] ### ctypes generator function ### Loading @@ -31,11 +31,7 @@ def dbl_from_geom(func, num_geom=1): geos_area = dbl_from_geom(GEOSFunc('GEOSArea')) geos_distance = dbl_from_geom(GEOSFunc('GEOSDistance'), num_geom=2) geos_length = dbl_from_geom(GEOSFunc('GEOSLength')) # Validity reason; only in GEOS 3.1+ if GEOS_PREPARE: geos_isvalidreason = GEOSFunc('GEOSisValidReason') geos_isvalidreason.argtypes = [GEOM_PTR] geos_isvalidreason.restype = geos_char_p geos_isvalidreason.errcheck = check_string __all__.append('geos_isvalidreason')