ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

AsShape

  • 描述
  • 讨论
  • 语法
  • 代码示例

描述

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

讨论

注:

AsShape 不支持 GeoJSON 坐标参考系对象;通过 GeoJSON 创建的几何对象的空间参考将为未知。

语法

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

使用 GeoJSON 对象创建 PointGeometry 对象。

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

使用 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
point = arcpy.AsShape(esri_json, True)
AsShape 示例 3

使用 GeoJSON 对象创建 Multipoint 对象。

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

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

使用 GeoJSON 对象创建 Polyline 对象。

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

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

使用 GeoJSON 对象创建多部分 Polyline 对象。

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

使用 GeoJSON 对象创建 Polygon 对象。

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

使用 GeoJSON 对象创建包含孔对象的 Polygon 对象。

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)

相关主题

  • FromWKB
  • FromWKT

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2021 Esri. | 隐私政策 | 法律声明