Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dietercastel/OSMap.r
Create custom (OSM-based) map plots using R (et alii).
https://github.com/dietercastel/OSMap.r
Last synced: 3 months ago
JSON representation
Create custom (OSM-based) map plots using R (et alii).
- Host: GitHub
- URL: https://github.com/dietercastel/OSMap.r
- Owner: dietercastel
- Created: 2019-12-12T05:49:33.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-21T15:05:15.000Z (over 4 years ago)
- Last Synced: 2024-08-06T03:04:02.141Z (7 months ago)
- Language: R
- Homepage:
- Size: 358 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](apache.be) 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:
- The web based [OpenLayers](https://openlayers.org/en/latest/examples/)
- Java driven [OpenStreetMap r package](https://cran.r-project.org/web/packages/OpenStreetMap/index.html)## 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](https://docs.docker.com/config/containers/resource_constraints/#--memory-swap-details) or do it in your docker preferences.After installing docker pull the required container (with R and all required libraries installed.)
```bash
./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:
- Fetch tiles from an OSM tile server
- Use the Overpass Query API to query some feature (here the "amenity" "bookcase") (see this page for other options https://wiki.openstreetmap.org/wiki/Map_Features)### 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.
```bash
#~/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"
```
2) run the download script from the folder osmtiling
```bash
#~/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
```3) Run the book cases example with the same string.
The r script run is [dockerMakeBookcases.r](https://github.com/dietercastel/OSMap.r/blob/master/dockerMakeBookcases.r) with the given command line argument inside the docker container.
```bash
cd ..
#~/git/OSMap.r · (master±)
./runBookcases.sh "Oostende,Belgium"
# "Look in the /output folder."
```4) Possibly trim the white edges
Requires python3 and Pillow installed.
```bash
./trimImages.py output/bookcases.png
```
Result should look like:
5) 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:
```bash
#~/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:
```bash
cd /tmp/wmleuv
r dockergeocode.r # required only once for generating necessary Rdata files.
r dockerMakeFrames.r
```Alternative example files run similarly
```bash
# 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](https://imagemagick.org/script/download.php) installed run:
`./makeGif.sh`
### For webms
With the excellent [ffmpeg](https://ffmpeg.org/) 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](https://www.apache.be/2020/01/08/leuvense-anpr-cameras-filmen-zonder-reden/)

[Winkeldief of shopper: Leuven filmt u, 24/7](https://www.apache.be/2020/01/09/hoe-leuven-een-gefilmde-stad-werd/)

[De Leuvense Privacy-wandeling van Apache](https://www.facebook.com/events/openbaar-entrepot-voor-de-kunsten-opek/volzet-apache-lokaal-de-slimme-stad/1208596742863953/)

All public book cases listed on OSM around 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