本文整理匯總了Python中django.contrib.gis.gdal.feature.Feature方法的典型用法代碼示例。如果您正苦於以下問題:Python feature.Feature方法的具體用法?Python feature.Feature怎麽用?Python feature.Feature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.contrib.gis.gdal.feature
的用法示例。
在下文中一共展示了feature.Feature方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _make_feature
# 需要導入模塊: from django.contrib.gis.gdal import feature [as 別名]
# 或者: from django.contrib.gis.gdal.feature import Feature [as 別名]
def _make_feature(self, feat_id):
"""
Helper routine for __getitem__ that constructs a Feature from the given
Feature ID. If the OGR Layer does not support random-access reading,
then each feature of the layer will be incremented through until the
a Feature is found matching the given feature ID.
"""
if self._random_read:
# If the Layer supports random reading, return.
try:
return Feature(capi.get_feature(self.ptr, feat_id), self)
except GDALException:
pass
else:
# Random access isn't supported, have to increment through
# each feature until the given feature ID is encountered.
for feat in self:
if feat.fid == feat_id:
return feat
# Should have returned a Feature, raise an OGRIndexError.
raise OGRIndexError('Invalid feature id: %s.' % feat_id)
# #### Layer properties ####
示例2: _make_feature
# 需要導入模塊: from django.contrib.gis.gdal import feature [as 別名]
# 或者: from django.contrib.gis.gdal.feature import Feature [as 別名]
def _make_feature(self, feat_id):
"""
Helper routine for __getitem__ that constructs a Feature from the given
Feature ID. If the OGR Layer does not support random-access reading,
then each feature of the layer will be incremented through until the
a Feature is found matching the given feature ID.
"""
if self._random_read:
# If the Layer supports random reading, return.
try:
return Feature(capi.get_feature(self.ptr, feat_id), self)
except OGRException:
pass
else:
# Random access isn't supported, have to increment through
# each feature until the given feature ID is encountered.
for feat in self:
if feat.fid == feat_id: return feat
# Should have returned a Feature, raise an OGRIndexError.
raise OGRIndexError('Invalid feature id: %s.' % feat_id)
#### Layer properties ####
示例3: __getitem__
# 需要導入模塊: from django.contrib.gis.gdal import feature [as 別名]
# 或者: from django.contrib.gis.gdal.feature import Feature [as 別名]
def __getitem__(self, index):
"Gets the Feature at the specified index."
if isinstance(index, six.integer_types):
# An integer index was given -- we cannot do a check based on the
# number of features because the beginning and ending feature IDs
# are not guaranteed to be 0 and len(layer)-1, respectively.
if index < 0:
raise OGRIndexError('Negative indices are not allowed on OGR Layers.')
return self._make_feature(index)
elif isinstance(index, slice):
# A slice was given
start, stop, stride = index.indices(self.num_feat)
return [self._make_feature(fid) for fid in range(start, stop, stride)]
else:
raise TypeError('Integers and slices may only be used when indexing OGR Layers.')
示例4: __iter__
# 需要導入模塊: from django.contrib.gis.gdal import feature [as 別名]
# 或者: from django.contrib.gis.gdal.feature import Feature [as 別名]
def __iter__(self):
"Iterates over each Feature in the Layer."
# ResetReading() must be called before iteration is to begin.
capi.reset_reading(self._ptr)
for i in range(self.num_feat):
yield Feature(capi.get_next_feature(self._ptr), self)
示例5: get_fields
# 需要導入模塊: from django.contrib.gis.gdal import feature [as 別名]
# 或者: from django.contrib.gis.gdal.feature import Feature [as 別名]
def get_fields(self, field_name):
"""
Returns a list containing the given field name for every Feature
in the Layer.
"""
if field_name not in self.fields:
raise GDALException('invalid field name: %s' % field_name)
return [feat.get(field_name) for feat in self]
示例6: get_geoms
# 需要導入模塊: from django.contrib.gis.gdal import feature [as 別名]
# 或者: from django.contrib.gis.gdal.feature import Feature [as 別名]
def get_geoms(self, geos=False):
"""
Returns a list containing the OGRGeometry for every Feature in
the Layer.
"""
if geos:
from django.contrib.gis.geos import GEOSGeometry
return [GEOSGeometry(feat.geom.wkb) for feat in self]
else:
return [feat.geom for feat in self]