This Week’s Widget -
Even a geo-novice like me can quickly see the amazing power of
mapshaper and its web gui and even use it immediately. The author has clearly focused on a speedy, intuitive, but still full-feautured user experience. To take it one step further though, let’s try to integrate mapshaper seamlessly into our
R geospatial workflow.
For now, I chose the awkward name
mapshaperWidget, since “mapshaperr” is a little hard and there already is
rmapshaper to use the non-gui node.js version. I’m thinking if ok with the author, eventually I can fold
mapshaper is an entire website, so converting it to an
htmlwidget is much different from most of the other conversions. As of now,
mapshaperWidget is not composeable and will not integrate into
rmarkdown, since it completely takes over the page. In later iterations, I hope to contain it. Not true after August 15, 2015, mapshaper fits nicely in its own little container for rmarkdown and Shiny.
mapshaperWidget relies on
geojsonio. Thanks to the contributors for this very helpful package. I also enjoyed adding some lazy magic from Hadley Wickham’s
lazyeval. Also, one last thanks to RStudio for integrating RStudio Viewer, which allows for a smooth all-in-one window experience.
mapshaperWidget is not yet on CRAN, so for now please install with
Examples usually help more than text. Let’s see if this is true.
# devtools::install_github("timelyportfolio/mapshaperWidget") library(mapshaperWidget) alabama <- paste0( readLines( "https://raw.githubusercontent.com/glynnbird/usstatesgeojson/master/alabama.geojson" ) ,collapse = " " ) mapshaper(alabama)
World Data from tmap
tmap will give us a good example of working with
mapshaper. Play with it a bit, and see if you can filter from the console.
# devtools::install_github("timelyportfolio/mapshaperWidget") library(mapshaperWidget) library(tmap) data(World) mapshaper(World)
Multiple Spatial Objects
Now, let’s incorporate some examples from
spdep to show how we can analyze multiple spatial objects with
mapshaper. Remember, you can always drag and drop shapefiles, geojson, topojson files onto your
mapshaper. I highly recommend trying it out with the shapefiles from
# devtools::install_github("timelyportfolio/mapshaperWidget") library(mapshaperWidget) library(spdep) library(maptools) auckland <- readShapePoly( system.file( "etc/shapes/auckland.shp" ,package="spdep" ) ) wheat <- readShapePoly( system.file( "etc/shapes/wheat.shp" ,package="spdep" ) ) columbus <- readShapePoly( system.file( "etc/shapes/columbus.shp" ,package="spdep" ) ) mapshaper( auckland, wheat, columbus )
This is certainly not all, but I’ll stop here. Next step will be bidirectional communication with
Shiny and as said earlier some containment for composeability. As always, I would love to work together if you have some ideas.
Thanks so much to Matthew Bloch from the New York Times for
mapshaper. It is really good!
As always, thanks to
- Ramnath Vaidyanathan and RStudio for
- all the contributors to