-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB06246_04_12-PointDEM.py
36 lines (26 loc) · 1.09 KB
/
B06246_04_12-PointDEM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Adding Elevation Data to Line Vertices using a DEM
# https://github.com/GeospatialPython/Learn/raw/master/path.zip
import processing
from PyQt4.QtCore import *
pth = "/qgis_data/rasters/path/"
rasterPth = pth + "elevation.asc"
vectorPth = pth + "paths.shp"
pointsPth = pth + "points.shp"
elvPointsPth = pth + "elvPoints.shp"
settings = QSettings()
originalSetting = settings.value("/Projections/defaultBehaviour", "prompt", type=str)
settings.setValue("/Projections/defaultBehaviour", "useProject")
rasterLyr = QgsRasterLayer(rasterPth, "Elevation")
crs = QgsCoordinateReferenceSystem()
crs.createFromSrid(4326)
rasterLyr.setCrs(crs)
settings.setValue( "/Projections/defaultBehaviour", originalSetting)
rasterLyr.isValid()
# True
vectorLyr = QgsVectorLayer(vectorPth, "Path", "ogr")
vectorLyr.isValid()
# True
QgsMapLayerRegistry.instance().addMapLayers([rasterLyr])
QgsMapLayerRegistry.instance().addMapLayers([vectorLyr, rasterLyr])
processing.runalg("saga:convertlinestopoints", vectorLyr, False, 1, pointsPth)
processing.runandload("saga:addgridvaluestopoints", pointsPth, rasterPth, 0, elvPointsPth)