Skip to content

Create custom (OSM-based) map plots using R (et alii).

Notifications You must be signed in to change notification settings

dietercastel/OSMap.r

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OSMap.r

Creating custom (OSM-based) maps with R

This project uses:

  • R scripts (inside Docker for generating map-based visualisations)
  • Python 3 scripts (for post-processing generated images, downloading OSM tiles/some preprocessing)
  • Bash scripts (for minor things)
  • Julia scripts (for one-of things, (my legacy, sorrynotsorry.))

Disclaimer

This was mainly a project for me to experiment with R (and ggplot) while working on a (hobbyist) data visualization for Apache and it got a bit out of hand. While it's certainly usable to create static custom maps, for more potent, dynamic, capabilities there exist better tools such as:

Docker

You might want to increase your docker memory & swap file size (in Preferences/Advanced) because R has a crashing tendency when not given enough resources. See run options here or do it in your docker preferences.

After installing docker pull the required container (with R and all required libraries installed.)

./pullDockerContainers
# or well just atm
# docker pull robinlovelace/geocompr 

Now you're all set!

Book case example

This will step you to the bookcase example. Which comes down to this:

Keep in mind the Tile server/Overpass Query API policy.

  1. Get the bounding box and generate a script for downloading the required map tiles.
#~/git/OSMap.r · (master±)
./runPrintBB.sh "Oostende,Belgium"
#[1] "Oostende,Belgium"
#Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
#[1] "Oostende,Belgium"
#[1] "./osm_tile_downloaderBB.py 51.2455721 2.8386276 51.1846337 3.0035408"
#[1] "Executable file written: /tmp/wmleuv/osmtiling/tileDLBB-Oostende,Belgium.sh"
  1. run the download script from the folder osmtiling
#~/git/OSMap.r · (master±)
cd osmtiling/
#~/git/OSMap.r/osmtiling · (master±)
./tileDLBB-Oostende,Belgium.sh
#14:8321-8328/5467-5471
#be/14-8321-5471.png
#downloading 'https://tile.openstreetmap.be/osmbe/14/8321/5471.png'
....
# tiles are in osmtiling/be
  1. Run the book cases example with the same string.

The r script run is dockerMakeBookcases.r with the given command line argument inside the docker container.

cd ..
#~/git/OSMap.r · (master±)
./runBookcases.sh "Oostende,Belgium"                                                                                        
# "Look in the /output folder."
  1. Possibly trim the white edges

Requires python3 and Pillow installed.

./trimImages.py output/bookcases.png

Result should look like: Book cases in Oostende as of 15-06-2020

  1. You can add text and logos by tweaking the addLogo.py script.

Other (older) examples.

These can be run from within the docker container atm best checkout the wmleuv branch for all the required files.

Then run a command prompt in the docker container with:

#~/git/OSMap.r · (wmleuv)
./docker.sh

This will take you inside the docker container ready to run the r scripts.

The repository map is synced under /tmp/wmleuv by the docker script and if you open that folder inside the container you can run scripts like:

cd /tmp/wmleuv
r dockergeocode.r # required only once for generating necessary Rdata files.
r dockerMakeFrames.r 

Alternative example files run similarly

# Smallest and most trivial example plotting book cases in Leuven.
r dockerMakeLeuvenBookcases.r
r dockerMakeSmallFrames.r
# Incorporating a GPX track:
r dockerMakeWandeling.r
# Overlaying other images:
r dockerANPROverlay.r

The output is placed inside output directory.

Gif/webm making

Prep

Trim the white edges

./trimImages.py imageName

Next with python 3 and pillow installed run: ./addLogo.py

For gifs

Finally with imagemagick convert installed run:

./makeGif.sh

For webms

With the excellent ffmpeg installed you can run.

./makeWebm.sh

Which results in a modern, smaller webm in ./output instead.

Projects using this toolchain

Leuvense ANPR-camera’s filmen je zonder reden

ANPR camera's in het stadscentrum van Leuven

Winkeldief of shopper: Leuven filmt u, 24/7 Toenemende gefilmde straten in het centrum Leuven 2005,2013,2020

Toenemende gefilmde straten regio ring van Leuven 2005,2013,2020

De Leuvense Privacy-wandeling van Apache

Wandeling door het Leuvense stadscentrum.

All public book cases listed on OSM around Leuven: Publieke boekenkasten op OpenStreetMaps in Leuven

License

Since the used data is derived from the OpenStreetMap data (using the overpass API) I think the Open Database License applies here. https://en.wikipedia.org/wiki/Open_Database_License

About

Create custom (OSM-based) map plots using R (et alii).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published