cedadev / ceda-di

Other
2 stars 2 forks source link

Fix "display" polygon to conform to geojson guide #33

Open agstephens opened 7 years ago

agstephens commented 7 years ago

We have discovered an issue with the "display" polygons that are being captured in Elasticsearch by the ceda-di code. The issue is as follows:

  1. We capture the bounding box polygon and label it as the "search" polygon. It is 5 points as a closed rectangle. We make sure of this by finding each extreme and then packaging up a new polygon (and ensuring we close it). We also specify the "orientation" as "counterclockwise" which is in-keeping with the standard (see: https://tools.ietf.org/html/rfc7946#section-3.1.6). The relevant code is: https://github.com/cedadev/ceda-di/blob/master/python/src/ceda_di/metadata/product.py#L255

  2. We also capture the full polygon provided in the source data and we label it as the "display" polygon. This can have any number of points and might not be a closed polygon.

  3. We need to fix the "display" polygon so that it:

    • is always anti-clockwise in orientation (i.e. the points are given in that orientation).
    • it includes the attribute "orientation": "counterclockwise".
    • the polygon is always closed (i.e. the first and last point are identical).

The code that generates the "display" polygon is here:

https://github.com/cedadev/ceda-di/blob/master/python/src/ceda_di/metadata/product.py#L164

We need to fix the code so that the conditions in (3) are always met.

The code will therefore need to:

agstephens commented 7 years ago

I had some thoughts about how to do this... ...firstly, there might be a library out there that already does it.

If not, here are some (maybe wrong) thoughts:

  1. Find limits of the polygon (i.e. the four extremes)
  2. Start at highest x (easternmost point) (Which might also be highest y - northernmost point).
  3. Go through array:
    • check you see highest y before lowest x
    • check you see lowest x before lowest y
    • check you see lowest y before highest x
    • check it returns to highest x

You would need to wrap the array (i.e. append a copy of the array to the end) to ensure that you got through all the points (regardless of where you found the highest x).

If the conditions were not satisfied we assume it is clockwise, we reverse the array and do the same tests. And hopefully it is found to be counterclockwise.

rsmith013 commented 7 years ago

Added a function to remove any consecutive duplicates in the display coordinates. 682a1eccf6d7163968d92afd65ac3175853147cf