gbif-api
gbif-api copied to clipboard
Clearly specify how geometry polygons wrapping a pole or crossing the antimeridian should be specified
A polygon can cross the antimeridian (e.g. Fiji) or cross the antimeridian when wrapping around the north or south pole (e.g. around the Arctic).
I need to investigate a bit more, but either WKT doesn't really define how these polygons should be specified, or there are conflicting implementations.
Within this API project, we validate WithinPredicates using the JTS library, which lacks support. Some ways of specifying the polygon happen to work.
We should work out what we want to support, and convert as necessary to our backend systems.
As an example of the differences between implementations, https://github.com/locationtech/spatial4j/issues/46 says:
Strict interpretation of WKT/OGC rules refer to the "right-hand-rule" which basically says the outer shell is counter-clockwise order. Based on that Spatial4j has a bug and your test shows it. WKT/OGC, AFAIK, also don't talk about the notion of a dateline. There is a special case in Spatial4j that when given a 4-point rectangular polygon (NOT multipolygon), then it is processed according to the right hand rule. And hence your test will pass if the shape is trivially converted. But I'm planning on removing that or making it optional in the next release because numerous people have complained, even if it meets specs.
Spatial4j does it this way because it seemed a real-world polygon wouldn't have longitudinal points >= 180 degrees apart… …yet it's reasonable to search GBIF based on a polygon around Eurasia.
(Spatial4J is a derivative of the JTS library we use.)
This is the secondary issue from https://dev.gbif.org/issues/browse/POR-3042/ , which is a polygon of the Arctic. It's a reasonable polygon, but doesn't validate with JTS. It can be made into a rectangle -180 90…180 90,-180 90
which does validate, but we either need to do this ourselves, or clearly document it.
There still seems to be an issue with polygons circling the pole. Even when they are converted to the rectangle (along the 180th meridian). simple WKT like this POLYGON((-180 90, -180 70, 180 70, 180 90, -180 90))
works and shows all the records above 70º N (as expected). But when I add only one point to the polygon POLYGON((-180 90, -180 70, 0 0, 180 70, 180 90, -180 90))
query fails (HERE) even-tough it shows nicely in the overview map.