Print

Print


NEARC-L,

I'm writing to summarize the responses to my inquiry about comparing spatial references in ArcPy. I'd like to thank Shaun Walbridge, Christopher Dunn, and Jim Duncan for their feedback.

The takeaways are:


*         If you really need to compare the "functional" properties of two spatial references in Python, you need to just compare each property one-at-a-time. In most cases, however, comparing the factoryCode, name, or exportToString() output will be sufficient.


*         We're fortunate enough to have a member of the Esri Python team who subscribes to NEARC-L (Shaun), and who has updated ArcPy to allow comparisons with the equality operator (==) in the next releases of Desktop and Pro. Note that this type of comparison will still require that the name, factory code, etc. be the same in order for two spatial references to be considered semantically the same. But, it'll let us keep our code cleaner by doing things like "if sr1 == sr2" instead of "if sr1.factoryCode == sr2.factoryCode". Thanks Shaun!



*         For comparisons sans-name, Jim recommended using exportToString(), then removing the name string from the results. That's a good idea that I hadn't considered before. Fortunately, string manipulations like that are easy in Python.



*         For reference, ArcObjects can compare spatial references without regard to their names, but that feature isn't exposed via ArcPy.


Thanks, again, for the quick and thoughtful responses. I hope everyone has an enjoyable weekend.

-Michael

P.S. Apparently my original message came through as plain text instead of HTML, which certainly made it hard to read. Apologies in advance if this summary arrives in the same condition. -M


Michael Mannion
Database Consultant | Mannion Geosystems | +1 617.939.9958 | http://www.manniongeo.com<http://www.manniongeo.com/>


-----Original Message-----
From: Northeast Arc Users Group [mailto:[log in to unmask]] On Behalf Of Michael Mannion
Sent: Thursday, July 28, 2016 4:18 PM
To: [log in to unmask]
Subject: [SPAM] Best way to compare spatial references in arcpy



NEARC-L,



I'm working on an arcpy-based tool in which I need to determine if the spatial references for two feature classes are the same, and I'd like your advice on the best way to do that.



In my research so far, I've learned:





*         Comparing different instances of identically-defined SpatialReference objects with the Python == operator yields False.





*         Folks online report doing things like compare the factoryCode or name properties. As far as I can tell, however, those properties are really only metadata whose values don't affect the functional definition of the coordinate system. So, two spatial references could be effectively the same, but with a different factoryCode or name value (see next).







*         For a more detailed comparison, I tried using the SpatialReference.exportToString()values. But, I can construct a case where the name is different, yet the functional properties of the coordinate systems are the same. For example, I can define my own coordinate system that is identical to a well-known one, but their string definitions will be different because of the names (as well as the factoryCode, PCSCode, etc.). The following two strings are identical except for their names (highlighted) and, of course, return False when compared:







o   Well-known: PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]];-20037700 -30241100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision





o   Custom: PROJCS['My_Custom_Name',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]];-20037700 -30241100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision



Therefore, my question is:





*         QUESTION: Is there any way to compare (in Python/arcpy) if two spatial references are functionally equivalent without doing a property-by-property comparison of their geographic, projected, and geodatabase coordinate system properties?



Thank you, in advance, for sharing your thoughts.



-Michael





Michael Mannion

Database Consultant | Mannion Geosystems | +1 617.939.9958 | http://www.manniongeo.com<http://www.manniongeo.com/<http://www.manniongeo.com%3chttp:/www.manniongeo.com/>>





------------------------------------------------------------------------- This list (NEARC-L) is an unmoderated discussion list for all NEARC Users.



If you no longer wish to receive e-mail from this list, you can remove yourself by going to http://s.uconn.edu/nearcsubscribe.

------------------------------------------------------------------------- This list (NEARC-L) is an unmoderated discussion list for all NEARC Users.

If you no longer wish to receive e-mail from this list, you can remove yourself by going to http://s.uconn.edu/nearcsubscribe.