本文整理汇总了Python中django.contrib.gis.geos.GEOSException方法的典型用法代码示例。如果您正苦于以下问题:Python geos.GEOSException方法的具体用法?Python geos.GEOSException怎么用?Python geos.GEOSException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.gis.geos
的用法示例。
在下文中一共展示了geos.GEOSException方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_python
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def to_python(self, value):
"""
Transforms the value to a Geometry object.
"""
if value in self.empty_values:
return None
if not isinstance(value, GEOSGeometry):
try:
value = GEOSGeometry(value)
except (GEOSException, ValueError, TypeError):
raise forms.ValidationError(self.error_messages['invalid_geom'], code='invalid_geom')
# Try to set the srid
if not value.srid:
try:
value.srid = self.widget.map_srid
except AttributeError:
if self.srid:
value.srid = self.srid
return value
示例2: clean
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def clean(self, value):
"""
Validates that the input value can be converted to a Geometry
object (which is returned). A ValidationError is raised if
the value cannot be instantiated as a Geometry.
"""
geom = super(GeometryField, self).clean(value)
if geom is None:
return geom
# Ensuring that the geometry is of the correct type (indicated
# using the OGC string label).
if str(geom.geom_type).upper() != self.geom_type and not self.geom_type == 'GEOMETRY':
raise forms.ValidationError(self.error_messages['invalid_geom_type'], code='invalid_geom_type')
# Transforming the geometry if the SRID was set.
if self.srid and self.srid != -1 and self.srid != geom.srid:
try:
geom.transform(self.srid)
except GEOSException:
raise forms.ValidationError(
self.error_messages['transform_error'], code='transform_error')
return geom
示例3: to_python
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def to_python(self, value):
"""Transform the value to a Geometry object."""
if value in self.empty_values:
return None
if not isinstance(value, GEOSGeometry):
try:
value = GEOSGeometry(value)
except (GEOSException, ValueError, TypeError):
raise forms.ValidationError(self.error_messages['invalid_geom'], code='invalid_geom')
# Try to set the srid
if not value.srid:
try:
value.srid = self.widget.map_srid
except AttributeError:
if self.srid:
value.srid = self.srid
return value
示例4: clean
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def clean(self, value):
"""
Validate that the input value can be converted to a Geometry object
and return it. Raise a ValidationError if the value cannot be
instantiated as a Geometry.
"""
geom = super().clean(value)
if geom is None:
return geom
# Ensuring that the geometry is of the correct type (indicated
# using the OGC string label).
if str(geom.geom_type).upper() != self.geom_type and not self.geom_type == 'GEOMETRY':
raise forms.ValidationError(self.error_messages['invalid_geom_type'], code='invalid_geom_type')
# Transforming the geometry if the SRID was set.
if self.srid and self.srid != -1 and self.srid != geom.srid:
try:
geom.transform(self.srid)
except GEOSException:
raise forms.ValidationError(
self.error_messages['transform_error'], code='transform_error')
return geom
示例5: deserialize
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def deserialize(self, value):
try:
return GEOSGeometry(value, self.map_srid)
except (GEOSException, ValueError) as err:
logger.error(
"Error creating geometry from value '%s' (%s)" % (
value, err)
)
return None
示例6: deserialize
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def deserialize(self, value):
try:
return GEOSGeometry(value)
except (GEOSException, ValueError) as err:
logger.error("Error creating geometry from value '%s' (%s)", value, err)
return None
示例7: parse_geo_json
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def parse_geo_json(geo_json):
"""Parses GeoJSON and returns a geometry object and metadata.
:param geo_json: The geo json to parse
:type geo_json: dict
:rtype: GEOSGeometry, dict
:returns: the geometry and metadata
"""
geom = None
geom_json = None
props = None
if geo_json['type'] == 'Feature':
geom_json = geo_json['geometry']
if 'properties' in geo_json:
props = geo_json['properties']
elif geo_json['type'] == 'FeatureCollection':
# Currently handles collections by just grabbing first entry
geom_json = geo_json['features'][0]['geometry']
if 'properties' in geo_json['features'][0]:
props = geo_json['features'][0]['properties']
else:
# The GeoJSON is just a geometry
geom_json = geo_json
# Parse geometry
if geom_json:
try:
geom = geos.GEOSGeometry(json.dumps(geom_json), srid=4326)
except geos.GEOSException as geos_error:
raise InvalidResultsManifest(str(geos_error))
return geom, props
示例8: data
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def data(self):
if not hasattr(self, '_data'):
self._data = super(FeatureSerializer, self).data
if 'crs' not in self._data:
try:
field = self.fields[self.Meta.geom_field]
srid = getattr(self.instance, field.source).srid
except (AttributeError, geos.GEOSException):
pass
else:
self._data['crs'] = sc.NamedCRS(srid)
return self._data
示例9: get_attribute
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def get_attribute(self, instance):
# SpatiaLite returns empty/invalid geometries in WKT or GeoJSON with
# exceedingly high simplification tolerances.
try:
return super(GeometryField, self).get_attribute(instance)
except geos.GEOSException:
return None
示例10: validate_row
# 需要导入模块: from django.contrib.gis import geos [as 别名]
# 或者: from django.contrib.gis.geos import GEOSException [as 别名]
def validate_row(headers, row, config):
party_name, party_type, geometry, tenure_type, location_type = (
None, None, None, None, None)
(party_name_field, party_type_field, location_type_field, type,
geometry_field, tenure_type_field) = get_fields_from_config(config)
if len(headers) != len(row):
raise ValidationError(
_("Number of headers and columns do not match.")
)
_get_field_value = partial(get_field_value, headers, row)
if party_name_field and party_type_field:
party_name = _get_field_value(party_name_field, "party_name")
party_type = _get_field_value(party_type_field, "party_type")
if geometry_field:
coords = _get_field_value(geometry_field, "geometry_field")
if coords == '':
geometry = None
else:
try:
geometry = GEOSGeometry(coords)
except (ValueError, GEOSException):
try:
geometry = GEOSGeometry(odk_geom_to_wkt(coords))
except InvalidODKGeometryError:
raise ValidationError(_("Invalid geometry."))
if location_type_field:
location_type = _get_field_value(location_type_field, "location_type")
type_choices = config['allowed_location_types']
if location_type and location_type not in type_choices:
raise ValidationError(
_("Invalid location_type: '%s'.") % location_type
)
if party_name_field and geometry_field:
tenure_type = _get_field_value(tenure_type_field, 'tenure_type')
if tenure_type and tenure_type not in config['allowed_tenure_types']:
raise ValidationError(
_("Invalid tenure_type: '%s'.") % tenure_type
)
values = (party_name, party_type, geometry, location_type, tenure_type)
if not all(sanitize_string(val) for val in values):
raise ValidationError(SANITIZE_ERROR)
return values