Created
July 30, 2017 12:52
-
-
Save mdsumner/449148a78ccea02b19ab1a21bfc5acb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This image has a drawing that bugs me a little as it's not a triangulation, but nearly is. | |
Here we download it, read as a 3-layer raster brick, plot with mapview and then digitize on the points. | |
```R | |
u <- "https://pbs.twimg.com/media/DF5UuWsVYAAR7sX.jpg" | |
download.file(u, basename(u), mode = "wb") | |
library(raster) | |
r <- brick(basename(u)) | |
#m <- mapview::plainview(r) | |
## we can't plainview it so let's pretend it's mercator | |
extent(r) <- extent(0, ncol(r)*1000, 0, nrow(r)*1000) | |
projection(r) <- "+init=epsg:3857" | |
library(mapedit) | |
library(mapview) | |
## enter the interactive drawing session | |
pt <- mapview(r) %>% editMap() | |
## note that we obtain the "drawn" sub-object, and have to transform it to web mercator | |
## and also union it to obtain a single point, and triangulate that to get the mesh that I wanted | |
tri <- st_triangulate(st_union(st_transform(pt$drawn, 3857))) | |
## now a trad plot | |
plot(tri) | |
plotRGB(r, add = TRUE) | |
plot(tri, col = NA, border = "dodgerblue", lty = 2, lwd = 2, add = TRUE) | |
``` | |
Finally, the drawn points (in raw longitude-latitude matrix form). | |
```R | |
#dput(matrix(unlist(st_geometry(pt$drawn)), ncol = 2, byrow = TRUE)) | |
structure(c(0.3296, 0.3516, 0.8679, 1.0437, 2.7576, 2.5269, 2.2412, | |
2.2083, 1.9116, 1.9666, 2.384, 2.7795, 2.2522, 1.604, 1.3184, | |
1.1755, 1.3513, 1.615, 1.604, 2.0874, 2.7246, 2.1533, 1.4172, | |
1.1426, 1.2964, 1.1096, 1.4612, 1.593, 1.8127, 2.0325, 2.2083, | |
2.2742, 2.5378, 3.0103, 2.9663, 3.219, 3.219, 3.3728, 3.1201, | |
2.8455, 3.4257, 3.5792, 3.5902, 3.8643, 6.7301, 6.3153, 6.5118, | |
6.1187, 6.2389, 5.6269, 5.8128, 5.3098, 5.4629, 5.7581, 5.6051, | |
5.2332, 5.2004, 5.3863, 5.1128, 5.2113, 4.6969, 4.9268, 4.883, | |
4.8611, 4.6202, 4.5874, 4.193, 3.645, 3.9191, 4.4121, 4.0615, | |
3.5902, 4.1492, 4.7188, 4.5874, 4.5764, 4.3793, 4.1602, 4.1821, | |
3.8643), .Dim = c(40L, 2L)) | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the final picture, note how the black lines between the nodes (the pardalote's 40 spots) are not (all) Delaunay (but also not convex ...)