2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
DensifyGeometries.py
|
|
|
|
---------------------
|
|
|
|
Date : October 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2016-09-21 18:24:26 +02:00
|
|
|
from builtins import range
|
2012-10-04 19:33:47 +02:00
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'October 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$'
|
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
import os
|
|
|
|
|
2017-03-29 10:42:42 +10:00
|
|
|
from qgis.core import (QgsGeometry,
|
|
|
|
QgsPoint,
|
|
|
|
QgsWkbTypes,
|
2017-04-25 17:53:32 +10:00
|
|
|
QgsApplication,
|
|
|
|
QgsProcessingUtils)
|
2012-10-03 18:46:01 +03:00
|
|
|
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.core.GeoAlgorithm import GeoAlgorithm
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.parameters import ParameterVector
|
|
|
|
from processing.core.parameters import ParameterNumber
|
|
|
|
from processing.core.outputs import OutputVector
|
2013-10-01 20:52:22 +03:00
|
|
|
from processing.tools import dataobjects, vector
|
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
|
|
|
|
2012-10-03 18:46:01 +03:00
|
|
|
|
|
|
|
class DensifyGeometries(GeoAlgorithm):
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
INPUT = 'INPUT'
|
|
|
|
VERTICES = 'VERTICES'
|
|
|
|
OUTPUT = 'OUTPUT'
|
2012-10-03 18:46:01 +03:00
|
|
|
|
2017-03-29 10:42:42 +10:00
|
|
|
def icon(self):
|
|
|
|
return QgsApplication.getThemeIcon("/providerQgis.svg")
|
|
|
|
|
|
|
|
def svgIconPath(self):
|
|
|
|
return QgsApplication.iconPath("providerQgis.svg")
|
|
|
|
|
2017-03-29 09:51:13 +10:00
|
|
|
def tags(self):
|
|
|
|
return self.tr('add,vertices,points').split(',')
|
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Vector geometry tools')
|
|
|
|
|
2017-03-29 12:51:59 +10:00
|
|
|
def name(self):
|
2017-03-29 17:09:39 +10:00
|
|
|
return 'densifygeometries'
|
2017-03-29 12:51:59 +10:00
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('Densify geometries')
|
2012-10-03 18:46:01 +03:00
|
|
|
|
2017-03-29 12:51:59 +10:00
|
|
|
def defineCharacteristics(self):
|
2015-01-15 20:41:15 +02:00
|
|
|
self.addParameter(ParameterVector(self.INPUT,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Input layer'),
|
2016-08-23 19:33:42 +03:00
|
|
|
[dataobjects.TYPE_VECTOR_POLYGON, dataobjects.TYPE_VECTOR_LINE]))
|
2015-01-15 20:41:15 +02:00
|
|
|
self.addParameter(ParameterNumber(self.VERTICES,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Vertices to add'), 1, 10000000, 1))
|
2015-01-15 20:41:15 +02:00
|
|
|
|
|
|
|
self.addOutput(OutputVector(self.OUTPUT,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Densified')))
|
2012-10-03 18:46:01 +03:00
|
|
|
|
2017-04-25 14:55:38 +10:00
|
|
|
def processAlgorithm(self, context, feedback):
|
2017-04-05 18:35:55 +10:00
|
|
|
layer = dataobjects.getLayerFromString(
|
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
|
|
|
self.getParameterValue(self.INPUT))
|
2013-01-12 23:36:00 +01:00
|
|
|
vertices = self.getParameterValue(self.VERTICES)
|
2012-10-03 18:46:01 +03:00
|
|
|
|
2016-08-04 09:10:08 +02:00
|
|
|
isPolygon = layer.geometryType() == QgsWkbTypes.PolygonGeometry
|
2012-10-03 18:46:01 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
writer = self.getOutputFromName(
|
2016-08-04 07:37:22 +10:00
|
|
|
self.OUTPUT).getVectorWriter(layer.fields().toList(),
|
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
|
|
|
layer.wkbType(), layer.crs())
|
2012-10-03 18:46:01 +03:00
|
|
|
|
2017-04-25 17:59:35 +10:00
|
|
|
features = QgsProcessingUtils.getFeatures(layer, context)
|
2017-04-25 17:53:32 +10:00
|
|
|
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
2016-02-17 09:36:59 +02:00
|
|
|
for current, f in enumerate(features):
|
2016-11-07 09:22:50 +10:00
|
|
|
feature = f
|
|
|
|
if feature.hasGeometry():
|
2017-03-25 15:17:22 +10:00
|
|
|
new_geometry = feature.geometry().densifyByCount(int(vertices))
|
2016-11-07 09:22:50 +10:00
|
|
|
feature.setGeometry(new_geometry)
|
2013-01-01 23:52:00 +01:00
|
|
|
writer.addFeature(feature)
|
2017-01-06 20:04:00 +10:00
|
|
|
feedback.setProgress(int(current * total))
|
2012-10-03 18:46:01 +03:00
|
|
|
|
|
|
|
del writer
|