Jump to content
Sign in to follow this  
Harald_Kraft

Solution: edit SRTM-data in paint program

Recommended Posts

Hi Scenerydesigners!Yesterday was a rainy day, so i downloaded Phyton and wrote my first script. So it's far from perfect, but with this script you can:1.) convert a .hgt-file into a .Raw-rastergrafic, which can be edited with a Paintprogram. I use Adobe Photoshop Elements 1.0 (which came with my scanner). I als tried Paint Shop Pro V3 (the trialversion for Win 3.1, which I downloaded yesterday - search for PSP311. It is less then 2MByte big)2.) Convert the edited RAW-File into a RAS File, which you can directly use in FlyII. In the paint Program all missing SRTM-Data are a bright green. Elevations start with blue (becoming a brighter blue up to 256 m), then a dark violett (becoming a brighter violett up to 512 m), then a more reddish violett for the next 256 m and so on, until its red for very high mountains. Look at the screenshot and you know what i mean. So it is easy to fill the missing spaces with cut and paste or flatten lakes.If you never have used Python, proceed as described below:1.) download Python from www.python.org and install it.2.) Save my script as H3.py (Attention: Phyton is case-sensitive, so h3.py won't work) and save it in the directorc c:Temp3.) Start thy Python-GUI called "IDLE" (don't use the Commanline Interface)4.) When you see the promt, enter the following lines (line by line and press enter after every line)>>> import sys>>> sys.path.append ("c:Temp")>>> import H3>>> H3.HGT2RAW ('c:/temp/NxxEyyy.hgt','c:/temp/NxxEyyy.raw')The first 2 lines tell Python where to find my script. Line 3 loads my script, line 4 executes my script.Attention!!! replace NxxEyyy with the data you want to edit (can be 47E015). The .hgt file must be in the temp-directory, the .raw-file will be created.Close Python and edit your elevation data.Make sure, you open and save (2 different menues in Paint shop pro) the file with following parameters: 8-bit, 3-channel color (=24 bit), interleaved, RGB-Order, no header, Filesize 1201 x 1201 After you have finished, start IDLE again and begin the 2nd conversion with>>> import sys>>> sys.path>>> sys.path.append ("c:Temp")>>> import H3>>> H3.RAW2RAS ('c:/temp/NxxEyyy.hgt','c:/temp/NxxEyyy.raw')Now yo can start FlyII, press CTRL E and import the .RAS-file. Read my mail from last week about Parameter settings.EnjoyHaraldOne more Hint: To check the alterd RAW-File, open it a second time in the Paintprogram. If now all blue is red, you have saved the file in BGR (BlueGreenRed) instead of RGB-Order. So always make a safty-copy.

Share this post


Link to post
Share on other sites

Here is the script: (to avoid timeout of attachment)# Manipulate SRTM-Data# Attention: HGT-Files are big Endian !!!!!!!!def HGT2RAW (inp,op) : # Convert 16bit Raw 1Channel --> 8Bit Raw 3-Channel# Start with H3.HGT2RAW ('c:/temp/N47E015.hgt','c:/temp/N47E015.raw') infile = open(inp,'rb') # open hgt-file as input outfile = open(op, 'wb') # open raw-file as output a=0 b=0 while a != '': # while not EOF a = infile.read(1) # read left Byte of Elevation b = infile.read(1) # read right Byte of Elevation if a == '': # break if nullstring (EOF or empty file) break elif a == 'x01': # create red channel from left Byte outfile.write('x10') elif a == 'x02': outfile.write('x20') elif a == 'x03': outfile.write('x30') elif a == 'x04': outfile.write('x40') elif a == 'x05': outfile.write('x50') elif a == 'x06': outfile.write('x60') elif a == 'x07': outfile.write('x70') elif a == 'x08': outfile.write('x80') elif a == 'x09': outfile.write('x90') elif a == 'x0A': outfile.write('xA0') elif a == 'x0B': outfile.write('xB0') elif a == 'x0C': outfile.write('xC0') elif a == 'x0D': outfile.write('xD0') elif a == 'x0E': outfile.write('xE0') elif a == 'x0F': outfile.write('xF0') elif a == 'x1F': outfile.write('xFF') else: outfile.write('x00') # write(red), 0 when missing SRTM outfile.write(a) # write(green) outfile.write(:( # write(blue) infile.close() outfile.close() print 'Conversion HGT2RAW sucessfull finished'def RAW2RAS (inp,op) : # Convert 8Bit Raw 3-Channel to 16bit Raw 1Channel (Fly2 RAS)# Start with H3.RAW2RAS ('c:/temp/N47E015.raw','c:/temp/N47E015.ras') infile = open(inp,'rb') # open raw-file as input outfile = open(op, 'wb') # open ras-file as output a=0 while a != '': infile.read(1) # remove red Channel a = infile.read(2) outfile.write(a) infile.close() outfile.close() print 'Conversion RAW2RAS sucessfull finished'

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...