parent
816c5753ac
commit
08972528c2
|
@ -134,23 +134,14 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations):
|
||||||
)
|
)
|
||||||
if internal_type in geometry_fields:
|
if internal_type in geometry_fields:
|
||||||
converters.append(self.convert_textfield_value)
|
converters.append(self.convert_textfield_value)
|
||||||
if hasattr(expression.output_field, 'geom_type'):
|
|
||||||
converters.append(self.convert_geometry)
|
|
||||||
return converters
|
return converters
|
||||||
|
|
||||||
def convert_geometry(self, value, expression, connection, context):
|
def convert_extent(self, clob):
|
||||||
if value:
|
|
||||||
value = Geometry(value)
|
|
||||||
if 'transformed_srid' in context:
|
|
||||||
value.srid = context['transformed_srid']
|
|
||||||
return value
|
|
||||||
|
|
||||||
def convert_extent(self, clob, srid):
|
|
||||||
if clob:
|
if clob:
|
||||||
# Generally, Oracle returns a polygon for the extent -- however,
|
# Generally, Oracle returns a polygon for the extent -- however,
|
||||||
# it can return a single point if there's only one Point in the
|
# it can return a single point if there's only one Point in the
|
||||||
# table.
|
# table.
|
||||||
ext_geom = Geometry(clob.read(), srid)
|
ext_geom = Geometry(clob.read())
|
||||||
gtype = str(ext_geom.geom_type)
|
gtype = str(ext_geom.geom_type)
|
||||||
if gtype == 'Polygon':
|
if gtype == 'Polygon':
|
||||||
# Construct the 4-tuple from the coordinates in the polygon.
|
# Construct the 4-tuple from the coordinates in the polygon.
|
||||||
|
|
|
@ -206,7 +206,7 @@ class PostGISOperations(BaseSpatialOperations, DatabaseOperations):
|
||||||
version = vtup[1:]
|
version = vtup[1:]
|
||||||
return version
|
return version
|
||||||
|
|
||||||
def convert_extent(self, box, srid):
|
def convert_extent(self, box):
|
||||||
"""
|
"""
|
||||||
Return a 4-tuple extent for the `Extent` aggregate by converting
|
Return a 4-tuple extent for the `Extent` aggregate by converting
|
||||||
the bounding box text returned by PostGIS (`box` argument), for
|
the bounding box text returned by PostGIS (`box` argument), for
|
||||||
|
@ -219,7 +219,7 @@ class PostGISOperations(BaseSpatialOperations, DatabaseOperations):
|
||||||
xmax, ymax = map(float, ur.split())
|
xmax, ymax = map(float, ur.split())
|
||||||
return (xmin, ymin, xmax, ymax)
|
return (xmin, ymin, xmax, ymax)
|
||||||
|
|
||||||
def convert_extent3d(self, box3d, srid):
|
def convert_extent3d(self, box3d):
|
||||||
"""
|
"""
|
||||||
Return a 6-tuple extent for the `Extent3D` aggregate by converting
|
Return a 6-tuple extent for the `Extent3D` aggregate by converting
|
||||||
the 3d bounding-box text returned by PostGIS (`box3d` argument), for
|
the 3d bounding-box text returned by PostGIS (`box3d` argument), for
|
||||||
|
|
|
@ -113,13 +113,13 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
|
||||||
raise ImproperlyConfigured('GeoDjango only supports SpatiaLite versions 4.0.0 and above.')
|
raise ImproperlyConfigured('GeoDjango only supports SpatiaLite versions 4.0.0 and above.')
|
||||||
return version
|
return version
|
||||||
|
|
||||||
def convert_extent(self, box, srid):
|
def convert_extent(self, box):
|
||||||
"""
|
"""
|
||||||
Convert the polygon data received from SpatiaLite to min/max values.
|
Convert the polygon data received from SpatiaLite to min/max values.
|
||||||
"""
|
"""
|
||||||
if box is None:
|
if box is None:
|
||||||
return None
|
return None
|
||||||
shell = Geometry(box, srid).shell
|
shell = Geometry(box).shell
|
||||||
xmin, ymin = shell[0][:2]
|
xmin, ymin = shell[0][:2]
|
||||||
xmax, ymax = shell[2][:2]
|
xmax, ymax = shell[2][:2]
|
||||||
return (xmin, ymin, xmax, ymax)
|
return (xmin, ymin, xmax, ymax)
|
||||||
|
@ -242,16 +242,3 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
|
||||||
def spatial_ref_sys(self):
|
def spatial_ref_sys(self):
|
||||||
from django.contrib.gis.db.backends.spatialite.models import SpatialiteSpatialRefSys
|
from django.contrib.gis.db.backends.spatialite.models import SpatialiteSpatialRefSys
|
||||||
return SpatialiteSpatialRefSys
|
return SpatialiteSpatialRefSys
|
||||||
|
|
||||||
def get_db_converters(self, expression):
|
|
||||||
converters = super().get_db_converters(expression)
|
|
||||||
if hasattr(expression.output_field, 'geom_type'):
|
|
||||||
converters.append(self.convert_geometry)
|
|
||||||
return converters
|
|
||||||
|
|
||||||
def convert_geometry(self, value, expression, connection, context):
|
|
||||||
if value:
|
|
||||||
value = Geometry(value)
|
|
||||||
if 'transformed_srid' in context:
|
|
||||||
value.srid = context['transformed_srid']
|
|
||||||
return value
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Extent(GeoAggregate):
|
||||||
super().__init__(expression, output_field=ExtentField(), **extra)
|
super().__init__(expression, output_field=ExtentField(), **extra)
|
||||||
|
|
||||||
def convert_value(self, value, expression, connection, context):
|
def convert_value(self, value, expression, connection, context):
|
||||||
return connection.ops.convert_extent(value, context.get('transformed_srid'))
|
return connection.ops.convert_extent(value)
|
||||||
|
|
||||||
|
|
||||||
class Extent3D(GeoAggregate):
|
class Extent3D(GeoAggregate):
|
||||||
|
@ -54,7 +54,7 @@ class Extent3D(GeoAggregate):
|
||||||
super().__init__(expression, output_field=ExtentField(), **extra)
|
super().__init__(expression, output_field=ExtentField(), **extra)
|
||||||
|
|
||||||
def convert_value(self, value, expression, connection, context):
|
def convert_value(self, value, expression, connection, context):
|
||||||
return connection.ops.convert_extent3d(value, context.get('transformed_srid'))
|
return connection.ops.convert_extent3d(value)
|
||||||
|
|
||||||
|
|
||||||
class MakeLine(GeoAggregate):
|
class MakeLine(GeoAggregate):
|
||||||
|
|
|
@ -57,18 +57,12 @@ class GeoSelectFormatMixin:
|
||||||
other fields, return a simple '%s' format string.
|
other fields, return a simple '%s' format string.
|
||||||
"""
|
"""
|
||||||
connection = compiler.connection
|
connection = compiler.connection
|
||||||
srid = compiler.query.get_context('transformed_srid')
|
|
||||||
if srid:
|
|
||||||
sel_fmt = '%s(%%s, %s)' % (connection.ops.transform, srid)
|
|
||||||
else:
|
|
||||||
sel_fmt = '%s'
|
|
||||||
if connection.ops.select:
|
if connection.ops.select:
|
||||||
# This allows operations to be done on fields in the SELECT,
|
# This allows operations to be done on fields in the SELECT,
|
||||||
# overriding their values -- used by the Oracle and MySQL
|
# overriding their values -- used by the Oracle and MySQL
|
||||||
# spatial backends to get database values as WKT, and by the
|
# spatial backends to get database values as WKT.
|
||||||
# `transform` method.
|
sql = connection.ops.select % sql
|
||||||
sel_fmt = connection.ops.select % sel_fmt
|
return sql, params
|
||||||
return sel_fmt % sql, params
|
|
||||||
|
|
||||||
|
|
||||||
class BaseSpatialField(Field):
|
class BaseSpatialField(Field):
|
||||||
|
|
Loading…
Reference in New Issue