Functionality to handle and project lat-long coordinates, easily download background maps and add a correct scale bar to 'OpenStreetMap' plots in any map projection.
OSMscale
is an R package to easily handle and project lat-long coordinates,
download background maps and add a correct scale bar to 'OpenStreetMap' plots in any map projection.
There are some other spatially related miscellaneous functions as well.
OSMscale
is available on CRAN:
It relies on OpenStreetMap to do the actual work,
thus rgdal
and rjava
must be available.
On Windows: Check if Java is available.
There should be no errors when running install.packages("rJava") ; library(rJava)
in R.
If necessary, install Java in the same bit-version as R (eg 64bit).
The Java binary file must be on the search path,
which will normally happen automatically.
On Linux: open a terminal (CTRL+ALT+T) and paste (CTRL+SHIFT+V) the following line by line to install gdal and rJava:
sudo apt updatesudo apt install libgdal-dev libproj-devsudo apt-get install r-cran-rjavaRinstall.packages("rgdal")library("rgdal"); library("rJava") # should not return errorsq("no") # to quit R
OSMscale
from within R:install.packages("OSMscale") library(OSMscale)?OSMscale # To update to the most recent development version:berryFunctions::instGit("brry/berryFunctions")berryFunctions::instGit("brry/OSMscale")
Assuming a data.frame with lat-long coordinates:
d <- read.table(sep=",", header=TRUE, text="lat, long # could e.g. be copied from googleMaps, rightclick on What's here?55.685143, 12.58000852.514464, 13.35013750.106452, 14.41998948.847003, 2.33721351.505364, -0.164752")png("ExampleMap.png", width=4, height=3, units="in", res=150) map <- pointsMap(lat, long, data=d, type="maptoolkit-topo", proj=putm(d$long), scale=FALSE)scaleBar(map, abslen=500, y=0.8, cex=0.8)lines(projectPoints(d$lat, d$long), col="blue", lwd=3)points(projectPoints(52.386609, 4.877008, to=putm(zone=32)), cex=3, lwd=2, col="purple") dev.off()
If direct installation doesn't work, your R version might be too old.
In that case, an update is really recommendable: r-project.org.
If you can't update R, try installing from source (github) via instGit
as mentioned above.
If that's not possible either, you might be able to source
some functions from the
package zip folder
Vectorize(source)(dir("path/you/unzipped/to/OSMscale-master/R", full=T))
This creates all R functions as objects in your globalenv workspace (and overwrites existing objects of the same name!).
package OSMscale: project points and add a scalebar to OpenStreetMap plots. Feedback, ideas, code suggestions welcome at [email protected] or via github.com/brry/OSMscale
Version 0.5.0 (2017-04-12)
Version 0.4.1 (2017-01-19)
Version 0.3.5 (2016-09-21)
Version 0.2.9 (2016-08-21) first release on CRAN Detailed changes at https://github.com/brry/OSMscale/commits/master
documentation (examples + github readme) expanded + improved
scaleBar automatic length selection improved and abslen unit bug corected
projectPoints can now handle datasets with NAs
pointsMap: argument scale can now be a list of arguments
new functions: degree, earthDist, checkLL
new projection functions: putm, posm, pll
moved here from berryFunctions: equidistPoints, randomPoints, triangleArea
Version 0.2.1 (2016-07-27) second stable release
Version 0.1.7 (2016-06-21) first stable release with 3 functions: pointsMap, projectPoints, scaleBar Can download openstreetmap background map for a data.frame with points, project those (and the map itself) to UTM (or any other projection), draws accurate scalebars even in the default OSM mercator projection (currently minimalistic in design)