Friday, December 21, 2007

Let's Call the Whole Thing Off...

You say "potato", I say "potato"; you say "long/lat", I say "lat/long". Long/lat, lat/long, lat/long, long/lat, let's call the whole thing off!

This thread at the MSDN forums is an interesting read, if you are a complete loser. (Disclosure: I am a complete loser.)

Y/X WorldIn a nutshell, Microsoft thinks the world looks like this. OK, OK, I'm being unfair, what they think is that it makes sense to use a latitude/longitude (y/x) order for ordinates in the Well-Known Text (WKT) and Well-Known Binary (WKB) that their STAsText() and STAsBinary() methods return, respectively. (Pls. see above re: my complete loserness.)

This is what the SQL Server spatial team had to say to a user wondering at this behavior:
This is the expected behavior, but as you found there is not a standard industry consensus on the ordering of latitude / longitude coordinates in formats such as WKT and WKB. The OGC SFS document does not cover geographic coordinates, only planar data, so it is not clear that the same ordering is necessary. However, the EPSG definition itself for 4326 defines the axis order as latitude / longitude, and that is what we use and what is defined by other formats such as GML / GeoRSS.

Here is a thread from the OpenGeoSpatial mailing list defining this behavior.
The place where I (surprise!) violently disagree with the Microsoft team is the assertion that “there is not a standard industry consensus on the ordering of ... coordinates in ... WKT and WKB”. There is, in fact, a massive industry consensus on WKT and WKB coordinate order. If the Microsoft team can find a shipping product that deliberately creates WKT or WKB in lat/long order I'll send them a 5lb box of Roger's Chocolates.

The comment goes on to muddy the waters by talking about GML, and GeoRSS and the OGC discussions on the topic of axis order, but is totally wrong about the core issue: what is the industry standard order for WKT and WKB. In this case, Microsoft is late to the game, they don't get to set the de facto standard, because there is already a de facto standard, and it is long/lat.

If Microsoft wants to interoperate easily with the standards-based products already in the marketplace, they will implement the de facto standard for their STAsBinary() and STAsText() functions. If they are paying lip service to actual interoperability ("we implemented the standard but for some reason absolutely everybody else is doing it different! who knew?") they'll do something else.

The de jure standard is, as the comment correctly notes, well nigh impossible to divine, because the OGC guidance on the subject has been scattered through so many areas, and because there is no explicit guidance on the topic for WKB and WKT. But the de facto standard, the “standard industry consensus” is clear: long/lat.

Update: To clarify the chocolate challenge, products that produce backwards WKB and WKT to satisfy SQL Server (FME, Manifold) don't count. This is about the industry standard that pre-existed SQL Server.

7 comments:

mentaer said...

It may be also about mathematicians/IT guys (sorry if..) and surveyors. The latter are used to work with (x,y = easting,northing) and probably invented maps :). Math people may put it the other way around. That is why i get used to rather use the words easting and northing during my studies instead using "x" and "y".
It may be further related to distance/angles on the sphere, i.e. in 3D Coordinate systems. Usually one first turns around the z-Axis of our lovely earth, then you move towards north. Here we move on 2 great circles on the sphere. For the other version we will first move on a great circle and afterwards in a little circle, i.e. not on the geodetic line between two points on a sphere ... just some thoughts ... maybe i am wrong. (if so... pls correct me).

Btw. In mapping from x,y to lat & long, the longitude value can be calculated straight forward, while the latitude needs to be approximated on the ellipsoid.

Dale said...

I have been accused of going a bit "staccato" during a few public speaking engagements where the topic of the ordering of x/y/lat/long comes up.

Why? This issue has cost my company alot of wasted time and wasted dollars. There exist many WFS servers out there that proudly say they are in this or that coordinate system, which according to the EPSG rules, should FLIP the x/y/lat/long, and yet they send us GML that is NOT flipped. And the GML, while it can include a hint as to if the data is 3D or 2D, DOES NOT give a hint about the coordinate system order, that is to be determined from the EPSG #. And so if folks aren't on top of things, the map gets flipped.

