alex_bn_lee

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

[886] Some useful functions in ArcPy

Exists: Determines the existence of the specified data object. This function tests for the existence of various data types including feature classes, tables, datasets, shapefiles, workspaces, layers, and files. The function returns a Boolean indicating whether the element exists.

查看代码
 import arcpy
arcpy.env.workspace = r'C:\Path\to\Your\Geodatabase.gdb' # Replace with the actual workspace path
feature_class_name = 'YourFeatureClass' # Replace with the actual feature class name
if arcpy.Exists(feature_class_name):
print(f"The feature class '{feature_class_name}' exists.")
else:
print(f"The feature class '{feature_class_name}' does not exist.")

Create File Geodatabase (Data Management): Creates a file geodatabase in a folder.

查看代码
 import arcpy
arcpy.env.workspace = r'C:\Path\to\Your\Folder'
geodatabase_name = 'YourGeodatabase.gdb' # Replace with your desired geodatabase name
arcpy.CreateFileGDB_management(arcpy.env.workspace, geodatabase_name)

ListFeatureClasses: Returns a list of the feature classes in the current workspace, limited by name, feature type, and optional feature dataset.

查看代码
 import arcpy
arcpy.env.workspace = r"C:\path\to\your\geodatabase.gdb"
feature_classes = arcpy.ListFeatureClasses()

Merge (Data Management): Combines multiple input datasets into a single, new output dataset. This tool can combine point, line, or polygon feature classes or tables.

Clip (Analysis): Extracts input features that overlay the clip features.

Multiple Ring Buffer (Analysis): Creates multiple buffers at specified distances around the input features. These buffers can be merged and dissolved using the buffer distance values to create non-overlapping buffers.

SearchCursor: Establishes read-only access to the records of a feature class or table. It returns an iterator of tuples. The order of values in the tuple matches the order of fields specified by the field_names argument.

查看代码
 import arcpy
arcpy.env.workspace = r'C:\Path\to\Your\Workspace'
shapefile_name = 'your_shapefile.shp' # Replace with the actual shapefile name
with arcpy.da.SearchCursor(shapefile_name, ['SHAPE@', 'FIELD1', 'FIELD2']) as cursor:
for row in cursor:
geometry = row[0] # Access the geometry of the feature
field1_value = row[1] # Access the value of FIELD1
field2_value = row[2] # Access the value of FIELD2
print(f"Geometry: {geometry}, FIELD1: {field1_value}, FIELD2: {field2_value}")

 

posted on   McDelfino  阅读(8)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-09-25 【484】Book - Deep Learning with Python 相关说明与代码
点击右上角即可分享
微信分享提示