rmapshaper
rmapshaper copied to clipboard
Implement more mapshaper commands
https://github.com/mbloch/mapshaper/wiki/Command-Reference
- [x] simplify
- [x] clip
- [x] erase
- [x] dissolve
- [x] explode
- [x] lines
- [x] innerlines
- [x] points
- [ ] snap (#161)
- [ ] join
- [ ] each ??
- [ ] filter
- [x] filter-islands
- [x] filter-fields
- [ ] rename-layers
- [ ] rename-fields
- [ ] merge-layers
- [ ] calc
- [ ] clean
- [ ] polygon-grid (https://github.com/mbloch/mapshaper/issues/238)
- [ ] affine
- [ ] filter-slivers
- [ ] point-grid
- [ ] rectangle
- [ ] filter-slivers
- [ ] split
- [ ] split-on-grid
- [ ] graticule
- [ ] mosaic
@ateucher, you're doing very fine work. Unfortunately, my domain ignorance is preventing me from helping much, but I am following along. Let me know if I can do anything.
Thanks @timelyportfolio! I'm really close to having something that people can kick the tires of. I'm trying to get all the methods implemented and tested for the five core functions checked above (simplify
, erase
, clip
, dissolve
, explode
) before I put a note on Twitter asking people to try it out and provide feedback.
Any time you want to try to incorporate your widget is fine by me - but no rush :)
Could you also add the convert feature. It might come in handy for converting to/from various formats w/o needing rgdal. Also I found that reading topojsons exported from https://pitchinteractiveinc.github.io/tilegrams/, using either rgdal or geojsonio doesn't quite work, but if I export that topojson to a shapefile using mapshaper then the resulting shapefile works well. So there's a use case for supporting convert function.
Hi @bhaskarvk, thanks for the note.
By convert, do mean the format
output option listed here? Unfortunately the -o
options aren't currently exposed in the mapshaper command line API, so that's not currently possible. I will think on it a bit more though
As for the topojson read issue, could you open up an issue in https:/github.com/ropensci/geojsonio?
Hello, Thanks for making this package! Any plans to add a mosaic function? It would be super useful for analyzing polygons that change through time.
Hi @ifoxfoot - just to be clear, are you referring to implementing the mosaic command available in the mapshaper javascript library? Or a mosaic in the ArcGIS sense? If the former, then happy to add it to the roadmap, but if the latter it would be out of scope as mapshaper (and hence rmapshaper) doesn't deal with raster data.
@ateucher the one in the mapshaper library. I want to flatten some polygons together. Thanks for responding!
You should be able to achieve what you're after with sf::st_intersection()
- when given a single layer it intersects with itself. You can also try with rmapshaper::apply_mapshaper_commands()
- it's not well documented and only works with geojson objects, but can apply any of the mapshaper commands, even if they're not implemented with their own function in rmapshaper
:
library(rmapshaper)
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE
m = rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0))
p = st_polygon(list(m))
n = 10
l = vector("list", n)
for (i in 1:n)
l[[i]] = p + 3 * runif(2)
s = st_sfc(l)
plot(s, col = sf.colors(categorical = TRUE, alpha = .5))
i = st_intersection(s)
plot(i, col = sf.colors(categorical = TRUE))
title("non-overlapping intersections")
s_geojson <- rmapshaper:::sf_to_GeoJSON(s)
j <- apply_mapshaper_commands(s_geojson, "-mosaic") |>
rmapshaper:::GeoJSON_to_sf()
plot(st_as_sfc(j), col = sf.colors(categorical = TRUE))
Created on 2022-10-27 with reprex v2.0.2
@ateucher I keep running into this bug with very large/messy datasets when I use st_intersection
(although maybe it's fixed now with GEOS 3.10, I haven't tried in awhile). I will try apply_mapshaper_commands()
though! Thanks!