Saturday, 1 April 2017

postgis - Best-practices for databases and APIs with geographic data spanning the antimeridian


What is the best-practice for storing geographic features (lines, polygons and their multipart equivalents) when these features span the antimeridian (±180° longitude), and need to be sent to and recieved from client web applications as GeoJSON?




I am starting work on a server-side web API with support from a Postgres/PostGIS database to work with historical and forecast tropical cyclone tracks and wind radii. Many cyclones in the Pacific Ocean have the unfortunate tendency to cross the antimeridian, sometimes multiple times in their lifespan:


enter image description here


As a New Zealander living near the antimeridian, I have encountered this problem often enough in regional data to have some coping strategies, but I would like to actually find out what is considered to be best practice. Unfortunately there are no existing questions tagged , so it is hard to search for related questions. Those questions that I have seen struggling this problem all seem to be seeking very application-specific advice. This question briefly discusses the antimeridian for the case of an earth-spanning GeoJSON polygon with no boundary. This question is pretty close to what I'm asking.


I need to store historical and forecast cyclones in a spatial database, but I anticipate that there will be issues with the antimeridian. For instance, a line starting at latitude/longitude (0,179) and ending at (0,-179) is ambiguous with respect to its direction: whether it takes the short path across the antimeridian, or "wraps" around the entire planet. How should such a path be stored in a spatial database (specifically I'm working with PostGIS but I hope the solution is generic enough)? Some ideas that I have:




  1. Make no change to feature geometries and shift the ambiguity to client applications.

  2. Split any feature crossing the antimeridian into a multipart geometry with a break at the antimeridian. (The GeoJSON specification supports named CRSs.)

  3. Work with non-global projections for different cyclone basins or oceanic regions that don't have such a discontinuity

  4. Exploiting the fact that a cyclone has never been observed to travel around the entire planet, store the coordinates of cyclones starting in the latitude range (90,-90) offset by a 360° phase (keeping the others -180–180°)

  5. Exploiting the fact that a cyclone is extremely unlikely south of the southern tip of Africa, use a break at 30° longitude (as in the above map).

  6. Allow coordinates to extend beyond the valid range of EPSG 4326, e.g. > 180° and < -180° for any features that pass the antimeridian.

  7. Delta encoding, like in TopoJSON (e.g. start at (0,-179) and then next coordinate is -3 latitude west). I have no idea whether or how to implement this when storing data in PostGIS, but this is a great solution for sending data to client applications.

  8. Some form of vector notation or polar coordinates. (Seems rather difficult and unusual.)


Of these, I don't like ideas 2–5 because they aren't generic, but I do like them because they make some sense for my particular application. For applications only dealing with data in the Pacific Ocean, they might make a lot of sense, so I don't want to completely discount them as options.



Ideas 6 and 7 were lifted from Tom MacWright's blog, which is worth a read but is not conclusive with respect to the antimeridian.


Idea 4 is used by GeographicaGS' GeodesicLinesToGISPython, which in turn is using fiona.transform.transform_geom with a 360° antimeridian offset. In turn, Fiona is using OGR's -wrapdateline. I suppose that's a very solid precedent and actually rather generic.


In conjunction with the issue of storage, I need to consider how such features should be sent to client applications, and how my application should consider data posted back to it (e.g. a human forecaster changing the forecast track of a cyclone in the Pacific). The interchange format will probably be GeoJSON, but does not have to be.


Unfortunately the GeoJSON specification is not explicit about antimeridian issues. This from Wikipedia:



Many geographic software libraries or data formats project the world to a rectangle; very often this rectangle is split exactly at the 180th meridian. This often makes it impossible to do simple tasks (like representing an area, or a line) over the 180th meridian. Some examples:




  • The GeoJSON specification doesn't mention handling of the 180th meridian in its specification, as such, representations of lines crossing the 180th meridian can just as well be interpreted as going around the world.





  • In OpenStreetMap, areas (like the boundary of Russia) are split at the 180th meridian.





My reading is that GeoJSON has no particular standard representation of antimeridian-spanning features, and it is deliberately left ambiguous (multi-part geometries would perhaps resolve the issue). Similarly in OpenStreetMap there are geometry divisions at the antimeridian, although I don't know if such split features are multipart or are actually discrete records.


This feels rather problematic, especially from the perspective of making bounding box or other spatial requests that span this line, but also in parsing and sanitising input and any updates to feature geometries. This is why I'm trying to determine a best practice that I can seek to conform to.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...