Saturday, 16 September 2017

Extract Elevation of Points from DEM using Python QGIS or GRASS


I am utterly new to GIS, so please bear with me if I am providing incomplete information here.


I have a DEM file (.dt2). What I am looking to do is as follows:



  1. take a series of points specified as lat, long

  2. calculate their elevations using the DEM data

  3. Output these points in as a list of ECEF coords


I need to do this in either GRASS or QGIS (using Python scripting, not the GUI).


I don't need a complete working code. I am only looking to be pointed in the right direction.




Answer



If you want to do that with PyQGIS, the def Val_raster(x,y,layer,bands,gt) of Python Script for getting elevation difference between two points becomes:


def Val_raster(point,raster):
return raster.dataProvider().identify(point,QgsRaster.IdentifyFormatValue).results().values()

for point in points.getFeatures():
geompt = point.geometry().asPoint()
print print Val_raster(geompt,DEM)
[169.21]
[268.65]

[200.43]

with a multiband raster (R,G,B values) the results are, for example


[203.0, 177.0, 202.0]
[194.0, 181.0, 199.0]
[109.0, 85.0, 101.0]

Or you can use GRASS command v.drape :


In the QGIS console (processing):


processing.alghelp("grass:v.drape")


In GRASS GIS with grass.script (GRASS 6.4.x, GRASS 7.x ) or Pygrass (GRASS 7.x)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...