DEM Help

Home Forums AR Sandbox Forum DEM Help

This topic contains 23 replies, has 7 voices, and was last updated by  ABCottrell 6 months ago.

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
  • #102939


    Dr. Kreylos,
    You are a steely-eyed missile man.

    It turned out that manual loading of the DEM in an already active SARndbox simulation was causing the error(s).
    The following script failed (manual browse and load while SARndbox is running);

    section Tool2
    	toolClass DEMTool
    	bindings ((Mouse, m))
    	demVerticalScale 4.0
    	demVerticalShift -1.5

    Pre-loading the DEM source to the mapped key results in successful DEM-interactivity.

    The following script succeed for both discussed DEM files (LakeTahoe and CedarLakeDam);

    section Tool2
    	toolClass DEMTool
    	bindings ((Mouse, m))
    	demFileName /home/siu-geology/src/SARndbox-2.3/<relevant *.grid file-name here>
    	demVerticalScale 4.0
    	demVerticalShift -1.5

    Great appreciation Dr. Kreylos.

    • This reply was modified 7 months ago by  jKrienert.
    • This reply was modified 7 months ago by  jKrienert.
    • This reply was modified 7 months ago by  jKrienert.
    • This reply was modified 7 months ago by  jKrienert.
    • This reply was modified 7 months ago by  jKrienert.
    • This reply was modified 7 months ago by  jKrienert. Reason: Code formating!
    • This reply was modified 7 months ago by  jKrienert.


    @siki… I’m getting an error – usage: [-h] [-o OFFSET] [-s SCALE] ARSand.dem [ARTest.grid] error: too few arguments

    Can you/anyone help, please?

    • This reply was modified 6 months, 1 week ago by  ABCottrell.


    For what its worth, I partially modified the distributed and utilities to have explicit (raw string) file location input/outputs.
    That solved a similar problem I was experiencing when attempting to use them.



    Thank you, jKrienert. I’m a newbie to python. Would you care to show how you did this in the .py? I’m still getting the “too few arguments”. Now it looks like this:

    usage: [-h] [-o OFFSET] [-s SCALE]
    [C:\Users*******\Documents\ARSandbox\SARndbox_util-master\SARndbox_util-master\ARSand.grid] error: too few arguments



    Here is an example of the adapted script I used which functions when run from a PyCharm Python Console…

    import sys
    import os
    import osgeo.gdal as gd
    from gdalconst import GA_ReadOnly, GDT_Byte, GDT_UInt16, GDT_Int16, \
         GDT_UInt32, GDT_Int32, GDT_Float32, GDT_Float64
    import struct
    # GDAL data types to packt data_types
    gd_type = {GDT_Byte:    "b",
               GDT_UInt16:  "H",
               GDT_Int16:   "h",
               GDT_UInt32:  "I",
               GDT_Int32:   "i",
               GDT_Float32: "f",
               GDT_Float64: "d"}
    # establish input file
    ifilename = r"C:\Users\Joe\map.asc"
    # generate output file name 
    ofilename = os.path.splitext(ifilename)[0] + ".grid"
    # use gdal to read DEM file
    idataset = gd.Open(ifilename, GA_ReadOnly)
    if idataset is None:
        print("Cannot read input file {}".format(ifilename));
    # get size of dem
    cols = idataset.RasterXSize
    rows = idataset.RasterYSize
    # get and calculate coordinate limits
    tr = idataset.GetGeoTransform()
    xul = tr[0]
    yul = tr[3]
    xlr = xul + (cols - 1) * tr[1] 
    ylr = yul + (rows - 1) * tr[5]
    # write data to binary output
    of = open(ofilename, "wb")
    of.write(struct.pack("2i", cols, rows))
    of.write(struct.pack("4f", xul, ylr, xlr, yul))
    band = idataset.GetRasterBand(1)
    d = band.ReadRaster(0, 0, cols, rows, cols, rows, band.DataType)
    data = struct.unpack(gd_type[band.DataType] * (rows * cols), d)
    of.write(struct.pack("f" * (cols * rows), *data))
    • This reply was modified 6 months, 1 week ago by  jKrienert.
    • This reply was modified 6 months, 1 week ago by  jKrienert. Reason: clarification and confidentiality


    Hey THANKS. That did spit out a .grid file for me. Now I need to see what the sandbox will do with it.

    Once again, thank you jKrienert!



    I’ve created a a repo (, there you can find a short description.
    There is only one obligatory parameter the input file.
    So if there is no need for offset and scale the elevations the command line should be:

    python your_dem_file

    This case the output will have the same name as the input, only the extension will be changed (output will be written to the same folder as the input file.

    If you set the input file in the code you lose flexibility, you have to change the source code if you want to use the code for a different input file.



    @siki and @abcottrell

    Siki is right.
    The sample I posted is a hardset means of output, and is neither adaptable nor pythonic. It gives an answer, but crudely so.

    The original Github script is preferred, and hopefully your able to get that going based off Siki’s (good) wisdom.

    Maybe my previous replies suggested that the raster used to produce a sandbox elevation map needed a burned in offset and exageration either before or during the Python utility.
    Pardon if this is the case.
    Actually, okreylos was correct to signal me way back some 5 posts ago that raster resampling before any sandbox elevation map was produced is unnecessary. Discovered such after trying a different raw *.asc map worked great. Then minor adjusting the offset and exaggeration wihin the running SARndbox application finished the job.

    • This reply was modified 6 months ago by  jKrienert.


    @jkrienert and @siki

    I believe I have figure out the py script. I would like to say thanks to both of you for your quick response and eagerness to assist me. It is much appreciated!!!

    I’m just now getting into the AR Sandbox and I’m stumbling quite a bit. Its frustrating and fun at the same time. Maybe I should learn the basics first before jumping into this. 🙂

    • This reply was modified 6 months ago by  ABCottrell.
Viewing 9 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic.

Comments are closed.