面朝大海,春暖华开

focus on scientific computue, 3dgis, spatial database
专注于科学计算、GIS空间分析

 

Using geometry objects with geoprocessing tools

Using geometry objects with geoprocessing tools

In many geoprocessing workflows, you may need to run a specific operation using coordinate and geometry information but don't necessarily want to go through the process of creating a new (temporary) feature class, populating the feature class with cursors, using the feature class, then deleting the temporary feature class. Geometry objects can be used instead for both input and output to make geoprocessing easier. Geometry objects can be created from scratch using Geometry, Multipoint, PointGeometry, Polygon, or Polyline classes.

Using geometry as input

The following sample creates a polygon geometry object created using a list of x,y coordinates. The Clip tool is then used to clip a feature class with the polygon geometry object.

import arcpy

 

# List of coordinates.

coordinates = [

    [2365000, 7355000],

    [2365000, 7455000],

    [2465000, 7455000],

    [2465000, 7355000]]

 

# Create an array with a point object for each coordinate pair

array = arcpy.Array([arcpy.Point(x, y) for x, y in coordinates])

 

# Create a polygon geometry object using the array object

boundary = arcpy.Polygon(array, arcpy.SpatialReference(2953))

 

# Use the geometry to clip an input feature class

arcpy.Clip_analysis('c:/data/rivers.shp', 

                    boundary, 

                    'c:/data/rivers_clipped.shp')

Outputting geometry objects

Output geometry objects can be created by setting the output of a geoprocessing tool to an empty geometry object. When a tool runs when set to an empty geometry object, the tool returns a list of geometry objects. In the following example, the Copy Features tool is used to return a list of geometry objects, which can then be looped through to accumulate the total length of all features.

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

posted on   风过 无痕  阅读(237)  评论(0编辑  收藏  举报

(评论功能已被禁用)
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

导航

统计

向日葵支付宝收钱码
点击右上角即可分享
微信分享提示