-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrab-attributes-from-point-vector-unique.py
47 lines (32 loc) · 1.37 KB
/
grab-attributes-from-point-vector-unique.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
__author__ = 'Colin'
import arcpy
arcpy.env.overwriteOutput = True
parcel_file = "\\\\Ccsvr01\\d\\GIS\\PG_County\\Fields.gdb\\Parcels_Gaps"
parcel_layer = arcpy.MakeFeatureLayer_management(parcel_file, "parcel_layer")
# EDIT 1
chop_file = "\\\\Ccsvr01\\d\\GIS\\PG_County\\CleanDatasets\\storm_drain_inventory\\Pipes_Dissolve_SD_Size_Type.shp"
chop_layer = arcpy.MakeFeatureLayer_management(chop_file, "chop_layer")
# EDIT 2
field = "SD_T_S1_S2"
# EDIT 3
fields = ["SD_T_S1_S2"]
uniquePipes = set([row.getValue(field) for row in arcpy.SearchCursor(chop_layer)])
for pipe in uniquePipes:
value_raw = pipe
sql = field + " = " + "'" + value_raw + "'"
arcpy.AddMessage(sql)
arcpy.SelectLayerByAttribute_management(chop_layer,"NEW_SELECTION", sql)
current_chop_layer = arcpy.MakeFeatureLayer_management(chop_layer, "current_chop_layer")
arcpy.SelectLayerByLocation_management(parcel_layer, "INTERSECT", current_chop_layer, "", "NEW_SELECTION")
codeblock = """def grabValue(existingValue):
if existingValue != "NA":
newValue = existingValue + ", " + "%s"
return newValue
else:
newValue = "%s"
return newValue
""" % (value_raw, value_raw)
# EDIT 4
expression = "grabValue(!PipeType!)"
# EDIT 5
arcpy.CalculateField_management(parcel_layer, "PipeType", expression, "Python", codeblock)