当前位置: 首页>>代码示例>>Python>>正文


Python QgsJSONUtils.encodeValue方法代码示例

本文整理汇总了Python中qgis.core.QgsJSONUtils.encodeValue方法的典型用法代码示例。如果您正苦于以下问题:Python QgsJSONUtils.encodeValue方法的具体用法?Python QgsJSONUtils.encodeValue怎么用?Python QgsJSONUtils.encodeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core.QgsJSONUtils的用法示例。


在下文中一共展示了QgsJSONUtils.encodeValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testEncodeValue

# 需要导入模块: from qgis.core import QgsJSONUtils [as 别名]
# 或者: from qgis.core.QgsJSONUtils import encodeValue [as 别名]
 def testEncodeValue(self):
     """ test encoding various values for use in GeoJSON strings """
     self.assertEqual(QgsJSONUtils.encodeValue(NULL), "null")
     self.assertEqual(QgsJSONUtils.encodeValue(5), "5")
     self.assertEqual(QgsJSONUtils.encodeValue(5.9), "5.9")
     self.assertEqual(QgsJSONUtils.encodeValue(5999999999), "5999999999")
     self.assertEqual(QgsJSONUtils.encodeValue("string"), '"string"')
     self.assertEqual(QgsJSONUtils.encodeValue("str\ning"), '"str\\ning"')
     self.assertEqual(QgsJSONUtils.encodeValue("str\ring"), '"str\\ring"')
     self.assertEqual(QgsJSONUtils.encodeValue("str\bing"), '"str\\bing"')
     self.assertEqual(QgsJSONUtils.encodeValue("str\ting"), '"str\\ting"')
     self.assertEqual(QgsJSONUtils.encodeValue("str\\ing"), '"str\\\\ing"')
     self.assertEqual(QgsJSONUtils.encodeValue("str\\ning"), '"str\\\\ning"')
     self.assertEqual(QgsJSONUtils.encodeValue("str\n\\\\ing"), '"str\\n\\\\\\\\ing"')
     self.assertEqual(QgsJSONUtils.encodeValue("str/ing"), '"str\\/ing"')
     self.assertEqual(QgsJSONUtils.encodeValue([5, 6]), "[5,6]")
     self.assertEqual(QgsJSONUtils.encodeValue(["a", "b", "c"]), '["a","b","c"]')
     self.assertEqual(QgsJSONUtils.encodeValue(["a", 3, "c"]), '["a",3,"c"]')
     self.assertEqual(QgsJSONUtils.encodeValue(["a", "c\nd"]), '["a","c\\nd"]')
     self.assertEqual(QgsJSONUtils.encodeValue({"key": "value", "key2": 5}), '{"key":"value",\n"key2":5}')
     self.assertEqual(
         QgsJSONUtils.encodeValue({"key": [1, 2, 3], "key2": {"nested": "nested\\result"}}),
         '{"key":[1,2,3],\n"key2":{"nested":"nested\\\\result"}}',
     )
开发者ID:mbernasocchi,项目名称:QGIS,代码行数:26,代码来源:test_qgsjsonutils.py

示例2: print

# 需要导入模块: from qgis.core import QgsJSONUtils [as 别名]
# 或者: from qgis.core.QgsJSONUtils import encodeValue [as 别名]
from qgis.utils import iface

geojson_contributors = os.path.join(
    os.path.dirname(QgsApplication.developersMapFilePath()),
    'contributors.json'
)
geojson_contributors_string = codecs.open(
    geojson_contributors,
    encoding='utf-8'
).read()

layer = iface.activeLayer()

# Encodes a value to a JSON string representation, adding appropriate
# quotations and escaping where required.
print(QgsJSONUtils.encodeValue([{"name": "George", "age": 34, "size": 1.69}]))

fields = QgsFields()
fields_list = [
    QgsField("name", QVariant.String),
    QgsField("age", QVariant.Int),
    QgsField("size", QVariant.Double)
]

for f in fields_list:
    fields.append(f)

feature = QgsFeature(fields)
feature.setGeometry(QgsGeometry.fromPoint(QgsPoint(60, 5)))
feature.setAttributes(["George", 34, 1.69])
开发者ID:GEO-IASS,项目名称:pyqgis-samples,代码行数:32,代码来源:qgis-sample-QgsJSONUtils.py


注:本文中的qgis.core.QgsJSONUtils.encodeValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。