本文整理匯總了Python中qgis.core.QgsJSONExporter.includeAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsJSONExporter.includeAttributes方法的具體用法?Python QgsJSONExporter.includeAttributes怎麽用?Python QgsJSONExporter.includeAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.core.QgsJSONExporter
的用法示例。
在下文中一共展示了QgsJSONExporter.includeAttributes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testJSONExporter
# 需要導入模塊: from qgis.core import QgsJSONExporter [as 別名]
# 或者: from qgis.core.QgsJSONExporter import includeAttributes [as 別名]
#.........這裏部分代碼省略.........
exporter.setAttributes([1, 2])
exporter.setExcludedAttributes([0, 1])
expected = """{
"type":"Feature",
"id":5,
"geometry":
{"type": "Point", "coordinates": [5, 6]},
"properties":{
"population":198
}
}"""
self.assertEqual(exporter.exportFeature(feature), expected)
exporter.setAttributes([])
exporter.setExcludedAttributes([])
# test excluding geometry
exporter.setIncludeGeometry(False)
self.assertEqual(exporter.includeGeometry(), False)
feature.setGeometry(QgsGeometry(QgsLineString(l)))
expected = """{
"type":"Feature",
"id":5,
"geometry":null,
"properties":{
"name":"Valsier Peninsula",
"cost":6.8,
"population":198
}
}"""
self.assertEqual(exporter.exportFeature(feature), expected)
exporter.setIncludeGeometry(True)
feature.setGeometry(QgsGeometry(QgsPointV2(5, 6)))
# test excluding attributes
exporter.setIncludeAttributes(False)
self.assertEqual(exporter.includeAttributes(), False)
expected = """{
"type":"Feature",
"id":5,
"geometry":
{"type": "Point", "coordinates": [5, 6]},
"properties":null
}"""
self.assertEqual(exporter.exportFeature(feature), expected)
exporter.setIncludeGeometry(False)
expected = """{
"type":"Feature",
"id":5,
"geometry":null,
"properties":null
}"""
self.assertEqual(exporter.exportFeature(feature), expected)
exporter.setIncludeAttributes(True)
# test overriding ID
expected = """{
"type":"Feature",
"id":29,
"geometry":null,
"properties":{
"name":"Valsier Peninsula",
"cost":6.8,
"population":198
}
}"""
self.assertEqual(exporter.exportFeature(feature, id=29), expected)
# test injecting extra attributes
expected = """{
"type":"Feature",
"id":5,
"geometry":null,
"properties":{
"name":"Valsier Peninsula",
"cost":6.8,
"population":198,
"extra":"val1",
"extra2":2
}
}"""
self.assertEqual(exporter.exportFeature(feature, extraProperties={"extra": "val1", "extra2": 2}), expected)
exporter.setIncludeAttributes(False)
expected = """{
"type":"Feature",
"id":5,
"geometry":null,
"properties":{
"extra":"val1",
"extra2":{"nested_map":5,
"nested_map2":"val"},
"extra3":[1,2,3]
}
}"""
self.assertEqual(exporter.exportFeature(feature, extraProperties={"extra": "val1", "extra2": {"nested_map": 5, "nested_map2": "val"}, "extra3": [1, 2, 3]}), expected)
exporter.setIncludeGeometry(True)