Hello everyone! Right now I'm trying to clip a point shape file to 9 different polygon feature classes. I've come up with this script, but it's not working for me for some reason.
Wildfires is the point shapefile and the boundaries are all polygons I'm trying to clip the point shapefile to.
import arcpy >>> from arcpy import env >>> env.workspace = "L:/OPP/Rangers/Central Office/GIS/Deidre GIS Reporting Files" >>> FDRA_Boundary = ['Catskill_FDRA_Boundary', 'Long_Island_FDRA_Boundary', 'Leatherstocking_FDRA_Boundary', 'St_Lawrence_FDRA_Boundary', 'Southern_Tier_FDRA_Boundary', 'UHC_FDRA_Boundary', 'Lake_Ontario_Plains_FDRA_Boundary', 'HudsonValley_FDRA_Boundary', 'ADK_HighPeaks_FDRA_Boundary', 'ADK_FDRA_Boundary'] >>> for boundary in FDRA_Boundary: ... arcpy.Clip_analysis('Wildfires', FDRA_Boundary, FDRA)
Forgive me if this is a simple question. I'm still trying to incorporate basic python into my workflow.
Solved! Go to Solution.
Hi Deidre,
simple fix, you need to replace
arcpy.Clip_analysis('Wildfires', FDRA_Boundary, FDRA)
with
arcpy.Clip_analysis('Wildfires', boundary, FDRA)
FDRA_Boundary is a list, which is not a valid input for the tool, whereas boundary is the place holder for the item in the list you are looping through(shapefile or GDB FC, first time through this would be 'Catskill_FDRA_Boundary', and so on and so forth).
I also notice you are not defining FDRA variable, you will need to do this, and name each output from clip analysis uniquely, or it will overwrite the output of each clip, since they will have the same name and filepath.
Also if your files are shapefiles(since I don't see a gdb in your file path thought they might be), you will want to add .shp to each filename in the FDRA_Boundary list.
Hope this helps!
EDIT: Okay maybe not so simple since there are a couple things wrong, but you are on the right track.
Hi Deidre,
simple fix, you need to replace
arcpy.Clip_analysis('Wildfires', FDRA_Boundary, FDRA)
with
arcpy.Clip_analysis('Wildfires', boundary, FDRA)
FDRA_Boundary is a list, which is not a valid input for the tool, whereas boundary is the place holder for the item in the list you are looping through(shapefile or GDB FC, first time through this would be 'Catskill_FDRA_Boundary', and so on and so forth).
I also notice you are not defining FDRA variable, you will need to do this, and name each output from clip analysis uniquely, or it will overwrite the output of each clip, since they will have the same name and filepath.
Also if your files are shapefiles(since I don't see a gdb in your file path thought they might be), you will want to add .shp to each filename in the FDRA_Boundary list.
Hope this helps!
EDIT: Okay maybe not so simple since there are a couple things wrong, but you are on the right track.
Thanks for your help! Also, how do I go about incorporating naming each new output in my python script? Here is what I have now:
>>> import arcpy >>> from arcpy import env >>> env = "L:/OPP/Rangers/Central Office/GIS/Deidre GIS Reporting Files" >>> inFeatures = 'Wildfires' >>> FDRABoundaries = ['Catskill_FDRA_Boundary', 'Long_Island_FDRA_Boundary', 'Leatherstocking_FDRA_Boundary', 'St_Lawrence_FDRA_Boundary', 'Southern_Tier_FDRA_Boundary', 'UHC_FDRA_Boundary', 'Lake_Ontario_Plains_FDRA_Boundary', 'HudsonValley_FDRA_Boundary', 'ADK_HighPeaks_FDRA_Boundary', 'ADK_FDRA_Boundary'] >>> xy_tolerance = "" >>> for boundary in FDRABoundaries: ... arcpy.Clip_analysis('Wildfires', boundary, xy_tolerance)
The script seems to be running fine now thanks to that fix! I initially put the FDRA variable as a name for the output, but I see now that was wrong. How should I change the script so that I can assign proper output names for each clip? I ran the script as is above and it's working fine but the names of the output are "Wildfires_Clip1, Wildfires_Clip2..." and so on.
The arguments for Clip are:
Clip_analysis (in_features, clip_features, out_feature_class, {cluster_tolerance})
So, in_features is first, clip_features second, out_feature_class third.
If you want to name your output feature class with a variable, you need to use it in the third position.
arcpy.Clip_analysis('Wildfires', boundary, boundary + "_clip") # or something
edit: setting something to "env" doesn't do anything, as far as I know. Well, actually it sets the thing that used to be the environment object (as imported) to a string equal to your specified path. If you intend to set the workspace environment, you need to call it
env.workspace = "L:/OPP/Rangers/Central Office/GIS/Deidre GIS Reporting Files"
Yeah, that was just an error do to rushing on my part. Thank you for pointing it out and thanks for your help!
Whoops I missed the lack of env.workspace.
Otherwise, we have to stop posting the almost same responses
Couple of ways though I think for your purpose, incorporating the original file name to the new file would be best to easily identify the new output.
for boundary in FDRABoundaries:
Would use the input file name and then add "_Clip" to the end of it for the output name. That way you know which dataset was used for the clip.
Also xy_tolerance(aka cluster_tolerance) is the 4th parameter for this tool, not the third.