Access DEM (altitude) from python processor

Hi, I have a product that does not include information about the altitude of a pixel (I will be better with OLCI but …). I am developing a processor in python for which I need to take the altitude into accout. Is there a method to access the GETASSE DEM (which came with BEAM) or another DEM? I would love a class DEM with a method "getAltitude(latitude, longitude). The API includes org.esa.snap.core.dataop.dem but it is not clear to me how to use it (I am not very much object-oriented programming experienced).

Exactly such method exist. Only the name is getElevation(...).
Following some Java example code. Unfortunately it is not Python but I know you can translate it.

double lat = 53.555;
double lon = 9.995;
final String resamplingMethod = Resampling.NEAREST_NEIGHBOUR.getName();
final String demName = "SRTM 3Sec"; // or GETASSE30
final ElevationModel dem = DEMFactory.createElevationModel(demName, resamplingMethod);

final double elevation = dem.getElevation(new GeoPos(lat, lon));

DEMS are automatically downloaded.
You can use other DEM names. For a list of available DEMs use DEMFactory.getDEMNameList(). Before using one of the names provided by this method you need to call

properDEMName = DEMFactory.getProperDEMName(demNameList[2]) 

This is necessary to remove “(Auto Download)” from the name.
As resampling you can also use one of the other resampling methods, e.g. Resampling.BICUBIC_INTERPOLATION.

Thanks … looks good, but I didn’t manage to import the class DEMFactory into my python code. I tried
from snappy import DEMFactory
but that didn’t work. Likewise I had success to import Resampling.

from snappy import *****

works only for the most frequently used classes. Those classes are defined in the __init__.py script. From line 286 on.
For classes not listed in the init script you need to do the following:

import jpy
DEMFactory = jpy.get_type('org.esa.snap.dem.dataio.DEMFactory')
Resampling = jpy.get_type('org.esa.snap.core.dataop.resamp.Resampling')

I think these are the classes you need to import.

Correcting my previous post.
You should better do the following:

import snappy
DEMFactory = snappy.jpy.get_type('org.esa.snap.dem.dataio.DEMFactory')
Resampling = snappy.jpy.get_type('org.esa.snap.core.dataop.resamp.Resampling')

With the previous code it is not ensured that you get the correct jpy version corresponding to snappy. It might work but only by accident.

1 Like