Select to view content in your preferred language

Parameter input syntax - UNION operation

887
6
07-28-2010 07:30 AM
SheriNorton
Frequent Contributor
I've tried running a Python script as a tool in ArcCatalog that accepts two input parameters to perform a union (it's actually the first part of a longer series of geoprocessing tasks I'm testing). I tried re-structuring the script as a stand-alone to run from PythonWin, no errors but also no output generated. Arg! Is there something obvious in the code that I'm missing (such as the syntax for using variables for parameter input in the Union operation)? Thanks for any thoughts.

#   Parameters:
#   0 - siteloc
#   1 - zonelayer

import arcgisscripting
gp = arcgisscripting.create(9.3)

import os
import sys

# Set the workspace
gp.Workspace = "C:\ZoneCalc\Scratch"

try:
# Define Parameters:
 
    # Define the Site Location Feature Class
    siteloc = gp.GetParameterAsText[0]

    # Define the Zone Feature Class - such as Soils, Slope, Wetlands, etc
    zonelayer = gp.GetParameterAsText[1]

# Perform Operations:

    # UNION the siteloc and zonelayer feature classes, creating a new feature class called output_union
    gp.union_analysis(siteloc, zonelayer, "output_union.shp", "NO_FID")

except:
    gp.AddError("An error occurred. " + gp.GetMessages(2))
0 Kudos
6 Replies
ChrisSnyder
Honored Contributor
The correct Python syntax is to use a semicolon to delimit the input FCs.

gp.union_analysis(siteloc + ";" + zonelayer, "output_union.shp", "NO_FID")
0 Kudos
SheriNorton
Frequent Contributor
I tried but this returned a syntax error when the script ran. Here's what I tried also:

  gp.union_analysis("siteloc; zonelayer", "output_union.shp", "NO_FID")

My suspicion is a problem with the parameters and associated variables, and how the variables are used in the UNION tool.
0 Kudos
ChrisSnyder
Honored Contributor
Not sure what the issues is. Hope this example helps:

#Process: Creates a FGDB to hold all the spatial layers
fgdbName = "pls"
fgdbPath = gp.workspace + "\\" + fgdbName + ".gdb"
gp.CreateFileGDB_management(gp.workspace, fgdbName); showGpMessage()

#Process: Define the path of a bunch of admin layers
adminFC = root + "\\gis_layers\\admin.gdb\\admin"
countyFC = root + "\\gis_layers\\county.gdb\\county"
districtFC = root + "\\gis_layers\\district.gdb\\district"
parcelFC = root + "\\gis_layers\\parcel.gdb\\parcel"
regionFC = root + "\\gis_layers\\region.gdb\\region"
  
#Process: unions everything together
union1FC = fgdbPath + "\\union1"
gp.Union_analysis(countyFC + ";" + regionFC + ";" + adminFC + ";" + districtFC + ";" + parcelFC, union1FC, "ALL", "", "GAPS"); showGpMessage()
0 Kudos
DebbieJamieson
Emerging Contributor
I have been trying for days to get multiple FC's to UNION. I can get 2 no problem, but no more. I am using vb.net in 9.2. ANy ideas??? THis is what I have been using so far...

  Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()
        Dim gpUtils As IGPUtilities2 = New GPUtilitiesClass()
           
       
      
            Dim inFeature1 As IFeatureClass = gpUtils.OpenFeatureClassFromString("C:\TestData\VP_Testdata\trails_buf.shp")
            Dim inFeature2 As IFeatureClass = gpUtils.OpenFeatureClassFromString("C:\TestData\VP_Testdata\Spawning_area_clp.shp")
            'Create and populate a Value Table Object
            Dim vt As IGpValueTableObject = New GpValueTableObjectClass()
            vt.SetColumns(1)
            Dim obj1 As Object = inFeature1
            vt.AddRow(obj1)
            Dim obj2 As Object = inFeature2
            vt.AddRow(obj2) 'Run the Tool
            Dim pUnion As ESRI.ArcGIS.AnalysisTools.Union = New ESRI.ArcGIS.AnalysisTools.Union()
      
            pUnion.in_features = vt
            pUnion.out_feature_class = C:\temp\Union_Out1.shp"

            GP.Execute(pUnion, Nothing)


thanks
0 Kudos
ChrisSnyder
Honored Contributor
From the Union tool help:

"With ArcView and ArcEditor licenses, the number of input feature classes or layers is limited to two."

ArcInfo is basically unlimited.

As a work around, you could write some code that will recursively go through a list of input layers, union them (two at a time), and then keep unioning those outputs until you are done. I wrote Python code to do this at one point (bug in the Union tool ~5 years ago where the output would be corrupt if > 5 layers were unioned at a time), but I can't seem to find it.
0 Kudos
DaleHoneycutt
Deactivated User
Coming late to this post... one thing that stands out is this code:
# Define the Site Location Feature Class
siteloc = gp.GetParameterAsText[0]


It should be:
siteloc = gp.GetParameterAsText(0)


(Note use of parentheses as opposed to brackets.  I suspect you've found this out...)
0 Kudos