mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Add __geo_interface__ to QgsFeature and QgsGeometry
This commit is contained in:
parent
770feee4f5
commit
c55c2ab82f
@ -24,6 +24,7 @@ __copyright__ = '(C) 2007, Martin Dobias'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import sip
|
||||
from qgis.core import QgsFeature, QgsGeometry
|
||||
|
||||
try:
|
||||
apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
|
||||
@ -64,3 +65,23 @@ try:
|
||||
core.NULL = QPyNullVariant( int )
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def mapping_feature(feature):
|
||||
geom = feature.geometry()
|
||||
properties = {}
|
||||
fields = [field.name() for field in feature.fields()]
|
||||
properties = dict(zip(fields, feature.attributes()))
|
||||
return {
|
||||
'type' : 'Feature',
|
||||
'properties' : properties,
|
||||
'geometry' : geom.__geo_interface__}
|
||||
|
||||
def mapping_geometry(geometry):
|
||||
geo = geometry.exportToGeoJSON()
|
||||
# We have to use eval because exportToGeoJSON() gives us
|
||||
# back a string that looks like a dictionary.
|
||||
return eval(geo)
|
||||
|
||||
QgsFeature.__geo_interface__ = property(mapping_feature)
|
||||
QgsGeometry.__geo_interface__ = property(mapping_geometry)
|
||||
|
Loading…
x
Reference in New Issue
Block a user