LocalData / localdata-api

API/server for LocalData
http://localdata.com/
BSD 3-Clause "New" or "Revised" License
20 stars 14 forks source link

Investigate TurfJS for geometry repair/simplification #267

Open prashtx opened 9 years ago

prashtx commented 9 years ago

https://github.com/Turfjs/turf-simplify https://github.com/Turfjs/turf-kinks

We need to confirm that the libraries behave well with problematic parcels that we've encountered in the past.

prashtx commented 9 years ago

It looks like turf-kinks doesn't detect overlaps with no crossover, as in

{
  "type": "Polygon",
  "coordinates": [[ [5,5],[5,6],[6,6],[7,6],[6,6],[6,5],[5,5] ]]
}

image

It also doesn't detect repeated points, although those are easier for us to deal with separately:

{
  "type": "Polygon",
  "coordinates": [[ [5,5],[5,6],[6,6],[6,6],[6,5],[5,5] ]]
}
hampelm commented 9 years ago

Should we file a bug? Is a self-overlap without crossover technically a kink?

On Wed, Dec 31, 2014 at 3:09 PM, Prashant Singh notifications@github.com wrote:

It looks like turf-kinks doesn't detect overlaps with no crossover, as in

{ "type": "Polygon", "coordinates": [[ [5,5],[5,6],[6,6],[7,6],[6,6],[6,5],[5,5] ]] }

[image: image] https://cloud.githubusercontent.com/assets/1307783/5590209/631f1f26-90e4-11e4-942f-4251212a61eb.png

It also doesn't detect repeated points, although those are easier for us to deal with separately:

{ "type": "Polygon", "coordinates": [[ [5,5],[5,6],[6,6],[6,6],[6,5],[5,5] ]] }

— Reply to this email directly or view it on GitHub https://github.com/LocalData/localdata-api/issues/267#issuecomment-68466280 .

prashtx commented 9 years ago

We can possibly use turf-envelope to index a feature's bounding box. It's possible to get a degenerate polygon out of turf-envelope, so we'd still need to do some validation. If we commit to simplifying all indexed polygons/multipolygons, then we start with computing the envelope. If the area is 0, we can index the centroid instead. The envelope is always a rectangular polygon, so we won't encounter weird zero-width arms. It should either be valid or have zero area.