Skip to content

Commit fe5c6f5

Browse files
Médéric RibreuxMédéric RIBREUX
Médéric Ribreux
authored and
Médéric RIBREUX
committed
Add i.rectify algorithm
1 parent 8ff07cf commit fe5c6f5

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
i.rectify
2+
Rectifies an image by computing a coordinate transformation for each pixel in the image based on the control points.
3+
Imagery (i.*)
4+
ParameterMultipleInput|rasters|Name of raster maps to rectify|3|False
5+
ParameterFile|gcp|Ground Control Points file|False|False
6+
ParameterSelection|order|Rectification polynomial order|1;2;3|0
7+
ParameterString|resolution|Target resolution|None|False|True
8+
ParameterNumber|memory|Amount of memory to use in MB|1|None|300|True
9+
ParameterSelection|method|Interpolation method to use|nearest;linear;cubic;lanczos;linear_f;cubic_f;lanczos_f|0
10+
ParameterCrs|crs|Destination CRS|None|False
11+
Hardcoded|extension=rectified
12+
*ParameterBoolean|-t|Use thin plate spline|False
13+
OutputDirectory|output|Output Directory
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
i_rectify.py
6+
------------
7+
Date : April 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__ = 'April 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 i import regroupRasters, copyFile, multipleOutputDir
29+
from qgis.core import QgsMessageLog
30+
from qgis.core import QgsCoordinateReferenceSystem
31+
from ..Grass7Utils import Grass7Utils
32+
from processing.core.parameters import getParameterFromString
33+
from os import path
34+
35+
36+
def processCommand(alg):
37+
# Creates a new location with the CRS
38+
crsParam = alg.getParameterFromName('crs')
39+
crsId = int(crsParam.value[5:])
40+
#QgsMessageLog.logMessage('crs = {}'.format(crs), 'DEBUG', QgsMessageLog.INFO)
41+
crs = QgsCoordinateReferenceSystem()
42+
crs.createFromId(crsId, QgsCoordinateReferenceSystem.EpsgCrsId)
43+
command = "g.proj proj4=\"{}\" location=TARGET".format(crs.toProj4())
44+
alg.commands.append(command)
45+
alg.parameters.remove(crsParam)
46+
47+
# Regroup rasters
48+
rasters = alg.getParameterFromName('rasters')
49+
rastersList = rasters.value.split(';')
50+
alg.parameters.remove(rasters)
51+
52+
# Insert a i.group command
53+
group = getParameterFromString("ParameterString|group|group of rasters|None|False|False")
54+
group.value = alg.getTempFilename()
55+
alg.addParameter(group)
56+
57+
command = 'i.group group={} input={}'.format(
58+
group.value,
59+
','.join([alg.exportedLayers[f] for f in rastersList])
60+
)
61+
alg.commands.append(command)
62+
63+
# Handle POINT File
64+
gcp = alg.getParameterFromName('gcp')
65+
extFileName = gcp.value
66+
destPath = path.join(Grass7Utils.grassMapsetFolder(),
67+
'PERMANENT',
68+
'group', group.value,
69+
'POINTS')
70+
copyFile(alg, extFileName, destPath)
71+
alg.parameters.remove(gcp)
72+
73+
# Add a target destination for our group
74+
command = "i.target group={} location=TARGET mapset=PERMANENT".format(group.value)
75+
alg.commands.append(command)
76+
77+
# remove output
78+
output = alg.getOutputFromName('output')
79+
alg.removeOutputFromName('output')
80+
81+
# Add an extension
82+
#extension = getParameterFromString("ParameterString|extension|Output raster map(s) suffix|None|False|False")
83+
#extension.value = "rectified"
84+
#alg.addParameter(extension)
85+
86+
# modify parameters values
87+
alg.processCommand()
88+
89+
# Re-add input rasters
90+
alg.addParameter(rasters)
91+
alg.addParameter(gcp)
92+
alg.addParameter(crs)
93+
94+
# Re-add output
95+
alg.addOutput(output)
96+
97+
98+
def processOutputs(alg):
99+
# We need to export from the TARGET location
100+
command = "g.mapset location=TARGET mapset=PERMANENT"
101+
alg.commands.append(command)
102+
multipleOutputDir(alg, 'output')

0 commit comments

Comments
 (0)