-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup_segmentations_part_2.py
65 lines (45 loc) · 2.35 KB
/
group_segmentations_part_2.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
## group segmentation files
## colin stief
## february 18, 2016
import arcpy, csv, os
### Running counts
j = 1
### Files and Folders
county = "Tioga"
workspace = "\\\\CCSVR01\\EastWalk\\Segmentation"
segmentation_folder = os.path.join(workspace, county)
geodatabase_name = county + ".gdb"
geodatabase = os.path.join(workspace, geodatabase_name)
grid_file = os.path.join(workspace, geodatabase_name, "Fishnet")
grid_layer = arcpy.MakeFeatureLayer_management(grid_file, "grid_layer")
### Procedure
complete_merge = os.path.join(geodatabase, "Complete_Merge")
complete_merge_layer = arcpy.MakeFeatureLayer_management(complete_merge, "complete_merge_layer")
with arcpy.da.SearchCursor(grid_file, ("OID@")) as cursor:
for row in cursor:
current_group_list = []
sql = "OID = " + str(row[0])
arcpy.SelectLayerByAttribute_management(grid_layer,"NEW_SELECTION", sql)
current_cell = arcpy.MakeFeatureLayer_management(grid_layer, "current_cell")
arcpy.SelectLayerByLocation_management(complete_merge_layer, "HAVE_THEIR_CENTER_IN", current_cell, "", "NEW_SELECTION")
with arcpy.da.SearchCursor(complete_merge_layer, "file_name") as innerCursor:
for innerRow in innerCursor:
current_file_name = innerRow[0] + ".shp"
current_file_path = os.path.join(segmentation_folder, current_file_name)
current_group_list.append(current_file_path)
if len(current_group_list) > 0:
current_group_name = "Group_" + str(j)
current_group_layer = os.path.join(geodatabase, current_group_name)
current_group_footprint_name = current_group_name + "_Footprint"
current_group_footprint = os.path.join(geodatabase, current_group_footprint_name)
field_map = arcpy.FieldMappings()
for part in current_group_list:
field_map.addTable(part)
for field in field_map.fields:
if field.name not in ["REGION_ID"]:
field_map.removeFieldMap(field_map.findFieldMapIndex(field.name))
arcpy.Merge_management(current_group_list, current_group_layer, field_map)
#arcpy.Dissolve_management(current_group_layer, current_group_footprint)
print "Added Group " + str(j) + " to the geodatabase."
j += 1
arcpy.Delete_management(current_cell)