Select to view content in your preferred language

Python Script Help: Batch Describe Projection

3002
11
02-24-2011 08:00 AM
AshleyMott
Occasional Contributor
Hi all,
I got a lot of help in creating a Python scribt that allows me to describe a dataset's projection: http://forums.arcgis.com/threads/23918-Check-Projection-Coordinate-tool-or-script

Now, I'd like to do the same thing in a "batch." Basically, the ugly window that pops up when I right click on my Describe Projection script tool and hit batch won't do. It needs to be a nicer interface and more automated (just like any batch GPTool). Although, I do get the output that I want.

I'm having two problems with my batch describe script:
1. My loop does not work. I am learning Python, so basic concepts elude me. Don't laugh at my code please!
2. I am getting indent errors that I cannot seem to correct.

I also am curious as to why the tool won't automatically batch if I set the script tool's input parameter to be multivalue.

Any help is most appreciated.
Regards, Ashley

import arcpy

#Define message constants so they may be translated easily
unknown_projection = "Unknown"
# Get the feature class to describe
#
featureClass = arcpy.GetParameterAsText(0)
desc = arcpy.Describe(featureClass)
#Loop through each dataset and describe projection.
for dataset in inDatasets:
        try:
            #Describe input dataset to check if a projection is already defined.
            dsc_Dataset = ConversionUtils.gp.Describe(dataset)
            cs_Dataset = dsc_Dataset.SpatialReference
            #Check if a projection is already define for the input dataset.
            if cs_Dataset.Name != unknown_projection:
                ConversionUtils.gp.AddWarning(msgPrjAlreadyDefine)
# Print SpatialReference object properties
SR = desc.spatialReference
print SR.name
# shows results in commandline of IDLE
print SR.exportToString()
# Show results in geoprocessing tool dialog 
arcpy.AddMessage(SR.name)
arcpy.AddMessage(SR.exportToString())
Tags (2)
0 Kudos
11 Replies
AshleyMott
Occasional Contributor
I can't tell you enough how much I appreciate your help R.D. I did some studying up on Python over the weekend. That with your updated code allowed me to get what I want.

This final code returns just the projection name(s) of multiple datasets (like a batch) from a script tool.

import ConversionUtils, arcpy

#Set the input datasets
inputs  = ConversionUtils.gp.GetParameterAsText(0)
inFeatureClasses = ConversionUtils.SplitMultiInputs(inputs)
for featureClass in inFeatureClasses:   
    # Describe each fc
    desc = arcpy.Describe(featureClass)
    # Print SpatialReference object properties
    SR = desc.spatialReference
    print SR.name
    # shows results in commandline of IDLE
    print SR.exportToString()
    # Show results in geoprocessing tool dialog
    arcpy.AddMessage(SR.name)
0 Kudos
RDHarles
Regular Contributor
Not a problem, glad you got it working...
0 Kudos