ropensci-archive / geoaxe

:no_entry: ARCHIVED :no_entry: Split 'Geospatial' Objects into Pieces
Other
13 stars 0 forks source link

Strategies for splitting up polygons #1

Open sckott opened 8 years ago

sckott commented 8 years ago

Right now we have one method:

  1. User gives cell size and cell dimension - then grid topology is created, then a spatial grid, then intersect the grid and the input polygon

What others?

sckott commented 8 years ago

Create bbox from polygon, do some geographic search with that bbox, then get subset of data by going back to original polygon by subtracting out of the bbox

Need for http get requests with wkt runs into 414 error quickly

mdsumner commented 7 years ago

I've put together sfdct to chop up polygons into triangles, it relies on RTriangle (which has a problem license for commercial use).

https://github.com/r-gris/sfdct

The behaviour currently replaces each feature with a GEOMETRYCOLLECTION of POLYGON triangles (that's the only way you can do it with simple features).

I thought we might explore the cross over for what geoaxe is aiming for here?

library(sfdct)
wkt <- "POLYGON((-180 -20, -140 55, 10 0, -140 -60, -180 -20))"
library(sf)
x <- st_as_sf(data.frame(g = wkt), wkt = "g")

## default
plot(ct_triangulate(x), col = "transparent")

## area-constrained
plot(ct_triangulate(x, a = 10 * 10), col = "transparent")

## area and angle constrained
plot(ct_triangulate(x, a = 10 * 10, q = 15), col = "transparent")

## ensure Delaunay-compliant as well
plot(ct_triangulate(x, a = 10 * 10, q = 15, D = TRUE), col = "transparent")

Another thing that I've learnt that might be of interest is turning a RasterLayer into individual-cell polygons. It can be more efficient to generate the mesh and then explode that into Polygons, though it's more efficient not to have to create the polygons of course - it's very different between sp and sf so the benchmarks aren't enough to make the case:

https://github.com/mdsumner/spex/blob/master/R/qm_rasterToPolygons.r

Using the sfdct approach you can actually merge all the edges from a raster and a polygon layer together first, before expanding everything out for simple features. I'm going to be exploring that so happy to discuss if you think it's of use. There's a couple of raw examples of merging layers as a planar partition here, still very early:

https://github.com/r-gris/sfdct/issues/11

It's not my primary focus right now but I think this is worth fleshing out more.

sckott commented 7 years ago

@mdsumner very nice!

works nicely.

I guess I'd be a little worried about the licensing - since i use geoaxe in rgbif which is widely used and perhaps used by companies, which I imagine then wouldn't be able to use it anymore, correct?

mdsumner commented 7 years ago

I think so, I wonder about a sensible way to isolate that to avoid preventing use of other code. So we can use it for research but point to other options for commercial use (Manifold is one). I also asked @ironholds to help get bindings to CGAL which is LGPL.

Ear clipping is another option though, not as nice triangles but available in rgl and in js "earcut". I want to explore any avenue to see what fits.

sckott commented 7 years ago

For my purposes I'm trying to avoid JS stuff as well - since going lite weight as possible is what I need - though in general JS wrapped stuff is great

mdsumner commented 7 years ago

Tried messing around with resampling the triangles for random polygon features, with ok results, just FYI.

http://rpubs.com/cyclemumner/randotri

At some point I'll figure out the lightest, safest dependencies for this, there's a heap of stuff we can use it for and it'll get simpler. It is possible to triangulate to convex form with sf but I don't have the patience to get that to work right now.

sckott commented 7 years ago

looks great, 👍