There must be a better way to do this. I am joining a parcel feature class to flood zones and to surge zones. I do not like that with a spatial join if two join features with the same code both intersect a parcel the parcel will have duplicate values, i.e. '1,2,1,1,3.' Below is the way I figured to do it but with two selections and a calculation per iteration Im looking at about 8 minutes per iteration. Except flood zone X and surge zone 1, those are about 33 minutes and 17 minutes respectively. The reason I do it this way is so the formatting is nice looking in the field. The only other way I can think of is to do a spatial join and then cursor over the field splitting the value into a list, making the list a set, sorting the set and then writing it back to the field. Due to field length some values might get truncated during the spatial join and be lost. I dont have a time on doing it that way but I cant imagine it would be too much more efficient.
arcpy.MakeFeatureLayer_management(r'\\Bay-gis\GIS Staff\Parcel_Processor\OSA@sde@bay-gis.sde\sde.SDE.ReferencedData\sde.SDE.Flood_Zones_2009','FloodZones','FLD_ZONE <> \'0.2 PCT ANNUAL CHANCE FLOOD HAZARD\' AND FLD_ZONE <> \'OPEN WATER\'')
for zone in ['A','AE','VE','X']:
query="FLD_ZONE = '%s'"%zone
arcpy.SelectLayerByAttribute_management('FloodZones','NEW_SELECTION',query)
arcpy.SelectLayerByLocation_management('parcels','INTERSECT','FloodZones')
cursor=arcpy.UpdateCursor('parcels')
for row in cursor:
if row.Flood_zn==None:
row.Flood_zn=zone
else:
row.Flood_zn=row.Flood_zn+',%s'%zone
cursor.updateRow(row)
del cursor
arcpy.MakeFeatureLayer_management(r'\\Bay-gis\GIS Staff\Parcel_Processor\OSA@sde@bay-gis.sde\sde.SDE.ReferencedData\sde.SDE.Storm_Surge','StormSurge')
for zone in ['1','2','3','4','5']:
query="Cat = '%s'"%zone
arcpy.SelectLayerByAttribute_management('StormSurge','NEW_SELECTION',query)
arcpy.SelectLayerByLocation_management('parcels','INTERSECT','StormSurge')
cursor=arcpy.UpdateCursor('parcels')
for row in cursor:
if row.Surge==None:
row.Surge=zone
else:
row.Surge=row.Surge+',%s'%zone
cursor.updateRow(row)
del cursor