Arcpy Snippets
This snippet helps to access the arcpy library snippets and write the code faster
| Syntax |
Tool |
| aew |
arcpy.env.workspace |
| pv |
parameters[0].value |
| pvt |
parameters[0].valueAsText |
| af |
arcpy.management.AddField |
| afm |
arcpy.management.AddFields |
| am |
arcpy.AddMessage |
| cf |
arcpy.management.CopyFeatures |
| df |
arcpy.management.DeleteField |
| sba |
arcpy.management.SelectLayerByAttribute |
| sbl |
arcpy.management.SelectLayerByLocation |
| para |
arcpy.Parameter |
| sc |
arcpy.da.SearchCursor |
| ic |
arcpy.da.InsertCursor |
| uc |
arcpy.da.UpdateCursor |
| sj |
arcpy.analysis.SpatialJoin |
| cga |
arcpy.management.CalculateGeometryAttributes |
| ca |
arcpy.analysis.Clip |
| sa |
arcpy.analysis.Select |
| lfl |
list field names in list |
| ct |
arcpy.management.CreateTable |
| toolbox |
ArcToolBox Template |
| tool |
Tool class template |
| field types |
TEXT,LONG,DOUBLE,FLOAT,SHORT,DATE,GUID,BLOB |
arcpy.management.AddField(in_table, field_name, field_type)
Add Message
arcpy.AddMessage(MESSAGE)
arcpy.management.CopyFeatures(in_features, out_feature_class)
arcpy.management.DeleteField(in_table, drop_field, 'DELETE_FIELDS|KEEP_FIELDS')
arcpy.management.SelectLayerByAttribute(in_layer_or_view, {selection_type}, {where_clause}, {invert_where_clause})
arcpy.management.SelectLayerByLocation(in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type}, {invert_spatial_relationship})
arcpy.Parameter ({name}, {displayName}, {direction}, {datatype}, {parameterType}, {enabled}, {category}, {symbology}, {multiValue})
NAME = arcpy.Parameter(
displayName = DISPLAY_NAME
name = NAME
datatype = DATA_TYPE
parameterType = Optional|Required
direction = Input|Output
)
SearchCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause}, {datum_transformation})
# Snippet
layer = ''
fields = ['']
with arcpy.da.SearchCursor(layer, fields) as cursor:
for row in cursor:
trow[] =
InsertCursor (in_table, field_names, datum_transformation)
# Snippet
fields = ['']
cursor = arcpy.da.InsertCursor('', fields)
cursor.insertRow(('row'))
del cursor
UpdateCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause}, {datum_transformation})
#Snippet
fc = #Feature name
fields = ['field_name']
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
row[index] =
cursor.updateRow(row)
arcpy.analysis.SpatialJoin(target_features, join_features, out_feature_class)
arcpy.management.CalculateGeometryAttributes(in_features, geometry_property)
arcpy.analysis.Clip(in_features, clip_features, out_feature_class)
arcpy.analysis.Select(in_features, out_feature_class)
List Fields
data = [f.name for f in arcpy.ListFields(field_name)]