arcpy.Describe(lyr).shapeType
- Point
- Polyline
- Polygon
arcpy.Describe(lyr).FIDset
this will return the FID(s) of the selected feature(s)
len(arcpy.Describe(lyr).FIDset)
will return number of feature selected. if Zero, nothing is selected
if(len(arcpy.Describe(fc).FIDset)):
do_something()
arcpy.Exists(gdb)
return true or false
if not(arcpy.Exists(gdb)):
arcpy.CreatePersonalGDB_management(path, gdb)
arcpy.env.workspace = gdb_path
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
try:
arcpy.Delete_management(fc)
except:
pass
if selection is applied, only selected features will be copied/saved
arcpy.CopyFeatures_management(source_fc, new_fc, "", "0", "0", "0")
searchCur = arcpy.SearchCursor(source_fc)
inCur = arcpy.InsertCursor(target_fc)
for Row in searchCur:
inCur.insertRow(Row)
or use append - filed name matching may need to apply if needed
arcpy.Append_management([soure_lyaer], target_layer, "", "", "")
??
NEW_FIELD = "geo_len_km"
DATA_TYPE = "DOUBLE"
arcpy.AddField_management(fc, NEW_FIELD, DATA_TYPE, "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
Area and length calculations in Field calculator (python)
!shape.area@acres!
!shape.length@kilometers!
Geodesic Area and Length calculations in Field calculator (python)
!shape.geodesicArea@acres!
!shape.geodesicLength@kilometers!
Python script
# Calculate length in KM
arcpy.CalculateField_management(fc, "geo_len_km_", "!shape.length@kilometers!", "PYTHON", "")
# Calculate geodesic length in KM
arcpy.CalculateField_management(fc, "geo_len_km_", "!shape.geodesicLength@kilometers!", "PYTHON", "")
Areal unit of measure keywords:
ACRES | ARES | HECTARES | SQUARECENTIMETERS | SQUAREDECIMETERS | SQUAREINCHES | SQUAREFEET | SQUAREKILOMETERS | SQUAREMETERS | SQUAREMILES | SQUAREMILLIMETERS | SQUAREYARDS | SQUAREMAPUNITS | UNKNOWN
Linear unit of measure keywords:
CENTIMETERS | DECIMALDEGREES | DECIMETERS | FEET | INCHES | KILOMETERS | METERS | MILES | MILLIMETERS | NAUTICALMILES | POINTS | UNKNOWN | YARDS
arcpy.Describe(lyr).hasM
return true or false
arcpy.Describe(lyr).hasZ
return true or false
layer = arcpy.GetParameterAsText(0)
desc = arcpy.Describe(layer)
path = desc.path
layersource = str(path) + "/" + layer
Choose Python for language option
!shape!.firstPoint.X, !shape!.firstPoint.Y, !shape!.firstPoint.Z, !shape!.firstPoint.M
!shape!.lastPoint.X, !shape!.lastPoint.Y, !shape!.lastPoint.Z, !shape!.lastPoint.M
with arcpy.da.SearchCursor(infc, ["SHAPE@"]) as rows:
# Step through each row
for row in rows:
f = row[0]
# Step through each vertex in the feature
for v in f:
# get attribute of vertex
x = v.X
y = v.Y
z = v.Z
m = v.M
path = os.path.dirname(__file__)
len_unit = arcpy.GetParameterAsText(#)
geodesic_formula = {"Kilometers": "!shape.geodesicLength@kilometers!", "Miles":"!shape.geodesicLength@miles!"}
expression = geodesic_formula[len_unit]
field_name = "geo"+ len_unit
arcpy.AddField_management(tmp_layer, field_name, "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(tmp_layer, field_name, expression , "PYTHON", "")