0

I have created a code that iterates through a geodatabase, intersecting each feature with a road network. I am not sure how to make it so the intersected features are output into a new geodatabase. Here is my code so far:

import arcpy
import os
arcpy.env.overwriteOutput = True
# Location of the data you want to import
arcpy.env.workspace = r"D:\Data\OriginalFCs.gdb"
# Output Location
out_workspace = r"D:\Data\IntersectedFCs.gdb"
# Lists all feature classes in the workspace
fc_list = arcpy.ListFeatureClasses()
# Iterating intersect through GDB
for fc in fc_list:
 arcpy.Intersect_analysis(["RoadNetwork", fc], fc + "_Intersect", "NO_FID")
 arcpy.CopyFeatures_management(fc, out_workspace)

I want the output intersected features to be saved into the geodatabase specified by out_workspace, which is what I attempted to do with arcpy.CopyFeatures_Management in the final line. However, the intersected features are still output to the input workspace and nothing is created in the output location.

How can I modify my code to place the intersected features created in the FOR loop to my output workspace?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 12, 2019 at 21:46
4
  • What happens if you try: arcpy.CopyFeatures_management(fc, os.path.join(out_workspace, 'some_name')? You'd have to make sure to change 'some_name' every loop. Commented Sep 12, 2019 at 21:56
  • Using that creates a copy of the original input features inside of the output workspace and the intersected output is still created inside the original workspace. Commented Sep 12, 2019 at 22:08
  • @Marcelo Villa Using what you mentioned, I was able to create a second FOR loop that copies over all features ending with "_Intersect". Here is the code I used: fc_list2 = arcpy.ListFeatureClasses("*_Intersect") for fc2 in fc_list2: arcpy.CopyFeatures_management(fc, os.path.join(out_workspace, fc2)) If anyone has a more elegant solution that deals with the first for loop directly, I'd love to hear it! Commented Sep 12, 2019 at 22:30
  • Would arcpy.CopyFeatures_management(fc, os.path.join(out_workspace, fc + '_intersect') be an option? Commented Sep 13, 2019 at 1:09

1 Answer 1

1

this will do it

# Iterating intersect through GDB
for fc in fc_list:
 outfc = os.path.join(out_workspace, fc + "_Intersect")
 arcpy.Intersect_analysis(["RoadNetwork", fc], outfc, "NO_FID")
 #arcpy.CopyFeatures_management(fc, outfc) # NOT NEEDED

there is no need for an intermediate output which you copyfeatures to the output gdb, just have intersect write directly to the output gdb.

the reason CopyFeatures doesn't work in you original case is that you have to specify the output location + fc name. Your code specified the out_workspace only.

answered Sep 13, 2019 at 13:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.