What I am trying to do is to have create a list of unique TAZs from the data already selected and iterate over that list and subselect all the rows that have that taz then check if they have the
Exclude identifier in the Exclude field, if so then remove 1 from the number of points else don't, have that iterate until there are no more values left in the list,
I tried inputting the below code into a Chat bot and it came out with the second code block however
it produces an error provided and don't know if the syntax is right as I only started learning Python and SQL yesterday, could someone help me figure out how to do this?
What I Gave
import arcpy
#geoprocesing layer creation
#repair the geometry
arcpy.management.RepairGeometry('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'KEEP_NULL')
print("fetures repaired")
#create points
arcpy.management.FeatureToPoint('USE_real_master_Martin_County_3_10_23_TAZ_CRA','PointsWithin', 'INSIDE')
print("points layer created")
#Summarize points and feture layer
arcpy.analysis.SummarizeWithin('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'PointsWithin','SummerizedPoints')
print("SummerizedPoints created")
#selections and calulations of the data
# add calculation field
arcpy.management.AddField('SummerizedPoints','Area_Per_Point', 'DOUBLE')
print("Area_Per_Point feild created")
#cleaning data
#selection of all the condos
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'NEW_SELECTION', 'Point_Count > 2')
#obtain list of TAZs
code goes here
#loop through the list of TAZ's selecting each group of same TAZ each time
for value < count of unique TAZ's; value++
{
#select the current value of TAZ
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', 'TAZ_REG = TAZ_REG.value')
if ("Exclude = 'Exclude'"){
#remove excluded
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'REMOVE_FROM_SELECTION', "Exclude = 'Exclude'")
#calculate the area of each point if excluded
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count! - 1)', 'PYTHON3')
}
#if there are not any excludes
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count!)', 'PYTHON3')
}
print("calculations compleate")
#clear out slection
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'CLEAR_SELECTION')
print("Program Done")
Chat Bot
import arcpy
#geoprocesing layer creation
#repair the geometry
arcpy.management.RepairGeometry('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'KEEP_NULL')
print("fetures repaired")
#create points
arcpy.management.FeatureToPoint('USE_real_master_Martin_County_3_10_23_TAZ_CRA','PointsWithin', 'INSIDE')
print("points layer created")
#Summarize points and feture layer
arcpy.analysis.SummarizeWithin('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'PointsWithin','SummerizedPoints')
print("SummerizedPoints created")
#selections and calulations of the data
# add calculation field
arcpy.management.AddField('SummerizedPoints','Area_Per_Point', 'DOUBLE')
print("Area_Per_Point feild created")
#cleaning data
#selection of all the condos
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'NEW_SELECTION', 'Point_Count > 2')
# Obtain list of TAZs
unique_taz_values = []
with arcpy.da.SearchCursor('SummerizedPoints', 'TAZ_REG') as cursor:
for row in cursor:
if row[0] not in unique_taz_values:
unique_taz_values.append(row[0])
# Loop through the list of TAZs, selecting each group of the same TAZ each time
for taz_value in unique_taz_values:
#select the current value of TAZ
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', 'TAZ_REG = TAZ_REG.value')
if ("Exclude = 'Exclude'"):
#remove excluded
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'REMOVE_FROM_SELECTION', "Exclude = 'Exclude'")
#calculate the area of each point if excluded
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count! - 1)', 'PYTHON3')
else:
#if there are not any excludes
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count!)', 'PYTHON3')
print("calculations compleate")
#clear out slection
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'CLEAR_SELECTION')
print("Program Done")
Error Given
Traceback (most recent call last):
File "<string>", line 12, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 11294, in SelectLayerByAttribute
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 11291, in SelectLayerByAttribute
retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 160144: An expected Field was not found or could not be retrieved properly.
Failed to execute (SelectLayerByAttribute).