Consider a Feature Class (part of an Enterprise GDB content) and two of its fields are "UTM_grid" and the "OID".
Scripting with python 2.7 for ArcGIS 10.3.
"UTM_grid" field was broken down into "UTM_block" + "UTM_sheet" and then using a dictionary and list structure UTM_block-->UTM_sheet-->OID was organized with this syntax:
{ 'UTM_block_1' : { 'UTM_sheet_A' : [ oid_1 , oid_2 ] }, { UTM_sheet_2 : [ oid_3 , oid_4, oid_5 ] } }
We need to create **shapefiles** with features (identified by the object value - oid) based on the follow data structure (OIDs will be organized regarding an UTM/location based structure):
- UTM_block_* will be a folder
- UTM-sheet_* its subfolder.
- List of objects (OIDs) will populate the shapefile.
---
Another point we have to deal with is that the shapefile should only have some fields of the original Feature Class:
We have used fieldmappings and arcpy.FeatureClassToFeatureClass_conversion() to create a non-UTM-organized shapefile from a Feature Class with the fields that we need.
---
Now the problem is how to process the **feature export** to get UTM-organized shapefiles! How can we manage it?
Bellow is what we have now inside a function:
with arcpy.da.SearchCursor(feature_class, ['UTM_grid , 'OBJECTID']) as cursor:
dic = dict()
for row in cursor:
UTM_grid_value = row[0]
oid_value = row[1]
try:
b_s_split = UTM_grid_value.split('_') # split into block & sheet
except Exception, e:
pass
print(UTM_grid_value)
print(e)
else:
# create folders & subfolders (blocks & sheets) in a directory
dic.setdefault( b_s_split[0], {} ).setdefault( b_s_split[1], [] ).append( oid_value )
dir_path = os.path.dirname("E:\\") # full path to directory
dirs = [ [b_s_split[0]] , [b_s_split[1]] ]
for item in itertools.product(*dirs):
if not os.path.isdir(os.path.join(dir_path, *item)):
os.makedirs(os.path.join(dir_path, *item))