Select to view content in your preferred language

Python: Get feature type and print

5068
7
11-02-2010 09:49 AM
LornaMurison
Regular Contributor
I would like to take the output of my intersect and dissolve operations and determine whether it is a shapefile or a geodatabase feature class.
If it is a shapefile, I need to add an "area" field and calculate it.

First, if I use this:
desc = gp.Describe(dissolveOutputFC)
outType = desc.FeatureType

will FeatureType give me the information I need?

Second, how do I test it?  If I type:
desc = gp.Describe(dissolveOutputFC)
outType = desc.FeatureType
print outType

where does it get printed to?

I have added the script to a toolbox in arc and specified the parameters that way.  I right-click > edit, to make any changes.
If I run it using pythonwin, how do I input the parameters?  Would it just be "path\file, path\file etc..."?


And last but not least, I am asking these simple questions because I can't find any documentation that would help me.  When I was learning VBA I would just google "iFeatureClass interface" for example, and that would lead me to the edn documentation that would list all the properties and methods of the interface.  Is there something similar for python, or the arcgisscripting module?  I am asking the above questions because I wasn't able to find out what gp.Describe is supposed to return.

Thanks.


Here is my full code, for what it's worth:
# Import Modules
import arcgisscripting

#Create Geoprocessor object
gp = arcgisscripting.create(9.3)
gp.overwriteoutput = True

# Intersect Catchments and Land Cover
catchmentsFC = gp.GetParameterAsText(0) #in a toolbox GUI, this should be Type = FeatureLayer
landCoverFC = gp.GetParameterAsText(1) #in a toolbox GUI, this should be Type = FeatureLayer
intersectOutputFC = gp.GetParameterAsText(2) #in a toolbox GUI, this should Type = FeatureClass
gp.Intersect_Analysis (catchmentsFC + ";" + landCoverFC, intersectOutputFC, "ALL", "", "INPUT")

# Dissolve output based on catchment and land cover IDs
# Field UCID (or other catchment ID) needs to be passed from the VBA code
dissolveOutputFC = gp.GetParameterAsText(3) #in a toolbox GUI, this should Type = FeatureClass
gp.Dissolve_management (intersectOutputFC, dissolveOutputFC, "UCID; GRIDCODE", "", "MULTI_PART", "")

# If the output is not a geodatabase feature class, then an area field must be calculated and added...
# And the necessary fields exported to dbf
# If the output is a geodatabase feature class, then the necessary fields are exported to dbf as is
desc = gp.Describe(dissolveOutputFC)
outType = desc.FeatureType
print outType
0 Kudos
7 Replies
RDHarles
Regular Contributor
Hi,

You want desc.DataType

This will give you this kind of output:
.shp = ShapeFile
.dbf = DbaseTable
temp.gdb/Business = FeatureClass
________________________________________________

Sounds like you're running your script from a ArcToolBox.  You need to use gp.AddMessage("Hi Mom.") instead of print.
"print" works if you're running your scripts from command line or pythonwin, to name a few.

________________________________________________

You input parameters in pythonwin by separating with a space.  e.g.  myscript.py apple banana pear

________________________________________________

Use the search here, lots of info to be had:
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=About_batch_processing_with_scripts

________________________________________________

The Describe outputs used to be listed in the help (like way back in 8.x maybe) but I haven't seen them in years.

________________________________________________
0 Kudos
LoganPugh
Frequent Contributor
"print" just does what it says, prints the value to the standard output (console window).

What you want to do is test the value of outType against the different possible return values of the Describe object's DataType property. If it's a shapefile the value will be "Shapefile", if it's a CAD or Geodatabase feature class it will be "FeatureClass".

This property is mentioned in the help, but I don't think the return values are documented: http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=1005&pid=980&topicname=Describe_Object_proper...
0 Kudos
ChrisSnyder
Honored Contributor
I usually debug my scripts in PythonWin using hardcoded gp.getparameterastext() values. For example:

##inputFC = gp.GetParameterAsText(0)
inputFC = r"C:\temp\test.shp"

Once it's working well I "un-hard code" the parameters and attach it to a toolbox.
0 Kudos
LornaMurison
Regular Contributor
Thank-you so much everyone,
This is all making a lot more sense now.

In this case:
##inputFC = gp.GetParameterAsText(0)
inputFC = r"C:\temp\test.shp"

What does the r mean?
0 Kudos
LoganPugh
Frequent Contributor
It means to take the string between the quotes literally, a "string literal". Otherwise you would have to escape each backslash (a special character in Python) with another backslash. More specifically, the r stands for "raw string": http://en.wikipedia.org/wiki/String_literal#Raw_strings
0 Kudos
ChrisSnyder
Honored Contributor
Also: Here's the object model cheat sheet for the geoprocessing methods like gp.listfields() or gp.describe() - not for the tools though like gp.Clip_managment(). The help has more details, but it's nice to just have a single page reference.

http://webhelp.esri.com/arcgisdesktop/9.3/pdf/Geoprocessor_93.pdf

Too bad ESRI didn't (yet!) make one of these bad boys for v10...
0 Kudos
RussellBrennan
Esri Contributor
Help on Describe is here:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Describe/000v00000026000000/

Once on this page you can click on the link to the data element you will be describing to find out what the output type of the describe will be.

For example, this is what is returned when describing a feature class:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/FeatureClass_properties/000v0000002p00...

Also notice in the summary in the help topic for feature classes that there is access to Table Properties and Dataset Properties as well. Most if not all data elements that you describe will inherit properties.
0 Kudos