AsShape (arcpy)

摘要

将 Esri JSON 或 GeoJSON 转换为 ArcPy 几何对象。GeoJSON 是地理空间数据交换格式,可用于对地理数据结构进行编码。

语法

AsShape (geojson_struct, {esri_json})
参数说明数据类型
geojson_struct

The geojson_struct includes type and coordinates.

The following strings are included for type: Point, LineString, Polygon, MultiPoint, and MultiLineString.

Dictionary
esri_json

The esri_json geometry properties and spatial reference.

The properties for geometry include points, paths, rings. The Following geometry types are supported: Point, Polyline, Polygon, multipart features and Feature Set, and Record Set.

(默认值为 False)

Boolean
返回值
数据类型说明
Geometry

AsShape 返回基于输入 GeoJSON 对象的几何对象(PointGeometryMultipointPolylinePolygon) 或 esriJSON 对象。

import arcpy
gjPoint = {"type": "Point", "coordinates": [5.0, 5.0]}
ptGeometry = arcpy.AsShape(gjPoint)

代码实例

使用 GeoJSON 对象创建 PointGeometry 对象。
import arcpy
gjPoint = {"type": "Point", "coordinates": [5.0, 5.0]}
ptGeometry = arcpy.AsShape(gjPoint)
使用 Esri JSON 对象创建 PointGeometry 对象。
import arcpy
esri_json = {"x": -122.65, "y": 45.53, "spatialReference": {"wkid": 4326}}
# Set the second parameter to True to use an esri JSON
ptGeometry = arcpy.AsShape(esri_json, True)
使用 GeoJSON 对象创建 Multipoint 对象。
import arcpy
gjMultiPoint = {
    "type": "MultiPoint",
    "coordinates": [[5.0, 4.0], [8.0, 7.0]]}
multiPoint = arcpy.AsShape(gjMultiPoint)
使用 Esri JSON 对象创建 Multipoint 对象。
import arcpy
esri_json = {
    "points" : [
        [-97.06138, 32.837],
        [-97.06133, 32.836],
        [-97.06124, 32.834],
        [-97.06127, 32.832]],
    "spatialReference" : {"wkid" : 4326}}
# Set the second parameter to True to use an esri JSON
multiPoint = arcpy.AsShape(esri_json, True)
使用 GeoJSON 对象创建 Polyline 对象。
import arcpy
gjLineString = {
    "type": "LineString",
    "coordinates": [[5.0, 4.0], [8.0, 7.0]]}
polyLine = arcpy.AsShape(gjLineString)
使用 Esri JSON 对象创建 Polyline 对象。
import arcpy
esri_json = {
    "paths" : [
        [[-97.08, 32.8], [-97.05, 32.6], [-97.06, 32.7], [-97.07, 32.6]],
        [[-97.4, 32.5], [-97.2, 32.75]]],
    "spatialReference" : {"wkid" : 4326}}
# Set the second parameter to True to use an esri JSON
polyLine = arcpy.AsShape(esri_json, True)
使用 GeoJSON 对象创建多部分 Polyline 对象。
import arcpy
gjMultiLineString = {
    "type": "MultiLineString",
    "coordinates": [
        [[5.0, 4.0], [8.0, 7.0]],
        [[4.0, 5.0], [7.0, 8.0]]]}
mpPolyLine = arcpy.AsShape(gjMultiLineString)
使用 GeoJSON 对象创建 Polygon 对象。
import arcpy
gjPolygon = {
    "type": "Polygon",
    "coordinates": [
        [[10.0, 0.0], [20.0, 0.0], [20.0, 10.0], [10.0, 10.0], [10.0, 0.0]]]}
polygon = arcpy.AsShape(gjPolygon)
使用 GeoJSON 对象创建包含孔对象的 Polygon 对象。
import arcpy
gjPolygonWithHole = {
    "type": "Polygon",
    "coordinates": [
        [[10.0, 0.0], [20.0, 0.0], [20.0, 10.0], [10.0, 10.0], [10.0, 0.0]],
        [[12.0, 2.0], [18.0, 2.0], [18.0,  8.0], [12.0,  8.0], [12.0, 2.0]]]}
polygonWithHole = arcpy.AsShape(gjPolygonWithHole)

相关主题

9/15/2013