NokiMo
ballisticfox
ballisticfox

patreon


Automating MTE (A quarter of it anyways)

Well, second one, this time on my rather terrible code which I'll probably remake eventually, anyways...


The thought occurred to me the other day that I need to try to get some real coding experience, as most of what I do in KSP is not that. I figured a good first project would be writing a script that will automatically normalize the heightmap values. I assumed C++ would be a good start, ImageMagick had a plugin for it after all and I thought I was all set.


Well, I was terribly wrong about the ImageMagick plugin, apparently it had last been tested on Windows XP and suggested Windows 95... and after 4 hours of messing with it I just assumed that wasn't going to work, luckily there's a python library currently being supported called "Wand" so I just jumped ship to python, who needs C++ anyways right?


The beginning was fairly simple, figure out the basics of Wand, open an image, rotate, save it, all was going to plan.

Since all the tiles use the same USGS heading I just looked for an image with that, then opened it, getting the max height was a bit trickier as it had a function to get the "maxima" of the image, which was the max value in the "QuantumRange", but no obvious answer of getting a usable max height value, then I realized that dividing the maxima by the range returns said usable maxheight and everything went swimmingly from there.

I wrote a function to do all of the math for that tile, so the tile width, height, location on earth, etc, and then a function to spit all of that out to a neat little text file.

I realized that this plugin, while nice, automates about 30 seconds of work, which honestly is not that much, so let's add more features!


Next thing I wanted to add was the ability to download the tiles from a url. TNM already has the ability to output the links I need, I just need to download each tile, iterate the normalize and data output steps, and then I'm done!

I tried using 3 different libraries, Urllib, Urllib3 and Requests, eventually settling on Requests because it had everything I needed, being able to both chunk the requests into smaller bits to avoid eating all of the RAM and get the content length of the package.

In the process of reformatting everything to work with the new links, I broke everything! yay! Just to add salt to the wound my 18lb absolute chomker of a cat decided it was his turn to help (his name is Finn and he is a very good boy). I chose to just restart and reuse the functions that I knew worked, after all of that was done I ended up with a pretty basic script which made my life a bit easier.

Next I plan to turn the textures I outputted into an actual 3d mesh, which will cut out quite a bit more time than this smaller problem.


Anyways thanks for listening to me ramble again! Cheers!


Source code down below, Requires Wand and Requests to be installed, to get the data go to:

https://apps.nationalmap.gov/downloader/

Select an extent.

Select elevation products.

Press Search Products

Then up at the top where it says TXT and CSV hit TXT

Stick data.txt in the same folder as the script and run it

Be warned that the textures are about 800mb a tile, please don't blow up your Hard Drive with this.

Automating MTE (A quarter of it anyways)

Related Creators