本文整理汇总了Python中django.contrib.gis.forms.GeometryField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.GeometryField方法的具体用法?Python forms.GeometryField怎么用?Python forms.GeometryField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.gis.forms
的用法示例。
在下文中一共展示了forms.GeometryField方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [as 别名]
def __init__(self, verbose_name=None, dim=2, geography=False, **kwargs):
"""
The initialization function for geometry fields. In addition to the
parameters from BaseSpatialField, it takes the following as keyword
arguments:
dim:
The number of dimensions for this geometry. Defaults to 2.
extent:
Customize the extent, in a 4-tuple of WGS 84 coordinates, for the
geometry field entry in the `USER_SDO_GEOM_METADATA` table. Defaults
to (-180.0, -90.0, 180.0, 90.0).
tolerance:
Define the tolerance, in meters, to use for the geometry field
entry in the `USER_SDO_GEOM_METADATA` table. Defaults to 0.05.
"""
# Setting the dimension of the geometry field.
self.dim = dim
# Is this a geography rather than a geometry column?
self.geography = geography
# Oracle-specific private attributes for creating the entry in
# `USER_SDO_GEOM_METADATA`
self._extent = kwargs.pop('extent', (-180.0, -90.0, 180.0, 90.0))
self._tolerance = kwargs.pop('tolerance', 0.05)
super(GeometryField, self).__init__(verbose_name=verbose_name, **kwargs)
示例2: deconstruct
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [as 别名]
def deconstruct(self):
name, path, args, kwargs = super(GeometryField, self).deconstruct()
# Include kwargs if they're not the default values.
if self.dim != 2:
kwargs['dim'] = self.dim
if self.geography is not False:
kwargs['geography'] = self.geography
return name, path, args, kwargs
# ### Routines specific to GeometryField ###
示例3: get_prep_value
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [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
示例4: contribute_to_class
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [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))
示例5: formfield
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [as 别名]
def formfield(self, **kwargs):
defaults = {'form_class': self.form_class,
'geom_type': self.geom_type,
'srid': self.srid,
}
defaults.update(kwargs)
if (self.dim > 2 and 'widget' not in kwargs and
not getattr(defaults['form_class'].widget, 'supports_3d', False)):
defaults['widget'] = forms.Textarea
return super(GeometryField, self).formfield(**defaults)
示例6: get_db_prep_value
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [as 别名]
def get_db_prep_value(self, value, connection, *args, **kwargs):
return connection.ops.Adapter(
super(GeometryField, self).get_db_prep_value(value, connection, *args, **kwargs),
**({'geography': True} if self.geography else {})
)
示例7: deconstruct
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [as 别名]
def deconstruct(self):
name, path, args, kwargs = super(GeometryField, self).deconstruct()
# Always include SRID for less fragility; include others if they're
# not the default values.
kwargs['srid'] = self.srid
if self.dim != 2:
kwargs['dim'] = self.dim
if self.spatial_index is not True:
kwargs['spatial_index'] = self.spatial_index
if self.geography is not False:
kwargs['geography'] = self.geography
return name, path, args, kwargs
# The following functions are used to get the units, their name, and
# the spheroid corresponding to the SRID of the GeometryField.
示例8: units_name
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [as 别名]
def units_name(self, connection):
if not hasattr(self, '_units_name'):
self._get_srid_info(connection)
return self._units_name
# ### Routines specific to GeometryField ###
示例9: contribute_to_class
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [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, GeometryProxy(Geometry, self))
示例10: get_prep_lookup
# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import GeometryField [as 别名]
def get_prep_lookup(self, lookup_type, value):
if lookup_type == 'contains':
# 'contains' name might conflict with the "normal" contains lookup,
# for which the value is not prepared, but left as-is.
return self.get_prep_value(value)
return super(GeometryField, self).get_prep_lookup(lookup_type, value)