Check Projection/Coordinate tool or script

5693
7
02-17-2011 09:59 AM
AshleyMott
New Contributor III
Hi everyone,
Do you know of a tool or  a python script that just returns the projection/coordinate system of a shapefile/feature class? In addition, and I know this sounds dumb, but it would be great if you could drag multiple shapefiles in like a batch. If the files were different, the tool would error out.

Thank you.
Tags (2)
0 Kudos
7 Replies
AshleyMott
New Contributor III
Or, just single file is good. I can probably figure the rest. Thanks!
0 Kudos
MichaelStead
Occasional Contributor III
The MultiMXD script would probably work if you saved an mxd with all your files first

http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=A910AB18-1422-2418-3418-3885D...

There might be a different tool in here somewhere that would work better. It is a pile of mxd production/management stuff demonstrating python/arcpy functionality.
0 Kudos
AndrewChapkowski
Esri Regular Contributor
You can use Describe and tool validation to check the projections before running tools.

Hope this helps
0 Kudos
AshleyMott
New Contributor III
Thanks Michael and Andrew.

I am attempting to create a Python script that will let me "describe" the projection of a dataset. I want to use this script in a tool I created in ArcCatalog (Add Script). See attached.

I am a little lost, because I don't know Python that well/at all.

I am thinking I need to define parameters? I am getting this error:
<type 'exceptions.NameError'>: name 'prjFile' is not defined
Failed to execute (DescribeProjection).

All I want the tool to do is tell you what projection that a dataset is in. You would either drag the dataset into the tool or search for it in a file.

Thanks!
0 Kudos
DanPatterson_Retired
MVP Emeritus
off hand, SpatialReference is case sensitive

"""
*******************************************************************************************
 NAME: DescribeProjection
 Source Name: DescribeProjection.py
 Version: ArcGIS 10.0
 Author: Ashley Mott
 Usage: DescribeProjection <input_data>, <input_coordinate_system>
 Required Arguments: A set of input feature classes or feature layers
 Description: Returns the coordinate system and/or projection of a dataset.
 Date Created: 02/22/2011

********************************************************************************************** """

import arcpy

# Get the feature class to describe
#
featureClass = arcpy.GetParameterAsText(0)
desc = arcpy.Describe(featureClass)

# Create a Describe Object from the prj file.
#
#desc = arcpy.Describe(prjFile)  # does nothing

# Print some SpatialReference object properties
SR = desc.SpatialReference  #case sensitive
print "SR: ", str(SR)
#haven't checked the rest
print "Name: " + SR.name
print "Type: " + SR.type
print "FalseOriginAndUnits: " + desc.falseOriginAndUnits
0 Kudos
AndrewChapkowski
Esri Regular Contributor
In your code you have this: desc = arcpy.Describe(prjFile). The variable prjFile is not defined.  Since you are pointing to a featureclass, you can just access the featureclass' spatial reference directly without having to use the .prj file:

import arcpy

# Get the feature class to describe
#
featureClass = arcpy.GetParameterAsText(0)
desc = arcpy.Describe(featureClass)
# Print some 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())
0 Kudos
AshleyMott
New Contributor III
Thanks Andrew and Dan. Success (plus, I see what I was doing wrong)! I just couldn't get over that hurdle in a reasonable amount of time.

Here is my output:

Executing: DescribeProjection "T:\WORK FOLDER\DEN_MP_SPCS.shp"
Start Time: Tue Feb 22 11:27:19 2011
Running script DescribeProjection...
NAD_1983_StatePlane_Colorado_Central_FIPS_0502_Feet
PROJCS['NAD_1983_StatePlane_Colorado_Central_FIPS_0502_Feet',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',3000000.000316083],PARAMETER['False_Northing',999999.999996],PARAMETER['Central_Meridian',-105.5],PARAMETER['Standard_Parallel_1',38.45],PARAMETER['Standard_Parallel_2',39.75],PARAMETER['Latitude_Of_Origin',37.83333333333334],UNIT['Foot_US',0.3048006096012192]];-118767900 -94525500 36985113.7070648;-100000 10000;-100000 10000;3.28083333333333E-03;0.001;0.001;IsHighPrecision
Completed script DescribeProjection...
Succeeded at Tue Feb 22 11:27:19 2011 (Elapsed Time: 0.00 seconds)
0 Kudos