A project about creating a beautiful map of trains for a selected area.
- .NET 10.0
- Clone the repository
- Obtain the data from OpenStreetMap as an .osm.pbf file and save it in
data/raw. You can use Geofabrik to download the data. - Filter the data. You can use Osmium to filter the data. The final file should be
data/raw/rails.osm.pbfThe following command will filter the data to only include railways and save it indata/raw:
# Obtain only railway related
osmium tags-filter -o rails.osm.pbf -t --output-format pbf,add_metadata=false europe-latest.osm.pbf "w/railway=bridge,goods,light_rail,monorail,narrow_gauge,rail,subway,tram"- Run the program
dotnet run --project TRAINer- The output will be saved as
data/output/rails.pngordata/output/rails.svg, depending on--format. Rendering a large area as SVG can produce a very large file.
Additional command line arguments can be passed to the program. The following arguments are available:
| Argument | Description | Default |
|---|---|---|
--data |
The path to the data directory | data |
--min-lat |
Minimum latitude of the area to be processed | -90 |
--max-lat |
Maximum latitude of the area to be processed | 90 |
--min-lon |
Minimum longitude of the area to be processed | -180 |
--max-lon |
Maximum longitude of the area to be processed | 180 |
--color-main |
Color of the railway with the largest gauge. Colors are interpolated between the main and secondary color. | #FFBA4A |
--color-secondary |
Color of the railway with the smallest gauge. Colors are interpolated between the main and secondary color. | #D5B690 |
--color-background |
Color of the background | #1E1414 |
--min-track-width |
Track width in pixels used for the slowest lines | 3 |
--max-track-width |
Track width in pixels used for the fastest lines | 23 |
--transport-color |
Override the color used for a given OSM railway tag value (e.g. subway, rail). Matching is case-insensitive. Run list-types to discover the valid mode names for your data. Repeatable, e.g. --transport-color subway=FFFFFF --transport-color tram=FF0000 or --transport-color subway=FFFFFF tram=FF0000 |
(none) |
--format |
Output image format, png or svg |
png |
--width |
Maximum width of the output image in pixels | 20000 |
--height |
Maximum height of the output image in pixels | 20000 |
--margin |
Blank space in pixels kept on every side of the map, inside the output image | 500 |
--width and --height are a maximum bounding box, not a fixed size. The output is scaled to
the real-world aspect ratio of the selected area (latitude-compensated, so it's not simply the
lon/lat span), so one dimension may come out smaller than requested but neither ever exceeds it.
The aspect ratio follows whatever --min-lat/--max-lat/--min-lon/--max-lon select. For
example, the default 20000x20000 box over all of Europe produces a 15169x20000 image.
--margin is blank space kept on every side, inside the output image. It's the drawn map that
carries the area's aspect ratio, so the margin is subtracted before fitting that ratio and added
back afterwards - the canvas therefore still never exceeds --width/--height. Continuing the
example above, --margin 500 fits the map into 19000x19000 rather than 20000x20000, so the map is
drawn proportionally smaller and the 500px border is added back around it; the image as a whole
still fits within the requested 20000x20000.
The list-types subcommand lists each railway type found in the data and how many ways use it,
most common first. Names are printed to stdout so the list can be piped, while progress messages
go to stderr. These are exactly the values --transport-color accepts.
dotnet run --project TRAINer -- list-typesdotnet testThis project is licensed under the MIT License - see the LICENSE file for details.
This project uses the OsmSharp, SkiaSharp and System.CommandLine libraries.
