當前位置: 首頁>>代碼示例>>Python>>正文


Python geos.GEOSException方法代碼示例

本文整理匯總了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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:23,代碼來源:fields.py

示例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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:26,代碼來源:fields.py

示例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 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:21,代碼來源:fields.py

示例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 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:26,代碼來源:fields.py

示例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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:11,代碼來源:widgets.py

示例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 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:8,代碼來源:widgets.py

示例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 
開發者ID:ngageoint,項目名稱:scale,代碼行數:35,代碼來源:geospatial_utils.py

示例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 
開發者ID:bkg,項目名稱:django-spillway,代碼行數:14,代碼來源:serializers.py

示例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 
開發者ID:bkg,項目名稱:django-spillway,代碼行數:9,代碼來源:fields.py

示例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 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:55,代碼來源:validators.py


注:本文中的django.contrib.gis.geos.GEOSException方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。