I personally applaud the pragmatism of the GeoJSON folks, who, in a variation of Matthew 5:37 said "Simply let your 'X' be 'X,' and your 'Y,' 'Y'; anything beyond this comes from the evil one." Now, sadly enough, since the GeoJSONers wanted to use EPSG #s as their coordinate system identifiers, they were forced then to OUTLAW a set of coordinate systems, and I have plans to donate to them a list of such forbidden #s to become part of the spec so at least we all agree on which ones they are, and there is a central list, lest no one go astray. Which leaves the question about what to do if the data comes to you in a forbidden coordinate system -- you can use a URN but from our looking there are 3 well known ones (LL-WGS84/LL-NAD27/LL-NAD83), and so other than that, we're just going to reproject things to LL84 and call it good.

But I digress. I am a strong believer in keeping things simple and straightforward. I'm not at all convinced that flipping lat/long long/lat away from an X/Y convention serves anyone, anywhere. Folks, its all inside a computer. We have to write software to do anything with this stuff. If end users have their crank turned by showing things in lat/long, then show it to them like that. But leave the internals in a standard, predictable storage mechanism.

All this to say that I will politely join the chorus of people asking for the WKT/WKB in SQL Server Geographic to go back to Long/Lat. And, though I might be turning down the 5 pounds of chocolate, I don't even think FME made a public Long/Lat WKT/WKB variation -- if we had to make such stuff (and I don't think we did actually), we did it behind the scenes only to be used to ferry info from our (well ordered xy world) into SQL Server.

Nothing like an inspiring coordinate system order discussion like this to liven up the Christmas season for all 3 of us who care....

Dale

Andrea Aime said...

Reading the blog makes me want to .... ROAR!!!

Ok ok, let's try to keep quiet. GeoServer has been hit by this madness too. Why? Well, because of WFS 1.1.

Before it EPSG:xxxx was not well defined enough that everybody chose the "obvious" order, that is, lon/lat.

Enter WFS 1.1, which requires you to define an SRS as "urn:ogc:def:crs:EPSG:xxxx" instead. What's the difference? The difference is that the above syntax is clearly defined and the definition says the axis order must respect the authority order which, in the case of EPSG, is lat/lon.

Long story short, ask GeoServer to output data from wfs 1.1 and you'll get it back in lat/lon order. Either that or we're not wfs 1.1 compliant.

To accomodate sane minded users and clients we still accept request asking for srsName=EPSG:xxxx, in that case we return data in lon/lat order instaed.

Crazy world we live in...

Dale said...

After having a day to think about it some more, perhaps the issue comes down to this. If a format has no way to explicitly express the coordinate system order (and giving me an EPSG # isn't explicit enough for me, I want the order explicit to avoid miscommunications), then I'd strongly vote that the coordinates be provided in X/Y. So that means, for WKT, which has no way to state the order, nor for that matter, the projection, best bet is to stick with X/Y. Aside: I'd also invite the GMLers to require a coordinate order indication in some future GML version to ensure this type of error cannot profilerate...

Dave Smith said...

In the US, the convention among surveyors is northing, easting, whereas in other countries, it's easting, northing.

But all conventions aside, we have run into the same issues - (Hey! why are there facilities showing up in China/the Pacific Ocean/any other odd place)

Certainly, one can often trap the reversals and switch them programmatically, but the bottom line remains that we need standards.

SharpGIS said...

They listened.
See: http://blogs.msdn.com/isaac/archive/2007/12/27/latitude-longitude-ordering.aspx

g said...

Interesting that the ISO has a position :-) on this too

They say "LatLong"

http://en.wikipedia.org/wiki/ISO_6709

About Me

My Photo
Victoria, British Columbia, Canada

Followers

Blog Archive

Labels