Skip to content

Commit 92b8dd3

Browse files
committed
[FEATURE] reproject layer tool for SEXTANTE
1 parent 9ad9f8c commit 92b8dd3

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

python/plugins/sextante/ftools/FToolsAlgorithmProvider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from sextante.ftools.NearestNeighbourAnalysis import NearestNeighbourAnalysis
4242

4343
# data management tools
44+
from sextante.ftools.ReprojectLayer import ReprojectLayer
4445

4546
# geometry tools
4647
from sextante.ftools.Delaunay import Delaunay
@@ -79,6 +80,7 @@ def __init__(self):
7980
BasicStatisticsNumbers(), NearestNeighbourAnalysis(),
8081
MeanCoords(), LinesIntersection(), UniqueValues(), PointDistance(),
8182
# data management
83+
ReprojectLayer(),
8284
# geometry
8385
ExportGeometryInfo(), Centroids(), Delaunay(), VoronoiPolygons(),
8486
SimplifyGeometries(), DensifyGeometries(), MultipartToSingleparts(),
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
ReprojectLayer.py
6+
---------------------
7+
Date : October 2012
8+
Copyright : (C) 2012 by Alexander Bruy
9+
Email : alexander dot bruy at gmail dot com
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__ = 'Alexander Bruy'
21+
__date__ = 'October 2012'
22+
__copyright__ = '(C) 2012, Alexander Bruy'
23+
# This will get replaced with a git SHA1 when you do a git archive
24+
__revision__ = '$Format:%H$'
25+
26+
import os.path
27+
28+
from PyQt4 import QtGui
29+
from PyQt4.QtCore import *
30+
31+
from qgis.core import *
32+
33+
from sextante.core.GeoAlgorithm import GeoAlgorithm
34+
from sextante.core.QGisLayers import QGisLayers
35+
from sextante.core.SextanteLog import SextanteLog
36+
37+
from sextante.parameters.ParameterVector import ParameterVector
38+
from sextante.parameters.ParameterCrs import ParameterCrs
39+
40+
from sextante.outputs.OutputVector import OutputVector
41+
42+
class ReprojectLayer(GeoAlgorithm):
43+
44+
INPUT = "INPUT"
45+
TARGET_CRS = "TARGET_CRS"
46+
OUTPUT = "OUTPUT"
47+
48+
def getIcon(self):
49+
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/reproject.png")
50+
51+
def defineCharacteristics(self):
52+
self.name = "Reproject layer"
53+
self.group = "Data management tools"
54+
55+
self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
56+
self.addParameter(ParameterCrs(self.TARGET_CRS, "Target CRS", "4326"))
57+
58+
self.addOutput(OutputVector(self.OUTPUT, "Reprojected layer"))
59+
60+
def processAlgorithm(self, progress):
61+
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
62+
crsId = self.getParameterValue(self.TARGET_CRS)
63+
targetCrs = QgsCoordinateReferenceSystem(int(crsId))
64+
65+
output = self.getOutputValue(self.OUTPUT)
66+
67+
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
68+
layer.wkbType(), targetCrs)
69+
70+
layer.select(layer.pendingAllAttributesList())
71+
72+
current = 0
73+
total = 100.0 / float(layer.featureCount())
74+
75+
layerCrs = layer.crs()
76+
crsTransform = QgsCoordinateTransform(layerCrs, targetCrs)
77+
78+
f = QgsFeature()
79+
outFeat = QgsFeature()
80+
while layer.nextFeature(f):
81+
geom = f.geometry()
82+
geom.transform(crsTransform)
83+
outFeat.setGeometry(geom)
84+
outFeat.setAttributeMap(f.attributeMap())
85+
writer.addFeature(outFeat)
86+
87+
current += 1
88+
progress.setPercentage(int(current * total))
89+
90+
del writer
Loading

0 commit comments

Comments
 (0)