# AsShape

## 语法

`AsShape (geojson_struct, {esri_json})`
 参数 说明 数据类型 geojson_struct geojson_struct 包括 type 和 coordinates。 包含 type 的以下字符串：Point、LineString、Polygon、MultiPoint 和 MultiLineString。 Dictionary esri_json 指定将输入 JSON 作为 Esri JSON 评估还是作为 GeoJSON 评估。如果为 True，则将输入作为 Esri JSON 评估。 (默认值为 False) Boolean

 数据类型 说明 Geometry AsShape 将基于输入 GeoJSON 或 Esri JSON 对象返回几何对象（PointGeometry、Multipoint、Polyline 或 Polygon）。 ``````import arcpy geojson_point = {"type": "Point", "coordinates": [5.0, 5.0]} point = arcpy.AsShape(geojson_point)`````` 如果 Esri JSON 是要素集，AsShape 将返回 FeatureSet。ArcGIS REST API 规范将要素集定义为具有特定几何类型、字段和空间参考的要素集合。JSON 转要素工具可用于将 Esri JSON 直接转换为要素类。

## 代码示例

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)``````