be-graphes-map-generator/README.md

176 lines
6.6 KiB
Markdown
Raw Permalink 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:
2021-10-07 12:39:06 +00:00
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:
2021-10-07 12:39:06 +00:00
- a script `coastline-fix.sh` to merge land/sea polygon (see below) and PBF files;
- multiple polygon (`.poly`) and bounding-box (`.bbox`) files for specific regions;
- PBF files downloaded organized in folder `$REGION/$REGION.pbf`.
2018-02-24 22:21:28 +00:00
- `outputs` is the default folder for generated output.
### Generating maps
2018-03-14 10:11:54 +00:00
This project can be used to generate two types of files:
- Graph file (`.mapgr`) containing graph information (see
2021-10-07 12:39:06 +00:00
[OSM2Graph](https://github.com/Holt59/OSM2Graph));
2018-03-14 10:11:54 +00:00
- Mapsforge file (`.mapfg`) containing [mapsforge](https://github.com/mapsforge/mapsforge)
2021-10-07 12:39:06 +00:00
data to display graph in a more visual way.
2018-03-14 10:11:54 +00:00
The process to generate the Mapsforge file is more complex than the one to generate graph file,
and it will often take much more time. Fortunately, it is often **not necessary** to generate
the Mapsforge file, because pre-generated files exist for most countries and regions.
Before generating the Mapsforge file, check if a file corresponding to the region you want
exists on the following server:
[http://download.mapsforge.org/maps/v4/](http://download.mapsforge.org/maps/v4/)
The hierarchy of this server is similar to [Geofabrik](http://download.geofabrik.de/), which
is the main source for our PBF files.
2018-02-27 19:07:28 +00:00
#### Step 1 - Obtaining a PBF file.
2018-02-24 22:21:28 +00:00
2018-03-14 10:11:54 +00:00
The first step is to 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/)
2018-03-14 10:11:54 +00:00
- If necessary, chop a region previously downloaded:
2018-02-24 22:21:28 +00:00
2021-10-07 12:39:06 +00:00
_Using a bounding box:_
2018-02-24 22:21:28 +00:00
2018-02-24 22:22:26 +00:00
```bash
2018-03-14 10:11:54 +00:00
bin/osmosis --rb inputs/europe/france/bretagne/bretagne.osm.pbf \ # Specify your input PBF
2018-02-27 19:07:28 +00:00
--bounding-box bottom=47.160000 left=-3.855000 top=48.330000 right=-1.915000 completeWays=yes \ # Specify the bounding bo
2018-03-14 10:11:54 +00:00
--write-pbf inputs/europe/france/bretagne/morbihan.pbf # Specify the output file
2018-02-24 22:21:28 +00:00
```
2021-10-07 12:39:06 +00:00
_Using a polygon:_
2018-02-24 22:55:31 +00:00
```bash
2020-07-15 14:24:59 +00:00
bin/osmosis --rb inputs/europe/france/bretagne/bretagne.osm.pbf \ # Specify your input PBF
--bounding-polygon file=inputs/europe/france/bretagne/morbihan.poly completeWays=yes \ # Specify your bounding polygon
--write-pbf file=inputs/europe/france/bretagne/morbihan.pbf # Specify your output file
2018-02-24 22:55:31 +00:00
```
2018-03-14 10:11:54 +00:00
The `inputs` 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-03-14 10:11:54 +00:00
**Important**: You can skip this step if your region does not contain sea or big inner
lakes, or if you do not want to generate the corresponding Mapsforge file.
2018-02-24 22:40:02 +00:00
2020-07-15 14:24:59 +00:00
You will need GDAL for this section, and the python bindings, you can usually install them
using a package manager:
```bash
2021-10-07 12:39:06 +00:00
# pip (better with a venv!)
pip install GDAL>=3
2020-07-15 14:24:59 +00:00
# Debian
2021-10-07 12:39:06 +00:00
sudo apt install gdal python-gdal
2020-07-15 14:24:59 +00:00
# CentOS
sudo yum install gdal gdal-python
```
2018-03-14 10:11:54 +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
2020-07-15 14:24:59 +00:00
cd inputs
2021-10-07 12:39:06 +00:00
./coastline-fix.sh europe/france/bretagne/morbihan.pbf
2018-02-24 22:40:02 +00:00
```
2018-03-14 10:11:54 +00:00
To apply the fix, you need a polygon file (`morbihan.poly` — not another name), 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-03-14 10:11:54 +00:00
- `inputs/europe/france/bretagne/morbihan.bbox`, actual bounding-box of the PBF file —
2021-10-07 12:39:06 +00:00
This will overwrite the old bounding-box if there was one.
2018-03-14 10:11:54 +00:00
- `inputs/europe/france/bretagne/morbihan_merge.pbf`, merged file that you should use as input
2021-10-07 12:39:06 +00:00
for mapsforge.
2018-02-24 22:40:02 +00:00
2018-03-14 10:11:54 +00:00
#### Step 2 - Generate graph & Mapsforge files
2018-02-27 19:07:28 +00:00
2018-03-14 10:11:54 +00:00
To generate both the graph file and the Mapsforge file corresponding to your input PBF,
you simply need to run the `generate.sh` script:
2018-02-24 22:40:02 +00:00
```bash
2018-03-14 10:11:54 +00:00
bash generate.sh inputs/europe/france/bretagne/bretagne.osm.pbf \
--id FR-E --name "Bretagne" \
--output outputs/bretagne
2018-02-24 22:40:02 +00:00
```
2018-03-14 10:11:54 +00:00
This command will generate two files: `outputs/bretagne.mapgr` and `outputs/bretagne.mapfg`,
you should not add the file extension when specifying `--output`.
You can get help about `generate.sh` by running:
2018-02-24 22:21:28 +00:00
2018-02-24 22:22:26 +00:00
```bash
2018-03-14 10:11:54 +00:00
bash generate.sh --help
```
2018-02-24 22:21:28 +00:00
2018-03-14 10:11:54 +00:00
If you use a merged file (`_merge.pbf`) file as input, you need to specify the corresponding
bounding-box:
```bash
bash generate.sh inputs/europe/france/bretagne/morbihan_merge.pbf \
--bounding-box inputs/europe/france/bretagne/morbihan.bbox \
2021-10-07 12:39:06 +00:00
--id FR-56 --name "Morbihan" \
--output outputs/morbihan
2018-03-14 10:11:54 +00:00
```
The script will automatically find the original file (`morbihan.pbf`) and use it to generate
the graph file (using the merged file can generate unexpected result... ).
If the input PBF file correspond to a region that has been cropped, it is better to specify
the polygon or bounding-box used for the generation of the PBF:
```bash
bash generate.sh inputs/europe/france/bretagne/morbihan_merge.pbf \
--bounding-box inputs/europe/france/bretagne/morbihan.bbox \
--bounding-polygon inputs/europe/france/bretagne/morbihan.poly \
2021-10-07 12:39:06 +00:00
--id FR-56 --name "Morbihan" \
--output outputs/morbihan
2018-02-27 19:07:28 +00:00
```
2018-02-24 22:21:28 +00:00
2018-03-14 10:11:54 +00:00
If both the `--bounding-box` and `--bounding-polygon` option are specified, the bounding-box
will be ignored for the generation of the graph file (the `--bounding-polygon` option has no
effect for the generation of the Mapsforge file).
2018-02-24 22:21:28 +00:00
2018-03-14 10:11:54 +00:00
You can generate only the graph file (`--graph-only`) or the Mapsforge file
(`--mapsforge-only`). With `--mapsforge-only`, the `--id` and `--name` options are not
required.