ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

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

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS for Developers

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

ArcGIS Solutions

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

ArcGIS Marketplace

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

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

帮助

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • 更多...

将几何对象与地理处理工具配合使用

  • 使用几何作为输入
  • 输出几何对象

在许多地理处理工作流中,您可能需要使用坐标和几何信息运行特定操作,但不一定想经历创建新(临时)要素类、使用光标填充要素类、使用要素类,然后删除临时要素类的过程。可以使用几何对象替代输入和输出,从而使地理处理变得更简单。可以使用 Geometry、Multipoint、PointGeometry、Polygon 或 Polyline 类从头开始创建几何对象。

使用几何作为输入

以下示例使用一个 x,y 坐标列表创建了一个多边形几何对象。然后使用裁剪工具来裁剪具有多边形几何对象的要素类。

import arcpy

# Create an Array object.
#
array = arcpy.Array()

# List of coordinates.
#
coordinates = [[1.0, 1.0], [1.0, 10.0], [10.0, 10.0], [10.0, 1.0]]

# For each coordinate set, create a point object and add the x- and 
#   y-coordinates to the point object, then add the point object 
#   to the array object.
#
for x, y in coordinates:
    pnt = arcpy.Point(x, y)
    array.add(pnt)

# Add in the first point of the array again to close the polygon boundary
#
array.add(array.getObject(0))

# Create a polygon geometry object using the array object
#
boundary = arcpy.Polygon(array)

# Use the geometry to clip an input feature class
#
arcpy.Clip_analysis('c:/data/rivers.shp', boundary, 'c:/data/rivers_clipped.shp')

输出几何对象

可通过将地理处理工具的输出设置为空几何对象来创建输出几何对象。如果工具在设置为空几何对象后运行,该工具将返回几何对象的列表。在下面的示例中,复制要素工具用于返回几何对象的列表,然后可循环该列表以累积所有要素的总长度。

import arcpy

# Run the CopyFeatures tool, setting the output to a geometry object.  
#  geometries is returned as a list of geometry objects.
#  
geometries = arcpy.CopyFeatures_management('c:/temp/outlines.shp', arcpy.Geometry())

# Walk through each geometry, totaling the length
#
length = sum([g.length for g in geometries])

print('Total length: {}'.format(length))

相关主题

  • 使用游标访问数据
  • 使用 Python 指定查询
  • 读取几何
  • 写入几何

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

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