0

Building a Script Tool that will take a selected polygon feature iterating through a 1 deg x 1 deg grid feature class. The tool creates a new geodatabase with name from [GEOCELL] field of selected feature (N34W107.gdb). This works.

I need to create a new GDB Feature Dataset with UTM of the selected feature. I'm not sure how to get the centroid of the selected feature x,y into arcpy.GetUTMFromLocation.

layer1x1 = arcpy.GetParameterAsText(0)
output = arcpy.GetParameterAsText(1)

with arcpy.da.SearchCursor(layer1x1, ['GEOCELL']) as geocell_cursor:
    for name in geocell_cursor:
        exp1 = "GEOCELL = '{}'".format(name[0])
        exp2 = "{}".format(name[0])
        gdbname = output + "/" + exp2 + ".gdb"
        
        arcpy.SelectLayerByAttribute_management(layer1x1, "NEW_SELECTION", exp1)
        
        arcpy.CreateFileGDB_management(output, exp2)

        utm = arcpy.GetUTMFromLocation(x, y)
        arcpy.CreateFeatureDataset_management(gdbname, "source_utm", utm)
        
        arcpy.SelectLayerByAttribute_management(layer1x1, "CLEAR_SELECTION")

1 Answer 1

0

I figured it out... added a SearchCursor for the selected feature layer row and centroid SHAPE@XY, and set row as the x, y variable. The creates a Feature Dataset with the correct UTM projection.

layer1x1 = arcpy.GetParameterAsText(0)
output = arcpy.GetParameterAsText(1)

with arcpy.da.SearchCursor(layer1x1, ['GEOCELL']) as geocell_cursor:
    for name in geocell_cursor:
        exp1 = "GEOCELL = '{}'".format(name[0])
        exp2 = "{}".format(name[0])
        gdbname = output + "/" + exp2 + ".gdb"
        
        arcpy.SelectLayerByAttribute_management(layer1x1, "NEW_SELECTION", exp1)
        
        for row in arcpy.da.SearchCursor(layer1x1, ["SHAPE@XY"]):
            x, y = row[0]
        
        utm = arcpy.GetUTMFromLocation(x, y)
        
        arcpy.CreateFileGDB_management(output, exp2)
        arcpy.CreateFeatureDataset_management(gdbname, "source_utm", utm)
        
        arcpy.SelectLayerByAttribute_management(layer1x1, "CLEAR_SELECTION")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.