Set a coordinate system to "Unknown" with Python

3947
10
Jump to solution
11-16-2015 08:06 AM
RandyMcGregor
New Contributor III

I have a script tool that creates outputs with unknown coordinate systems. This is as designed. The outputs are profiles, created from an x,y table.

Recently (10.3?), the tool has been failing and that seems to be because ArcMap wants to apply the wgs84 coordinate system by default when none is specified.

I want it to be "Unknown" or "Undefined" both of which fail when I enter them into the MakeXY_Table_management tool:

  arcpy.MakeXYEventLayer_management(proftab,"PROF_X","PROF_Y",profptlyr,"Unknown","#")

This also fails:

    arcpy.DefineProjection_management(profptlyr,coor_system="Unknown"), although I can enter "Unknown" when I run the DefineProjection tool from the toolbox.

The coord_system input is considered illegitimate.

Is it possible to do this?

Thanks

0 Kudos
1 Solution

Accepted Solutions
FreddieGibson
Regular Contributor II

Give this a shot.

import arcpy
unknown = arcpy.SpatialReference()
unknown.loadFromString(u'{B286C06B-0879-11D2-AACA-00C04FA33C20};-450359962737.05 -450359962737.05 10000;#;#;0.001;#;#;IsHighPrecision')
arcpy.MakeXYEventLayer_management(r'C:\Path\To\DATA.csv', 'x_coord', 'y_coord', 'LayerName', unknown)

View solution in original post

10 Replies
LukeSturtevant
Occasional Contributor III

I'm not sure if there is a way to set the spatial reference to Unknown using the define projection tool. One thing you can do is use python to delete the .prj file for the shapefile. I'm not sure why you would ever want to do this, but that is one way to go about it.

0 Kudos
NeilAyres
MVP Frequent Contributor

There was an earlier question (some while ago) here.

Trying to find it.

0 Kudos
FreddieGibson
Regular Contributor II

Give this a shot.

import arcpy
unknown = arcpy.SpatialReference()
unknown.loadFromString(u'{B286C06B-0879-11D2-AACA-00C04FA33C20};-450359962737.05 -450359962737.05 10000;#;#;0.001;#;#;IsHighPrecision')
arcpy.MakeXYEventLayer_management(r'C:\Path\To\DATA.csv', 'x_coord', 'y_coord', 'LayerName', unknown)
NeilAyres
MVP Frequent Contributor

Freddie, brilliant.

As someone said at the time, nothing says Unknown Spatial Reference like..

{B286C06B-0879-11D2-AACA-00C04FA33C20}

Perfectly obvious.

JoshuaBixby
MVP Esteemed Contributor

The problem with creating an "Unknown/Undefined" spatial reference has been around for years; unfortunately, Esri has made it clear they don't really see it as much of a problem and don't plan on addressing it.  For example, see  Bug NIM-087033: Arcpy.DefineProjection_management does not take 'Unknown' as a valid coordinate syst....

The SpatialReference.loadFromString works, but it relies on passing the Esri internal Class ID/GUID value for the unknown spatial reference.  Although that Class ID/GUID has remained the same for many, many years, it is nonetheless an internal value that Esri could change.  My preferred workaround is to create an empty point geometry with no spatial reference, which gets turned into the unknown spatial reference, and then pass that into a variable:

>>> SR = arcpy.FromWKT('POINT EMPTY').spatialReference
>>> #which can be seen to use Unknown/Undefined spatial reference
>>> SR.exportToString()

u'{B286C06B-0879-11D2-AACA-00C04FA33C20};-450359962737.05 -450359962737.05 10000;#;#;0.001;#;#;IsHighPrecision'
DanPatterson_Retired
MVP Esteemed Contributor

or like mine below...

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

One problem I run into trying to reply during the day, I get distracted and my responses get drawn out, so other responses come in before I hit reply.  I wish comments could be easily saved as draft and revisited later.  Although there is auto-saving, I have run into cases where I lost content, and copying and pasting the content/html back and forth to the clipboard is such a hassle.

RandyMcGregor
New Contributor III

Thank you, that did it.

Just like that.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Me thinks Freddie is being cruel....

so here is what you do

  • I am going to demo with a shapefile
    • get over it if you don't use shapefiles...they have a *.prj that can be deleted
  • delete the *.prj ... or rename it for the meek and timid
  • get a describe object for the file that has the *.prj deleted
  • get its spatial reference
  • export it to text and see what you get
>>> desc = arcpy.Describe(r'f:\test\buff.shp')
>>> SR_unknown = desc.SpatialReference
>>> ancient_text = SR_unknown.exportToString()
>>> print("FYI \n{}".format(ancient_text))
FYI 
{B286C06B-0879-11D2-AACA-00C04FA33C20};341985 5023985 300239975158033;#;#;0.001;#;#;IsHighPrecision
>>>

Of course yours will be different, but it was an MTM zone 9 originally which the first two numbers are about right for.