# AsShape (arcpy)

## 语法

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 对象的几何对象（PointGeometry、Multipoint、Polyline 或 Polygon） 或 esriJSON 对象。 import arcpy gjPoint = {"type": "Point", "coordinates": [5.0, 5.0]} ptGeometry = arcpy.AsShape(gjPoint)

## 代码实例

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

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)

import arcpy
gjMultiPoint = {
"type": "MultiPoint",
"coordinates": [[5.0, 4.0], [8.0, 7.0]]}
multiPoint = arcpy.AsShape(gjMultiPoint)

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)

import arcpy
gjLineString = {
"type": "LineString",
"coordinates": [[5.0, 4.0], [8.0, 7.0]]}
polyLine = arcpy.AsShape(gjLineString)

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)

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)

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)

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