Path to .prj files in ArcGIS v10.1?

4733
13
08-08-2012 04:39 PM
ChrisSnyder
Regular Contributor III
In v10.0 and before there was always a folder that contained all the ESRI .prj definition files... Usually something like C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems.

Maybe I messed up my install somehow, but now in v10.1 it seems that 'Coordinate Systems' folder is no longer there, and to boot, there are no .prj files at all in the ArcGIS Program Files directory... at all!

I always used the .prj files to set the arcpy.env.outputCoordinateSystem variable (and all its various past incarnations).

What gives? How can we now access the official ESRI projection definitions in a script if there are no .prj definition file anymore?

The help says you can use .prj files, and the provided example in the arcpy.env.outputCoordinateSystem help topic yields:

arcpy.env.outputCoordinateSystem = "Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/Northern Hemisphere/WGS 1984 UTM Zone 18N.prj"
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 515, in set_
    self[env] = val
  File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 567, in __setitem__
    ret_ = setattr(self._gp, item, value)
RuntimeError: Object: Error in accessing environment <outputCoordinateSystem>
Am I totally missing something?
Tags (2)
0 Kudos
13 Replies
PeterYurkosky1
Occasional Contributor
By way of suggestions for a workaround:


  • Keep in mind that you can still export coordinate systems to .prj files in the dialog (right click the coordinate system in the treeview and select Save As...).

  • You can also get the factory code in the same dialog (and avoid searching through that .pdf file). It's shown as the "WKID" in the large text box at the bottom.

0 Kudos
NeilAyres
MVP Alum
Okay Pete,
As I havn't yet upgraded my system, is there a way to select a coordinate system, modify it then "Save As"?
But this is quite a change and I agree with the comments above.

N
0 Kudos
PeterYurkosky1
Occasional Contributor
is there a way to select a coordinate system, modify it then "Save As"?


Yes, just right-click the coordinate system in the tree-view and select Copy and Modify. This will create a new coordinate system that will appear under a "Custom" category. Then either add it to your "Favorites" (which creates a .prj file in your %APPDATA% folder) or select Save As to put it wherever you want.

Basically, the software still reads and honors .prj files, but they're no longer the mechanism for deploying the 4000+ coordinate systems included with ArcGIS.
0 Kudos
T__WayneWhitley
Frequent Contributor
This may be a little late to post here, but I followed up on Chris Snyder's suggestion (post #10) to write the prj file using the exportToString() method.  I didn't find it posted anywhere else and it's simple, so here it is (below).  The topic came up again yesterday with a post by Janet Brewster.

This script version simply writes a single file...

- gets the SR object from an input dataset and exports it to string.

- replaces single quotes with double quotes in the string (mine was rejected when I tried to use it with 10.0; was accepted as the coord sys param by tools such as Create Feature Class after replacing the quotes).

- writes the result to a text file (use a prj extension).
# define a few variables 1st:
dataset = r'< fc or shp pathname you want to create prj from >'
outFile = r'< text file pathname you want to write to (make sure to use prj ext) >'

print 'executing...please wait.\n'
import arcpy, time

# get Spatial Reference object
SR = arcpy.Describe(dataset).spatialReference

# get the string from the object
seeString = SR.exportToString()

# Testing w/ system ArcGIS tools at 10.0 rejected the string - the problem:  single quotes, simply replace with double quotes:
seeString = seeString.replace('\'', '\"')

# let's see it...
print 'This is the string after replacing single quotes, if any found:\n'
print seeString + '\n'

# write it and use it!
writeTo = open(outFile, 'wb')
writeTo.writelines(seeString)
writeTo.close()

print 'done.  ...check your new prj file in the directory you defined.'
time.sleep(5)


Enjoy,
Wayne
0 Kudos