A script to generate heightmaps from real-world elevation data

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
bba
Engineer
Engineer
Posts: 8
Joined: 25 Aug 2020 19:16

A script to generate heightmaps from real-world elevation data

Post by bba »

After trying to create a decent heightmap of Ireland and spending a bit of time playing around with various image and GIS editors, I wrote a script to automate (to an extent) the process of creating a heightmap from real-world elevation data. Basically, you feed it the coordinates you want and it will fetch the relevant elevation data from this website and convert it to a greyscale PNG that OpenTTD can load. It can also perform some basic manipulation of the data that could help you get a better heightmap.

Rather than talk about it here I will simply direct you to the README on GitHub which explains how to install and use it. It does require some (not too much) familiarity with the command line and Python. In addition I've only tested it on Linux, I would guess it should work okay on Mac but from googling around it seems like it's difficult to install the necessary dependencies on Windows . Nevertheless, hopefully some of you find this helpful. Thanks!

personman
Engineer
Engineer
Posts: 1
Joined: 19 Sep 2020 18:45

Re: A script to generate heightmaps from real-world elevation data

Post by personman »

Thank you for making this! It installed on my Mac with no issue (I already had python 3). I had so much fun with this that I wanted to build a GUI for it. I've got a working prototype now, but I want to add controls for more of your code's options and clean it up for production. Any objection to me deploying this to a server so people can use your script via a website? Here's a preview:

Image

bba
Engineer
Engineer
Posts: 8
Joined: 25 Aug 2020 19:16

Re: A script to generate heightmaps from real-world elevation data

Post by bba »

Hi personman - I already said this on Reddit, but this looks great! I have no issue with you deploying this on a server to give people a more user-friendly interface, it sounds like a great idea. Someone else on Reddit is trying to incorporate Bother into a script to generate real-world scenarios (with realistic town placement). I'm happy to see that it's helping other people build their own useful tools.

Of course some attribution / link to the original source would be appreciated.

As a more general update, since the original post I have (with the help of another user on Github who contributed some of the pull requests) implemented a number of bugfixes and a couple of new features / behaviour changes, including:
  • a .bat file for Windows, allowing "bother" to be used from the CLI;
  • better handling of directory paths;
  • a progress bar for downloading SRTM data;
  • better handling of land at sea level; and
  • use of the Web Mercator projection (EPSG 3857) as the default projection for the heightmaps.
The new release has been uploaded to PyPI and the AUR as v1.0.

Guillo2900
Engineer
Engineer
Posts: 2
Joined: 07 Jun 2015 23:44
Location: Argentina

Re: A script to generate heightmaps from real-world elevation data

Post by Guillo2900 »

Hi!

I was very happy when I knew about the site http://map.personman.com, I thought finally I can have my personalized heightmaps. It's very simple to use, but maybe I'm doing something wrong.

I search a city in my country, then I define the capture box, and generate the image. Sometimes it just stays generating, but most of the times the imagen comes up fine. The thing is that I don't recognize the zone that I've delimitated.

I'm sorry to bohter you with this things, but I don't know if I'm doing something wrong, the map is fine but I can't recongize the zone as I see it in the common map or what...

I attach what I see. Thank you in advance, sorry for my rusted english.
Attachments
Untitled-2.jpg
(722.49 KiB) Not downloaded yet

bba
Engineer
Engineer
Posts: 8
Joined: 25 Aug 2020 19:16

Re: A script to generate heightmaps from real-world elevation data

Post by bba »

I think the heightmap is displaying the correct area. You can clearly make out the lake above Miramar in the top left corner of the heightmap. The Río de la Plata also looks okay in the bottom right corner. The dark shape winding through the middle of the heightmap (that looks like a river) is just low-lying land, not necessarily water. What I've found from working with other heightmaps is that they can often look surprisingly different to how the area looks on a "normal" map.

I don't know that much about the topography of Argentina, but it looks like the area you've tried to capture is quite flat in real life? If that is the case, differences in elevation can appear exaggerated in the heightmap because the highest point in the captured area will be rendered as pure white and the lowest point will be rendered as pure black. So the differences in elevation can appear more extreme in the heightmap than they are in real life.

User avatar
kamnet
Moderator
Moderator
Posts: 7327
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: A script to generate heightmaps from real-world elevation data

Post by kamnet »

And what you can't see right away, especially from a low-resolution rendering, is that the areas that look black are actually subtle shades of greys that the game will render, depending on what you've set the height level at. It will likely take a lot of tweaking in both an image editor and the in=game editor to get it to display exactly right.

bba
Engineer
Engineer
Posts: 8
Joined: 25 Aug 2020 19:16

Re: A script to generate heightmaps from real-world elevation data

Post by bba »

Just to add, the bother command line script has certain options you can provide that should hopefully create heightmaps that will be rendered well in OpenTTD without having to do a lot of post-processing in an image editor (YMMV). These are described in more detail in the README that I linked in the original post. For Guillo2900's region the --max-brightness and --raise-low options may be helpful. These are not yet implemented in personman's web interface.

Regardless of whether you use these options or an image editor (or both), there will be some trial and error involved.

Guillo2900
Engineer
Engineer
Posts: 2
Joined: 07 Jun 2015 23:44
Location: Argentina

Re: A script to generate heightmaps from real-world elevation data

Post by Guillo2900 »

Thanks a lot for you time!

bba wrote:
17 Oct 2020 15:24
I think the heightmap is displaying the correct area. You can clearly make out the lake above Miramar in the top left corner of the heightmap.

What I've found from working with other heightmaps is that they can often look surprisingly different to how the area looks on a "normal" map.

I don't know that much about the topography of Argentina, but it looks like the area you've tried to capture is quite flat in real life?


Now that I have your point of view, it's true, I couldn't recognize anything :lol:
Yes, the captured zone is pretty flat, between 20 and 30 meters above sea level. My idea was to capture a larger zone, where the land elevates a bit to the north west.

kamnet wrote:
17 Oct 2020 15:36
And what you can't see right away, especially from a low-resolution rendering, is that the areas that look black are actually subtle shades of greys that the game will render, depending on what you've set the height level at. It will likely take a lot of tweaking in both an image editor and the in=game editor to get it to display exactly right.


I'll try to capture a bigger zone and then I'll use Photoshop on it.

bba wrote:
18 Oct 2020 22:24
Just to add, the bother command line script has certain options you can provide that should hopefully create heightmaps that will be rendered well in OpenTTD without having to do a lot of post-processing in an image editor (YMMV). These are described in more detail in the README that I linked in the original post. For Guillo2900's region the --max-brightness and --raise-low options may be helpful. These are not yet implemented in personman's web interface.

Regardless of whether you use these options or an image editor (or both), there will be some trial and error involved.


I've tried to download something I don't remember, but it was over 10 minutes when I had to cancell the process. I was preparing to go to work and I thought it was something quick. I'll read everything more carefully to see if I can understand it. Thanks for your time on that too :D

Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 8 guests