本文整理汇总了Python中django.contrib.gis.geometry.backend.Geometry方法的典型用法代码示例。如果您正苦于以下问题:Python backend.Geometry方法的具体用法?Python backend.Geometry怎么用?Python backend.Geometry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.gis.geometry.backend
的用法示例。
在下文中一共展示了backend.Geometry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_extent
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def convert_extent(self, clob, srid):
if clob:
# Generally, Oracle returns a polygon for the extent -- however,
# it can return a single point if there's only one Point in the
# table.
ext_geom = Geometry(clob.read(), srid)
gtype = str(ext_geom.geom_type)
if gtype == 'Polygon':
# Construct the 4-tuple from the coordinates in the polygon.
shell = ext_geom.shell
ll, ur = shell[0][:2], shell[2][:2]
elif gtype == 'Point':
ll = ext_geom.coords[:2]
ur = ll
else:
raise Exception('Unexpected geometry type returned for extent: %s' % gtype)
xmin, ymin = ll
xmax, ymax = ur
return (xmin, ymin, xmax, ymax)
else:
return None
示例2: _geo_field
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def _geo_field(self, field_name=None):
"""
Returns the first Geometry field encountered or the one specified via
the `field_name` keyword. The `field_name` may be a string specifying
the geometry field on this GeoQuerySet's model, or a lookup string
to a geometry field via a ForeignKey relation.
"""
if field_name is None:
# Incrementing until the first geographic field is found.
for field in self.model._meta.fields:
if isinstance(field, GeometryField):
return field
return False
else:
# Otherwise, check by the given field name -- which may be
# a lookup to a _related_ geographic field.
return GISLookup._check_geo_field(self.model._meta, field_name)
示例3: __init__
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def __init__(self, obj, geography=False):
"""
Initialize on the spatial object.
"""
self.is_geometry = isinstance(obj, (Geometry, PostGISAdapter))
# Getting the WKB (in string form, to allow easy pickling of
# the adaptor) and the SRID from the geometry or raster.
if self.is_geometry:
self.ewkb = bytes(obj.ewkb)
self._adapter = Binary(self.ewkb)
else:
self.ewkb = to_pgraster(obj)
self.srid = obj.srid
self.geography = geography
示例4: _geomset_attribute
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def _geomset_attribute(self, func, geom, tolerance=0.05, **kwargs):
"""
DRY routine for setting up a GeoQuerySet method that attaches a
Geometry attribute and takes a Geoemtry parameter. This is used
for geometry set-like operations (e.g., intersection, difference,
union, sym_difference).
"""
s = {
'geom_args': ('geom',),
'select_field': GeomField(),
'procedure_fmt': '%(geo_col)s,%(geom)s',
'procedure_args': {'geom': geom},
}
if connections[self.db].ops.oracle:
s['procedure_fmt'] += ',%(tolerance)s'
s['procedure_args']['tolerance'] = tolerance
return self._spatial_attribute(func, s, **kwargs)
示例5: _get_db_prep_lookup
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def _get_db_prep_lookup(self, lookup_type, value, connection):
"""
Prepare for the database lookup, and return any spatial parameters
necessary for the query. This includes wrapping any geometry
parameters with a backend-specific adapter and formatting any distance
parameters into the correct units for the coordinate system of the
field.
Only used by the deprecated GeoQuerySet and to be
RemovedInDjango20Warning.
"""
# Populating the parameters list, and wrapping the Geometry
# with the Adapter of the spatial backend.
if isinstance(value, (tuple, list)):
params = [connection.ops.Adapter(value[0])]
# Getting the distance parameter in the units of the field.
params += self.get_distance(value[1:], lookup_type, connection)
else:
params = [connection.ops.Adapter(value)]
return params
# The OpenGIS Geometry Type Fields
示例6: as_postgresql
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def as_postgresql(self, compiler, connection):
geo_field = GeometryField(srid=self.srid) # Fake field to get SRID info
if self.source_is_geography():
# Set parameters as geography if base field is geography
for pos, expr in enumerate(
self.source_expressions[self.geom_param_pos + 1:], start=self.geom_param_pos + 1):
if isinstance(expr, GeomValue):
expr.geography = True
elif geo_field.geodetic(connection):
# Geometry fields with geodetic (lon/lat) coordinates need special distance functions
if self.spheroid:
# DistanceSpheroid is more accurate and resource intensive than DistanceSphere
self.function = connection.ops.spatial_function_name('DistanceSpheroid')
# Replace boolean param by the real spheroid of the base field
self.source_expressions[2] = Value(geo_field._spheroid)
else:
self.function = connection.ops.spatial_function_name('DistanceSphere')
return super(Distance, self).as_sql(compiler, connection)
示例7: convert_geometry
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
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
示例8: convert_geom
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def convert_geom(self, value, geo_field):
if value:
if isinstance(value, Database.LOB):
value = value.read()
return Geometry(value, geo_field.srid)
else:
return None
示例9: convert_geom
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def convert_geom(self, hex, geo_field):
"""
Converts the geometry returned from PostGIS aggregates.
"""
if hex:
return Geometry(hex, srid=geo_field.srid)
else:
return None
示例10: convert_extent
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def convert_extent(self, box, srid):
"""
Convert the polygon data received from Spatialite to min/max values.
"""
if box is None:
return None
shell = Geometry(box, srid).shell
xmin, ymin = shell[0][:2]
xmax, ymax = shell[2][:2]
return (xmin, ymin, xmax, ymax)
示例11: get_prep_value
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def get_prep_value(self, value):
"""
Spatial lookup values are either a parameter that is (or may be
converted to) a geometry, or a sequence of lookup values that
begins with a geometry. This routine will setup the geometry
value properly, and preserve any other lookup parameters before
returning to the caller.
"""
value = super(GeometryField, self).get_prep_value(value)
if isinstance(value, Expression):
return value
elif isinstance(value, (tuple, list)):
geom = value[0]
seq_value = True
else:
geom = value
seq_value = False
# When the input is not a GEOS geometry, attempt to construct one
# from the given string input.
if isinstance(geom, Geometry):
pass
elif isinstance(geom, (bytes, six.string_types)) or hasattr(geom, '__geo_interface__'):
try:
geom = Geometry(geom)
except GeometryException:
raise ValueError('Could not create geometry from lookup value.')
else:
raise ValueError('Cannot use object with type %s for a geometry lookup parameter.' % type(geom).__name__)
# Assigning the SRID value.
geom.srid = self.get_srid(geom)
if seq_value:
lookup_val = [geom]
lookup_val.extend(value[1:])
return tuple(lookup_val)
else:
return geom
示例12: from_db_value
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def from_db_value(self, value, expression, connection, context):
if value and not isinstance(value, Geometry):
value = Geometry(value)
return value
示例13: contribute_to_class
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def contribute_to_class(self, cls, name, **kwargs):
super(GeometryField, self).contribute_to_class(cls, name, **kwargs)
# Setup for lazy-instantiated Geometry object.
setattr(cls, self.attname, SpatialProxy(Geometry, self))
示例14: get_db_prep_lookup
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
"""
Prepare for the database lookup, and return any spatial parameters
necessary for the query. This includes wrapping any geometry
parameters with a backend-specific adapter and formatting any distance
parameters into the correct units for the coordinate system of the
field.
"""
# special case for isnull lookup
if lookup_type == 'isnull':
return []
elif lookup_type in self.class_lookups:
# Populating the parameters list, and wrapping the Geometry
# with the Adapter of the spatial backend.
if isinstance(value, (tuple, list)):
params = [connection.ops.Adapter(value[0])]
if self.class_lookups[lookup_type].distance:
# Getting the distance parameter in the units of the field.
params += self.get_distance(value[1:], lookup_type, connection)
elif lookup_type in connection.ops.truncate_params:
# Lookup is one where SQL parameters aren't needed from the
# given lookup value.
pass
else:
params += value[1:]
elif isinstance(value, Expression):
params = []
else:
params = [connection.ops.Adapter(value)]
return params
else:
raise ValueError('%s is not a valid spatial lookup for %s.' %
(lookup_type, self.__class__.__name__))
示例15: intersection
# 需要导入模块: from django.contrib.gis.geometry import backend [as 别名]
# 或者: from django.contrib.gis.geometry.backend import Geometry [as 别名]
def intersection(self, geom, **kwargs):
"""
Returns the spatial intersection of the Geometry field in
an `intersection` attribute on each element of this
GeoQuerySet.
"""
return self._geomset_attribute('intersection', geom, **kwargs)