AsShape (arcpy)

讨论

AsShape 不支持 GeoJSON 坐标参考系对象；通过 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 Sets whether the input JSON is evaluated as Esri JSON or GeoJSON. If True, the input is evaluated as Esri JSON.(默认值为 False) Boolean

 数据类型 说明 Geometry AsShape 基于输入 GeoJSON 返回几何对象（PointGeometry、Multipoint、Polyline 或 Polygon）。 或 esriJSON 对象。 ``````import arcpy geojson_point = {"type": "Point", "coordinates": [5.0, 5.0]} point = arcpy.AsShape(geojson_point) ``````

代码实例

AsShape 示例 1

``````import arcpy

geojson_point = {
"type": "Point",
"coordinates": [5.0, 5.0]}
point = arcpy.AsShape(geojson_point)
``````
AsShape 示例 2

``````import arcpy

esri_json = {
"x": -122.65,
"y": 45.53,
"spatialReference": {
"wkid": 4326}}
# Set the second parameter to True to use an esri JSON
point = arcpy.AsShape(esri_json, True)
``````
AsShape 示例 3

``````import arcpy

geojson_multipoint = {
"type": "MultiPoint",
"coordinates": [[5.0, 4.0], [8.0, 7.0]]}
multipoint = arcpy.AsShape(geojson_multipoint)
``````
AsShape 示例 4

``````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)
``````
AsShape 示例 5

``````import arcpy

geojson_linestring = {
"type": "LineString",
"coordinates": [[5.0, 4.0], [8.0, 7.0]]}
polyline = arcpy.AsShape(geojson_linestring)
``````
AsShape 示例 6

``````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)
``````
AsShape 示例 7

``````import arcpy

geojson_multilinestring = {
"type": "MultiLineString",
"coordinates": [
[[5.0, 4.0], [8.0, 7.0]],
[[4.0, 5.0], [7.0, 8.0]]]}
polyline = arcpy.AsShape(geojson_multilinestring)
``````
AsShape 示例 8

``````import arcpy

geojson_polygon = {
"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(geojson_polygon)
``````
AsShape 示例 9

``````import arcpy

geojson_polygon = {
"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]]]}
polygon = arcpy.AsShape(geojson_polygon)
``````

5/10/2014