LISTSERV mailing list manager LISTSERV 16.0

Help for NEARC-L Archives


NEARC-L Archives

NEARC-L Archives


NEARC-L@LISTSERV.UCONN.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

NEARC-L Home

NEARC-L Home

NEARC-L  July 2016

NEARC-L July 2016

Subject:

SUMMARY: Best way to compare spatial references in arcpy

From:

Michael Mannion <[log in to unmask]>

Reply-To:

Michael Mannion <[log in to unmask]>

Date:

Fri, 29 Jul 2016 17:57:35 +0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (123 lines)

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.

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

May 2024
April 2024
March 2024
February 2024
January 2024
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014

ATOM RSS1 RSS2



LISTSERV.UCONN.EDU

CataList Email List Search Powered by the LISTSERV Email List Manager