The International Simutrans Forum

 

Author Topic: Get Simutrans maps with rivers from OpenStreetMap data  (Read 833 times)

0 Members and 1 Guest are viewing this topic.

Offline isidoro

  • Devotee
  • *
  • Posts: 1124
Get Simutrans maps with rivers from OpenStreetMap data
« on: August 13, 2018, 10:18:59 PM »
I plan to post here the scripts and programs I've developed that can be used to build Simutrans maps with rivers (and possible cities) with data obtained from OpenStreetMap.

All the work have been done for Linux and is in a state that requires medium/advance knowledge of programming and operating system.  For example, the ability to install the libraries/programs needed from standard packages.

I plan to post it in three steps:
1) MAPS
2) RIVERS
3) SCENARIOS

So first part is MAPS.  Just make a new directory named SIMUTRANSMAPS and, inside it, create another one named MAPS.  In that, expand the attached file maps.tar.gz

You will see a Makefile.  Just make.  Solve the problems about dependencies by installing the appropriate packages (for instance, but not limited to, graphicsmagick-libmagick-dev-compat).  If everything goes alright, you'll get a "map" executable.  That will convert a GeoTiff map to a bmp, suitable to be used for ST with waterlevel of -10.

Get one of such GeoTiff maps (with embedded elevation), for example let's say its name is sicilia.tiff.  Convert it to map.bmp with the above program and create a directory for that map, for instance, SICILIA.  Move map.bmp inside SICILIA.  Create a directory named RIVERS inside SICILIA.

You have to add an XML file named "map.xml" inside SICILIA, that will describe the properties of your map.  You can follow the example inside IBERIA directory.

The format is:
<?xml version="1.0" encoding="UTF-8"?>
<map imageFileName="map.bmp" startYear="1850" waterLevel="-10"
     industryIncreaseEvery="100000"
     heightMapConversionVersion="1" maximizeHeightLevels="1">
  <coordinates lats="35,44.5" longs="-10,4.5"/>
  <climates desert="-10" tropical="-8" mediterranean="2"
            temperate="4" tundra="6" alpine="10"/>
  <rivers>
    <river name="Alagón" coords="RIVERS/TAJO/Alagón.2918666.coords"/>
    [...]
  </rivers>
  <cities populationSimPopulationRatio="200">
  </cities>
</map>

Of course, you have to change the data to suit you map.  In particular, the latitude and longitude range of you map.
Never mind about the river data now.  It will be covered in the next chapter.  And also about getRiverMapCoordinates.sh,
it will be used later.

The script convertLatLongToMapCoordinates.sh can be used to convert geographical coordinates to map coordinates and back.

Offline isidoro

  • Devotee
  • *
  • Posts: 1124
Re: Get Simutrans maps with rivers from OpenStreetMap data
« Reply #1 on: August 14, 2018, 10:56:43 PM »
CHAPTER 2: RIVERS

In order to populate the map with rivers, we need the coordinates of the points that make up the river.  We are going to retrieve that from OpenStreetMap data.  It isn't easy, since the information found there although mostly amazing, sometimes it is incomplete or difficult to retrieve.  It also varies greatly among different world zones, depending on people collaboration in the project. [[N.B. the site is slow these days, so some of the scripts or tests may not work as expected]]

In OpenStreetMap, there are different objects that can appear in a certain map.  Each object has a unique Id.  Among all objects, one can find "ways".  We are interested in "water ways".  But, a certain river isn't a water way but is made of water ways and constitutes what is known as a "relation" in OSM jargon.  If we are lucky, we can find a relation that groups all the river data, but sometimes, we haven't that or the relation is incomplete and some parts of the river are missing.

For example, let's take river Duero, the first one I made.  Open http://www.openstreetmap.org, and search for "Duero".  You won't find anything useful, but if you search for "río Duero", at the end, you find:
River Douro, Valladolid, Castile and León, 09417, Spain
that links to:
https://www.openstreetmap.org/relation/2566210

Hooray! As you can see in the hyperlink, that's a relation.  The Id of that relation is 2566210.  Just click on the link and you'll get to a map with the river drawn.

There's an API that lets any programmer retrieve the information stored in OSM.  Using that in the scripts, we can get the coordinates of the rivers we are interested in and add it to the MAP directory of chapter one.  Note that that information in the MAP directory is in geographical coordinates.  Reason is that this way the data is reusable for different maps.  If coordinates of the points of the river were stored in map coordinates or our Simutrans map, they wouldn't be useful for other maps.

If you want information for tributaries, you have to get those too.

So, following the example above, make (or go to) a directory named RIVERS inside SICILIA map.  Inside that, you'll create files with the geographical coordinates of the rivers.  I prefer to group them in basins, that is, I create a directory named "DUERO" and inside it, place all the .coords files of Duero itself and all its tributaries.  For each of the files you create, you have to write the corresponding line in the <rivers> section of the map.xml file.

Just create a directory named RIVERS inside SIMUTRANSMAPS.  Go inside it, and expand the attached file: rivers.tar.gz.  The scripts speak for themselves and also there is a readme.txt file.  You can also find an example of one of such coords files.  It isn't the file for Duero coordinates because the file exceeds the 64kb limit for attachments in the forum.  It is for river Tormes, one of the tributaries of river Duero.