Create hydrology layers for each state with arcpy

08-24-2021 12:10 AM
New Contributor III

Hi everyone,


I am trying to change my script to loop through the State_Boundary layer and do the below geoprocessing tool for all states in Australia. the results should be hydrology layer for each states which clipped based on properties layer. How can I change this to create only *_Hydrology  layer and delete rest of layers? At the moment I need to change the name of states, inputs and outputs!

Hydrology=r"V:\Hydro\Data\NSW_HYDRO_LINE_shp.shp"  All hydrology layers saved in one folder but divided by states.



#1. Import system modules
import arcpy
arcpy.env.overwriteOutput= True

#2. set environmnet setting
arcpy.env.workspace =r"R:\R\Data\Buffer_States.gdb"

#3. Seprate a state from State_Boundary layer
arcpy.analysis.Select(FC_BoundaryState,FC_State, "NAM = '{0}'".format(StateName))

#4.Clip the properties layer based on a state
arcpy.analysis.Clip(FC_Forest, FC_State, "NSW_Properties", None)

#5.Buffer properties layer 
DistanceField="20 Meter"
arcpy.analysis.Buffer("NSW_Properties", "NSWProperties_Buffer", DistanceField, "FULL", "ROUND", "NONE", None, "PLANAR")

#6. Clip Hydrology layer based on properties
arcpy.analysis.Clip(Hydrology,"NSWProperties_Buffer", "NewSouthWales_Hydrology", None)


0 Kudos
1 Reply
MVP Notable Contributor

Are you familiar with modelbuilder, this would be very simple to do in that? You would use a feature iterator to step over each state in your boundary layer and that becomes the buffered clipper geometry? Not a single line of python code needs to be written to solve this task.

If you want to continue in the scripting environment then you need to read the help file on SearchCursors as that is what you need to use to extract the state names and create a simple loop. If your coding skills are not up to that then I would recommend modelbuilder for developing repetitive automation with little or no coding required.

0 Kudos