From 1bf5e79394c43af29d2c67c54b32dca0f0e42ca2 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Thu, 16 Mar 2017 18:38:02 +0500 Subject: [PATCH] Removed GeoQuerySet leftovers. Follow up to a0d166306fbdc41f49e6fadf4ec84b17eb147daa. --- .../gis/db/backends/base/operations.py | 31 --------------- .../gis/db/backends/oracle/operations.py | 20 ++-------- .../gis/db/backends/postgis/operations.py | 38 ++----------------- .../gis/db/backends/spatialite/operations.py | 26 ++----------- tests/gis_tests/geoapp/test_functions.py | 2 +- 5 files changed, 13 insertions(+), 104 deletions(-) diff --git a/django/contrib/gis/db/backends/base/operations.py b/django/contrib/gis/db/backends/base/operations.py index e24e45188c..ceb899a1e0 100644 --- a/django/contrib/gis/db/backends/base/operations.py +++ b/django/contrib/gis/db/backends/base/operations.py @@ -16,30 +16,6 @@ class BaseSpatialOperations: geography = False geometry = False - area = False - bounding_circle = False - centroid = False - difference = False - distance = False - distance_sphere = False - distance_spheroid = False - envelope = False - force_rhr = False - mem_size = False - num_geom = False - num_points = False - perimeter = False - perimeter3d = False - point_on_surface = False - polygonize = False - reverse = False - scale = False - snap_to_grid = False - sym_difference = False - transform = False - translate = False - union = False - # Aggregates disallowed_aggregates = () @@ -59,13 +35,6 @@ class BaseSpatialOperations: 'Translate', 'Union', } - # Serialization - geohash = False - geojson = False - gml = False - kml = False - svg = False - # Constructors from_text = False from_wkb = False diff --git a/django/contrib/gis/db/backends/oracle/operations.py b/django/contrib/gis/db/backends/oracle/operations.py index 6c82996692..4778da135a 100644 --- a/django/contrib/gis/db/backends/oracle/operations.py +++ b/django/contrib/gis/db/backends/oracle/operations.py @@ -63,21 +63,7 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations): Adapter = OracleSpatialAdapter - area = 'SDO_GEOM.SDO_AREA' - gml = 'SDO_UTIL.TO_GMLGEOMETRY' - centroid = 'SDO_GEOM.SDO_CENTROID' - difference = 'SDO_GEOM.SDO_DIFFERENCE' - distance = 'SDO_GEOM.SDO_DISTANCE' extent = 'SDO_AGGR_MBR' - intersection = 'SDO_GEOM.SDO_INTERSECTION' - length = 'SDO_GEOM.SDO_LENGTH' - num_points = 'SDO_UTIL.GETNUMVERTICES' - perimeter = length - point_on_surface = 'SDO_GEOM.SDO_POINTONSURFACE' - reverse = 'SDO_UTIL.REVERSE_LINESTRING' - sym_difference = 'SDO_GEOM.SDO_XOR' - transform = 'SDO_CS.TRANSFORM' - union = 'SDO_GEOM.SDO_UNION' unionagg = 'SDO_AGGR_UNION' from_text = 'SDO_GEOMETRY' @@ -222,6 +208,8 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations): SRID of the field. Specifically, this routine will substitute in the SDO_CS.TRANSFORM() function call. """ + tranform_func = self.spatial_function_name('Transform') + if value is None: return 'NULL' @@ -230,7 +218,7 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations): if hasattr(value, 'as_sql'): if transform_value(value, f.srid): - placeholder = '%s(%%s, %s)' % (self.transform, f.srid) + placeholder = '%s(%%s, %s)' % (tranform_func, f.srid) else: placeholder = '%s' # No geometry value used for F expression, substitute in @@ -239,7 +227,7 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations): return placeholder % sql else: if transform_value(value, f.srid): - return '%s(SDO_GEOMETRY(%%s, %s), %s)' % (self.transform, value.srid, f.srid) + return '%s(SDO_GEOMETRY(%%s, %s), %s)' % (tranform_func, value.srid, f.srid) else: return 'SDO_GEOMETRY(%%s, %s)' % f.srid diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py index 574aa5ff4a..7bb66b8a0c 100644 --- a/django/contrib/gis/db/backends/postgis/operations.py +++ b/django/contrib/gis/db/backends/postgis/operations.py @@ -153,44 +153,12 @@ class PostGISOperations(BaseSpatialOperations, DatabaseOperations): prefix = self.geom_func_prefix - self.area = prefix + 'Area' - self.bounding_circle = prefix + 'MinimumBoundingCircle' - self.centroid = prefix + 'Centroid' self.collect = prefix + 'Collect' - self.difference = prefix + 'Difference' - self.distance = prefix + 'Distance' - self.distance_sphere = prefix + 'distance_sphere' - self.distance_spheroid = prefix + 'distance_spheroid' - self.envelope = prefix + 'Envelope' self.extent = prefix + 'Extent' self.extent3d = prefix + '3DExtent' - self.force_rhr = prefix + 'ForceRHR' - self.geohash = prefix + 'GeoHash' - self.geojson = prefix + 'AsGeoJson' - self.gml = prefix + 'AsGML' - self.intersection = prefix + 'Intersection' - self.isvalid = prefix + 'IsValid' - self.kml = prefix + 'AsKML' - self.length = prefix + 'Length' self.length3d = prefix + '3DLength' - self.length_spheroid = prefix + 'length_spheroid' self.makeline = prefix + 'MakeLine' - self.makevalid = prefix + 'MakeValid' - self.mem_size = prefix + 'mem_size' - self.num_geom = prefix + 'NumGeometries' - self.num_points = prefix + 'npoints' - self.perimeter = prefix + 'Perimeter' self.perimeter3d = prefix + '3DPerimeter' - self.point_on_surface = prefix + 'PointOnSurface' - self.polygonize = prefix + 'Polygonize' - self.reverse = prefix + 'Reverse' - self.scale = prefix + 'Scale' - self.snap_to_grid = prefix + 'SnapToGrid' - self.svg = prefix + 'AsSVG' - self.sym_difference = prefix + 'SymDifference' - self.transform = prefix + 'Transform' - self.translate = prefix + 'Translate' - self.union = prefix + 'Union' self.unionagg = prefix + 'Union' @cached_property @@ -324,6 +292,8 @@ class PostGISOperations(BaseSpatialOperations, DatabaseOperations): not in the SRID of the field. Specifically, this routine will substitute in the ST_Transform() function call. """ + tranform_func = self.spatial_function_name('Transform') + # Get the srid for this object if value is None: value_srid = None @@ -337,9 +307,9 @@ class PostGISOperations(BaseSpatialOperations, DatabaseOperations): if value_srid is None or value_srid == f.srid: placeholder = '%s' elif f.geom_type == 'RASTER' and isinstance(value, str): - placeholder = '%s((%%s)::raster, %s)' % (self.transform, f.srid) + placeholder = '%s((%%s)::raster, %s)' % (tranform_func, f.srid) else: - placeholder = '%s(%%s, %s)' % (self.transform, f.srid) + placeholder = '%s(%%s, %s)' % (tranform_func, f.srid) if hasattr(value, 'as_sql'): # If this is an F expression, then we don't really want diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py index 33c69dc1a7..b859765c20 100644 --- a/django/contrib/gis/db/backends/spatialite/operations.py +++ b/django/contrib/gis/db/backends/spatialite/operations.py @@ -38,29 +38,9 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations): Adapter = SpatiaLiteAdapter - area = 'Area' - centroid = 'Centroid' collect = 'Collect' - contained = 'MbrWithin' - difference = 'Difference' - distance = 'Distance' - envelope = 'Envelope' extent = 'Extent' - geojson = 'AsGeoJSON' - gml = 'AsGML' - intersection = 'Intersection' - kml = 'AsKML' - length = 'GLength' # OpenGis defines Length, but this conflicts with an SQLite reserved keyword makeline = 'MakeLine' - num_geom = 'NumGeometries' - num_points = 'NumPoints' - point_on_surface = 'PointOnSurface' - scale = 'ScaleCoords' - svg = 'AsSVG' - sym_difference = 'SymDifference' - transform = 'Transform' - translate = 'ShiftCoords' - union = 'GUnion' # OpenGis defines Union, but this conflicts with an SQLite reserved keyword unionagg = 'GUnion' from_text = 'GeomFromText' @@ -178,11 +158,13 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations): SRID of the field. Specifically, this routine will substitute in the Transform() and GeomFromText() function call(s). """ + tranform_func = self.spatial_function_name('Transform') + def transform_value(value, srid): return not (value is None or value.srid == srid) if hasattr(value, 'as_sql'): if transform_value(value, f.srid): - placeholder = '%s(%%s, %s)' % (self.transform, f.srid) + placeholder = '%s(%%s, %s)' % (tranform_func, f.srid) else: placeholder = '%s' # No geometry value used for F expression, substitute in @@ -192,7 +174,7 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations): else: if transform_value(value, f.srid): # Adding Transform() to the SQL placeholder. - return '%s(%s(%%s,%s), %s)' % (self.transform, self.from_text, value.srid, f.srid) + return '%s(%s(%%s,%s), %s)' % (tranform_func, self.from_text, value.srid, f.srid) else: return '%s(%%s,%s)' % (self.from_text, f.srid) diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index 6b2a725ff7..ac429dfda9 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -24,7 +24,7 @@ class GISFunctionsTests(TestCase): def test_asgeojson(self): # Only PostGIS and SpatiaLite support GeoJSON. - if not connection.ops.geojson: + if not connection.features.has_AsGeoJSON_function: with self.assertRaises(NotImplementedError): list(Country.objects.annotate(json=functions.AsGeoJSON('mpoly'))) return