be-graphes-map-generator/README.md

108 lines
4.7 KiB
Markdown
Raw Normal View History

2018-02-24 22:21:28 +00:00
### Map generator for "BE Graphes"
2018-02-24 23:01:48 +00:00
The purpose of this repository is to ease the process of generating graph and mapforge file that are consistent (using the same OpenStreetMap data).
### How to start?
2018-02-24 22:21:28 +00:00
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.
### Generating maps
2018-02-27 19:07:28 +00:00
#### Step 1 - Obtaining a PBF file.
2018-02-24 22:21:28 +00:00
2018-02-27 19:07:28 +00:00
You should create a PBF files containining the region you want:
2018-02-24 22:21:28 +00:00
2018-02-27 19:07:28 +00:00
- Download a complete region from Geofabrik: [http://download.geofabrik.de/](http://download.geofabrik.de/)
- Chop a region previously downloaded:
2018-02-24 22:21:28 +00:00
2018-02-27 19:07:28 +00:00
*Using a bounding box:*
2018-02-24 22:21:28 +00:00
2018-02-24 22:22:26 +00:00
```bash
2018-02-27 19:07:28 +00:00
bin/osmosis --rb inputs/bretagne/bretagne-latest.osm.pbf \ # Specify your input PBF
--bounding-box bottom=47.160000 left=-3.855000 top=48.330000 right=-1.915000 completeWays=yes \ # Specify the bounding bo
--write-pbf inputs/bretagne/morbihan.pbf # Specify the output file
2018-02-24 22:21:28 +00:00
```
2018-02-27 19:07:28 +00:00
*Using a polygon:*
2018-02-24 22:55:31 +00:00
```bash
2018-02-27 19:07:28 +00:00
osmosis --rb inputs/bretagne/bretagne-latest.osm.pbf \ # Specify your input PBF
--bounding-polygon file=inputs/bbox/morbihan.poly completeWays=yes \ # Specify your bounding polygon
--write-pbf file=inputs/bretagne/morbihan.pbf # Specify your output file
2018-02-24 22:55:31 +00:00
```
2018-02-27 19:07:28 +00:00
The `inputs/bbox` directory contains bounding-box (`.bbox`) and bounding polygon (`.poly`) for some regions. You can find polygon for a lots of region here: [http://polygons.openstreetmap.fr/index.py](http://polygons.openstreetmap.fr/index.py) (to find the id of the relation, search it on openstreetmap, e.g. [https://www.openstreetmap.org/relation/7447](https://www.openstreetmap.org/relation/7447)).
2018-02-24 22:55:31 +00:00
2018-02-27 19:07:28 +00:00
#### Step 1 Bis - Fixing coastlines and sea.
2018-02-24 22:55:31 +00:00
2018-02-27 19:07:28 +00:00
Skip this step if your region does not contain sea or big inner lakes, or if you do not want to generate mapsforge file.
2018-02-24 22:40:02 +00:00
2018-02-27 19:07:28 +00:00
We need to add sea information to the PBF file to generate a correct mapsforge map. To do so, a script `coastline-fix.sh` is provided. Run it simply:
2018-02-24 22:40:02 +00:00
```bash
2018-02-27 19:07:28 +00:00
./coastline-fix.sh bretagne/morbihan.pbf
2018-02-24 22:40:02 +00:00
```
2018-02-27 19:07:28 +00:00
To apply the fix, you need a polygon file (`morbihan.poly` — not another name), either in the same directory as the PBF or in the `inputs/bbox` directory (recommended).
2018-02-24 22:40:02 +00:00
2018-02-27 19:07:28 +00:00
This script will generate multiple intermediate files, but only two are importants:
2018-02-24 22:40:02 +00:00
2018-02-27 19:07:28 +00:00
- `inputs/bbox/morbihan.bbox`, actual bounding-box of the PBF file — This will overwrite the old bounding-box if there was one.
- `inputs/bretagne/morbihan_merge.pbf`, merged file that you should use as input for mapsforge.
2018-02-24 22:40:02 +00:00
2018-02-27 19:07:28 +00:00
#### Step 2 - Binary graph files
2018-02-24 22:40:02 +00:00
```bash
2018-02-27 19:07:28 +00:00
# You can use either "insa2016" or "insa2018" writers, and you should change the map id to your need.
bin/osmosis --rb inputs/bretagne/morbihan.pbf \
--used-node \
--tf reject-relations \
--tf accept-ways highway=(cat inputs/highway-filter.cmd) natural=coastline \
--osm2graph file=outputs/morbihan.mapgr writer=insa2018 map-id=0x235
2018-02-24 22:40:02 +00:00
```
2018-02-27 19:07:28 +00:00
#### Step 3 - Mapsforge files
2018-02-24 22:21:28 +00:00
2018-02-24 22:22:26 +00:00
```bash
2018-02-27 19:07:28 +00:00
# You must specify a bounding-box if you used the coastline fix.
# You can use type=ram to speed-up the process for small maps.
bin/osmosis --rb inputs/bretagne/morbihan_merge.pbf \
--mapfile-writer file=outputs/morbihan.mapfg bbox=$(cat inputs/bbox/morbihan.bbox) type=hd threads=2
2018-02-24 22:21:28 +00:00
2018-02-27 19:07:28 +00:00
```
2018-02-24 22:21:28 +00:00
2018-02-27 19:07:28 +00:00
#### Extra informations:
2018-02-24 22:21:28 +00:00
2018-02-27 19:07:28 +00:00
- Using a polygon to crop your region is preferred if you plan on applying the coastline fix.
- I do not recommend using the merged file as input for `osm2graph` because coastlines are often very long OpenStreetMap ways, and the plugin will not cut them (typically, you could reach Spain when using the merged Morbihan file).
- I do not recommend using `osmosis` bounding-box option with `osm2graph` and/or `mapfile-writer` unless your bounding-box is small and does not contain sea or coastline. It is always preferred to generate an intermediate PBF file containing only your region (using `--write-pbf`).