be-graphes-map-generator/README.md

133 lines
4.8 KiB
Markdown
Raw Normal View History

2018-02-24 22:21:28 +00:00
### Map generator for "BE Graphes"
To clone this repository:
2018-02-24 22:22:26 +00:00
```bash
2018-02-24 22:21:28 +00:00
# You need the --recursive option (--recurse-submodules with Git >= 2.13),
# you can use https or ssh, it does not matter.
git clone --recursive https://gitea.typename.fr/INSA/be-graphes-map-generator.git
# Then you need to initialize the repository, this may takes some time as it needs
# to fetch a shapefile (~500MB) on a remote server.
cd be-graphes-map-generator
bash init.sh
```
If you do not plan on generating maps with coastline for mapsforge (see below), you can use the `--no-shapefile` option
to avoid the download:
2018-02-24 22:22:26 +00:00
```bash
2018-02-24 22:21:28 +00:00
bash init.sh --no-shapefile
```
### Folders organization
The two main folders are `inputs` and `outputs`:
- `inputs` mainly contains:
- a script `coastline-fix.sh` to merge land/sea polygon (see below) and PBF files;
- a directory containing boundinx-box (`bbox`) for specific regions;
- a file containing highway filters;
- PBF files downloaded organized in folder `$REGION/$REGION.pbf`.
- `outputs` is the default folder for generated output.
### Obtaining PBF files
You can download PBF files for multiple regions on Geofabrik: [https://download.geofabrik.de/index.html](https://download.geofabrik.de/index.html)
You should put the PBF file in subfolders, e.g. if you want to use `bretagne.pbf`, you should save it to:
2018-02-24 22:22:26 +00:00
```bash
2018-02-24 22:21:28 +00:00
inputs/bretagne/bretagne.pbf
```
Doing so will avoid having a messy `inputs` folder due to region-specific files generated by `coastline-fix.sh`.
### Generating maps
2018-02-24 22:55:31 +00:00
Only manual generation using `osmosis` is supported currently.
2018-02-24 22:21:28 +00:00
#### Mapsforge file:
2018-02-24 22:22:26 +00:00
```bash
2018-02-24 22:21:28 +00:00
# You do not need to specify a bounding-box if you did not use the coastline fix or
2018-02-24 23:00:21 +00:00
# do not want it. You can use type=ram to speed-up the process for small maps.
2018-02-24 22:21:28 +00:00
bin/osmosis --rb inputs/bretagne/bretagne_merge.pbf \
2018-02-24 23:00:21 +00:00
--mapfile-writer file=outputs/morbihan.mapfg bbox=47.234,-3.598,47.997,-1.648 type=hd threads=2
2018-02-24 22:21:28 +00:00
```
#### Binary graph files
2018-02-24 22:22:26 +00:00
```bash
2018-02-24 22:21:28 +00:00
# You do not need to specify a bounding box if you do not need it. You can use either "insa2016" or
# "insa2018" writers, and you should change the map id to your need.
bin/osmosis --rb inputs/bretagne/bretagne-latest.osm.pbf \
--used-node --bounding-box top=48.1749 left=-1.7709 right=-1.5014 bottom=48.0644 completeWays=yes \
--tf reject-relations --tf accept-ways highway=(cat inputs/highway-filter.cmd) natural=coastline --lp \
--osm2graph file=outputs/rennes.mapgr writer=insa2018 map-id=0x235
```
2018-02-24 22:55:31 +00:00
#### Combining generations
You can combine both generation using the `--tee` option of `osmosis`:
```bash
# The order is important! You do not want to use osmosis filters/bounding-box before mapfile-writer.
bin/osmosis --rb inputs/bretagne/bretagne_merge.pbf --tee \
2018-02-24 23:00:21 +00:00
--mapfile-writer file=outputs/morbihan.mapfg bbox=$(cat inputs/bbox/morbihan.bbox) type=hd threads=2 \
2018-02-24 22:55:31 +00:00
--bounding-box $(cat inputs/bbox/morbihan.bbox | tr "," " " | xargs printf "bottom=%f left=%f top=%f right=%f") completeWays=yes
--used-node --tf reject-relations --tf accept-ways highway=(cat inputs/highway-filter.cmd) natural=coastline
--osm2graph file=ouputs/morbihan.mapgr writer=insa2018 map-id=0x400
```
**Note**: You can add logging by specifying `--lp` between `osmosis` tasks.
2018-02-24 22:40:02 +00:00
### Bounding box
Bounding box files should contain a single line with comma-separated (**without spaces**) values:
```bash
minLat,minLon,maxLat,maxLon
```
To use it with `osmosis`:
- for `mapfile-writer`, simply `cat` the file to set the `bbox` argument:
```bash
bbox=$(cat inputs/bbox/morbihan.bbox)
```
- for `osm2graph`, it is a bit more complicated:
```bash
--bounding-box $(cat inputs/bbox/morbihan.bbox | tr "," " " | xargs printf "bottom=%f left=%f top=%f right=%f") completeWays=yes
```
2018-02-24 22:21:28 +00:00
### Fixing coastline
When generating mapsforge file that contains sea, you will need to fix the PBF file prior to running osmosis.
The fix is an adaptation from [https://github.com/mapsforge/mapsforge-creator](https://github.com/mapsforge/mapsforge-creator)
— It basically does the same but does not download PBF or do the final osmosis run for you.
You will first need a PBF file and its associated polygon file, you can get these from [https://download.geofabrik.de/index.html](https://download.geofabrik.de/index.html). You need to put those file in a region folder, e.g. if you want to fix `bretagne`, you should have:
2018-02-24 22:22:26 +00:00
```bash
2018-02-24 22:21:28 +00:00
# Do not rename these files!
inputs/bretagne/bretagne-latest.osm.pbf
inputs/bretagne/bretagne.poly
```
You should also have run the `init.sh` script without the `--no-shapefile` option (you should see a folder named `land-polygons-split-4326` in the `inputs` folder).
Once you have the requested files, you can simply run (from the `inputs` folder):
2018-02-24 22:22:26 +00:00
```bash
2018-02-24 22:21:28 +00:00
# If you are not already in the inputs folder
cd inputs
# Change bretagne to whatever region...
bash coastline-fix.sh bretagne
```