Select to view content in your preferred language

Union for a list of Feature classes

750
2
11-16-2010 06:28 AM
GraziaZulian
Emerging Contributor
I wrote this script for performin an union operation between 2 lists of files.
Files have different names but end with the same number. Files are in the same directory.

Wht's wrong in the code?
thanks


#Import modules
import sys, string, os, arcgisscripting

gp = arcgisscripting.create(9.3)
gp.CheckOutExtension("Spatial")

gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")

pathA = sys.argv[1]

outWorkspace = sys.argv[2]

gp.workspace = pathA

try:
   
    FeatsA = gp.ListFeatureClasses("A_*","POLYGONS")
    FeatsB = gp.ListFeatureClasses("B_*","POLYGONS")
    for FeatA in FeatsA:
        for FeatB in FeatsB:
            if FeatA[1:2] == FeatB[1:2]:
                outfeat = outWorkspace + "\\union_" + str(FeatB)   
                gp.Union_analysis(FeatA + ";" + FeatB, outfeat, "ALL", "", "GAPS"); showGpMessage()

               
except:
    # If an error occurred while running a tool, then print the messages.
    print gp.GetMessages()
0 Kudos
2 Replies
DonovanCameron
Deactivated User
Are you experiencing an error when executing this script?

Also keep in mind that the limit of inputs for a Union is set to  no  more than 2 if you are using any Arc licensing below ArcINFO.

If you want to union more than two features at once, then you need ArcInfo, otherwise, merge your features prior to the union and union that merged feature with itself.
0 Kudos
GraziaZulian
Emerging Contributor
I'm working with an ArcInfo licence.

It works but the output is just one, the first one... (for example union_B_01.shp)

I'm trying now just with 4 polygons to test the code, But I need to process 40 polygons...

here are the data for the test
thanks for helping

Gra
0 Kudos