Skip to content

Commit a39d258

Browse files
author
Médéric RIBREUX
committed
[Processing]Add v.what.rast algorithms
* Implements Redmine feature request #6859. * v.what.rast.points when type=point. For points input layers. * v.what.rast.centroids when type=centroid. For polygons input layers.
1 parent 4825856 commit a39d258

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
v.what.rast
2+
v.what.rast.centroids - Uploads raster values at positions of vector centroids to the table.
3+
Vector (v.*)
4+
ParameterVector|map|Name of vector points map for which to edit attributes|2|False
5+
ParameterRaster|raster|Raster map to be sampled|False
6+
ParameterTableField|column|Name of attribute column to be updated with the query result|map|0|False
7+
ParameterString|where|WHERE conditions of SQL statement without 'where' keyword|None|True
8+
Hardcoded|type=centroid
9+
*ParameterBoolean|-i|Interpolate values from the nearest four cells|False|True
10+
OutputVector|output|Sampled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
v.what.rast
2+
v.what.rast.points - Uploads raster values at positions of vector points to the table.
3+
Vector (v.*)
4+
ParameterVector|map|Name of vector points map for which to edit attributes|0|False
5+
ParameterRaster|raster|Raster map to be sampled|False
6+
ParameterTableField|column|Name of attribute column to be updated with the query result|map|0|False
7+
ParameterString|where|WHERE conditions of SQL statement without 'where' keyword|None|True
8+
Hardcoded|type=point
9+
*ParameterBoolean|-i|Interpolate values from the nearest four cells|False|True
10+
OutputVector|output|Sampled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_what_rast.py
6+
---------------------
7+
Date : January 2016
8+
Copyright : (C) 2016 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
19+
This Python module handles output for v.what.rast.* GRASS7 modules.
20+
"""
21+
22+
__author__ = 'Médéric Ribreux'
23+
__date__ = 'January 2016'
24+
__copyright__ = '(C) 2016, Médéric Ribreux'
25+
26+
# This will get replaced with a git SHA1 when you do a git archive
27+
28+
__revision__ = '$Format:%H$'
29+
30+
import os
31+
32+
33+
def removeOutput(alg):
34+
"""Remove the output fo v.what.rast"""
35+
# We temporary remove the output 'sequence'
36+
output = alg.getOutputFromName(u'output')
37+
alg.removeOutputFromName(u'output')
38+
39+
# Launch the algorithm
40+
alg.processCommand()
41+
42+
# We re-add the previous output
43+
alg.addOutput(output)
44+
45+
46+
def outputInput(alg):
47+
"""Make output the initial point/polygon layer"""
48+
output = alg.getOutputValue(u'output')
49+
command = u"v.out.ogr -c type=auto -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
50+
alg.exportedLayers[alg.getParameterValue(u'map')],
51+
os.path.dirname(output),
52+
os.path.basename(output)[:-4]
53+
)
54+
alg.commands.append(command)
55+
alg.outputCommands.append(command)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_what_rast_centroids.py
6+
------------------------
7+
Date : January 2016
8+
Copyright : (C) 2016 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'January 2016'
22+
__copyright__ = '(C) 2016, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from v_what_rast import removeOutput, outputInput
29+
30+
31+
def processCommand(alg):
32+
removeOutput(alg)
33+
34+
35+
def processOutputs(alg):
36+
outputInput(alg)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_what_rast_points.py
6+
---------------------
7+
Date : January 2016
8+
Copyright : (C) 2016 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'January 2016'
22+
__copyright__ = '(C) 2016, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from v_what_rast import removeOutput, outputInput
29+
30+
31+
def processCommand(alg):
32+
removeOutput(alg)
33+
34+
35+
def processOutputs(alg):
36+
outputInput(alg)

0 commit comments

Comments
 (0)