1

I have 2 gdb's; one that contains a polygon feature class of census blocks(cb), and one that contains centroids that may lie within those census blocks. They are organized by state. Ex: FL_cb = FL_centroid. I want to iterate through both of those cdb's at the same time using arcp.ListFeatureClasses() and find the matching feature class for each state. The problem seems to be that to do this, I have to switch workspaces.

res_centroids = r"<path>\Processed\ResidentialParcels_Processed_ByState.gdb"
cbs = r"<path>\CensusBlocksStates.gdb"
res_cb_pt_intersects = r"<path>\Processed\ResCentroid_CB_Intersects_ByState.gdb"
arcpy.env.workspace = res_centroids
cent_featureclasses = arcpy.ListFeatureClasses()
for k, v in stateabb.items():
 for fc in cent_featureclasses:
 if k in fc:
 print (k)
 print (fc)
 arcpy.env.workspace = cbs
 cb_features = arcpy.ListFeatureClasses()
 for cb in cb_features:
 if v in cb:
 print (v)
 outputInt = "{}_CB_Cent_Interest".format(v)
 outputFC = os.path.join(res_cb_pt_intersects, outputInt)
 arcpy.Intersect_analysis(in_features=[cb, fc], out_feature_class=outputFC , join_attributes="ALL", cluster_tolerance="-1 Unknown", output_type="POINT").

The end results is that my fc no longer exists and throws a Failed to execute. Parameters are not valid error when I do the intersect.

Is there a way to store it in memory or can I create a temporary feature somehow to perform the intersect?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 2, 2019 at 16:51

1 Answer 1

2

Yes. So if you were to print cent_featureclasses, you'd see that it only has the feature class name, not the full path. So if you change the workspace, it is looking for those names in the current workspace. So basically all you have to do is add full path list, like so:

cent_featureclasses = arcpy.ListFeatureClasses()
cent_featureclassesFP = []
for k, v in stateabb.items():
 for fc in cent_featureclasses:
 cent_featureclassesFP.append(res_centroids+'\\'+fc)

But honestly, you are over-killing it with the loops. As long as the naming conventions are consistent (I assume k is the state name and v is the abbreviation in your dictionary), all you really need is this:

res_centroids = r"<path>\Processed\ResidentialParcels_Processed_ByState.gdb"
cbs = r"<path>\CensusBlocksStates.gdb"
res_cb_pt_intersects = r"<path>\Processed\ResCentroid_CB_Intersects_ByState.gdb"
arcpy.env.workspace = res_cb_pt_intersects
for k, v in stateabb.items():
 print (k)
 in_features = [res_centroids+"\\"+str(v)+"_centroid", cbs+"\\"+str(v)+"_cb"]
 outputInt = "{}_CB_Cent_Interest".format(v)
 arcpy.Intersect_analysis(in_features, outputInt, join_attributes="ALL", cluster_tolerance="-1 Unknown", output_type="POINT").
answered Jul 2, 2019 at 20:47

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.