2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
polygonize.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
from PyQt4 import QtCore
|
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.parameters import ParameterRaster
|
|
|
|
from processing.core.parameters import ParameterString
|
|
|
|
from processing.core.outputs import OutputVector
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
from processing.tools.system import isWindows
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class polygonize(GdalAlgorithm):
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
INPUT = 'INPUT'
|
|
|
|
OUTPUT = 'OUTPUT'
|
|
|
|
FIELD = 'FIELD'
|
2014-06-13 09:03:15 +02:00
|
|
|
|
2013-10-06 13:25:01 +02:00
|
|
|
def commandLineName(self):
|
|
|
|
return "gdalogr:polygonize"
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def defineCharacteristics(self):
|
2015-07-26 03:48:27 +02:00
|
|
|
self.name, self.i18n_name = self.trAlgorithm('Polygonize (raster to vector)')
|
|
|
|
self.group, self.i18n_group = self.trAlgorithm('[GDAL] Conversion')
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterRaster(polygonize.INPUT,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Input layer'), False))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterString(polygonize.FIELD,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Output field name'), 'DN'))
|
2015-04-10 09:44:20 +02:00
|
|
|
self.addOutput(OutputVector(polygonize.OUTPUT, self.tr('Vectorized')))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
def getConsoleCommands(self):
|
2013-04-10 12:15:55 +04:00
|
|
|
arguments = []
|
|
|
|
arguments.append(self.getParameterValue(polygonize.INPUT))
|
|
|
|
arguments.append('-f')
|
2013-09-15 16:15:57 +03:00
|
|
|
arguments.append('ESRI Shapefile')
|
2013-04-10 12:15:55 +04:00
|
|
|
output = self.getOutputValue(polygonize.OUTPUT)
|
|
|
|
arguments.append(output)
|
|
|
|
arguments.append(QtCore.QFileInfo(output).baseName())
|
|
|
|
arguments.append(self.getParameterValue(polygonize.FIELD))
|
|
|
|
|
|
|
|
commands = []
|
2013-09-12 13:19:00 +02:00
|
|
|
if isWindows():
|
2013-10-01 20:52:22 +03:00
|
|
|
commands = ['cmd.exe', '/C ', 'gdal_polygonize.bat',
|
|
|
|
GdalUtils.escapeAndJoin(arguments)]
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
2013-10-01 20:52:22 +03:00
|
|
|
commands = ['gdal_polygonize.py',
|
|
|
|
GdalUtils.escapeAndJoin(arguments)]
|
2012-12-10 00:12:07 +01:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
return commands
|