[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}")
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2020-09-25 【484】Book - Deep Learning with Python 相关说明与代码