I started a project and write an application in java using geotools. I have an simple geoobject with the attributes latitude, longitude and altitude. Now i have to determine, wheather the geoobject is an aircraft or a car on a road.

I modeled my roads as LineStrings an my geoobjects a circle polygones. So i run a simple test, if the geoobject touchs or intersects the linestring, at the given coordinate. So far it works.

But some roads have an elevation. I found sample digital elevation model files, but don't know to handle them. Is there an easy way to get elevation data respectively is there another simple way? Need i software like postgis or somethin else?

2 Answers 2


You can download elevation data in raster format from this url

Load each tif into postgres with:-

 raster2pgsql -d -s 4326 -t 50x50 <TIFF>.tif <YOUR TABLE> | psql -n <YOUR DATABASE>

Then get an elevation with:-

SELECT ST_Value(rast,1, 
                ST_GEOMFROMEWKT('SRID=4326;POINT('||lon||' '||lat||')')

This abstracts most of the geometry stuff for you. You will need gdal, a postgres database with postgis installed and a connection from java.


Have a look at the GeoTools image tutorial to show you how to load a raster (which is what your DEM is)

    AbstractGridFormat format = GridFormatFinder.findFormat( rasterFile ); 
    //this is a bit hacky but does make more geotiffs work
    Hints hints = new Hints();
    if (format instanceof GeoTiffFormat) {
        hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
    reader = format.getReader(rasterFile, hints);
    Layer rasterLayer = new GridReaderLayer(reader, rasterStyle);

You can use the evaluate methods on the coverage to get back the raster value(s) at a point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.