-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE][processing] New 'drop geometries' algorithm
Simply removes any geometries from an input layer and returns the features with attributes only
- Loading branch information
1 parent
38a0ea0
commit 1e661e3
Showing
6 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
DropGeometry.py | ||
-------------- | ||
Date : November 2016 | ||
Copyright : (C) 2016 by Nyall Dawson | ||
Email : nyall dot dawson 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__ = 'Nyall Dawson' | ||
__date__ = 'November 2016' | ||
__copyright__ = '(C) 2016, Nyall Dawson' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive323 | ||
|
||
__revision__ = '$Format:%H$' | ||
|
||
from qgis.core import QgsFeatureRequest, QgsWkbTypes, QgsCoordinateReferenceSystem | ||
from processing.core.GeoAlgorithm import GeoAlgorithm | ||
from processing.core.parameters import ParameterVector | ||
from processing.core.outputs import OutputVector | ||
from processing.tools import dataobjects, vector | ||
|
||
|
||
class DropGeometry(GeoAlgorithm): | ||
|
||
INPUT_LAYER = 'INPUT_LAYER' | ||
OUTPUT_TABLE = 'OUTPUT_TABLE' | ||
|
||
def defineCharacteristics(self): | ||
self.name, self.i18n_name = self.trAlgorithm('Drop geometries') | ||
self.group, self.i18n_group = self.trAlgorithm('Vector general tools') | ||
self.tags = self.tr('remove,drop,delete,geometry,objects') | ||
|
||
self.addParameter(ParameterVector(self.INPUT_LAYER, | ||
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_POINT, | ||
dataobjects.TYPE_VECTOR_LINE, | ||
dataobjects.TYPE_VECTOR_POLYGON])) | ||
self.addOutput(OutputVector(self.OUTPUT_TABLE, self.tr('Dropped geometry'))) | ||
|
||
def processAlgorithm(self, progress): | ||
layer = dataobjects.getObjectFromUri( | ||
self.getParameterValue(self.INPUT_LAYER)) | ||
writer = self.getOutputFromName( | ||
self.OUTPUT_TABLE).getVectorWriter( | ||
layer.fields(), | ||
QgsWkbTypes.NoGeometry, | ||
QgsCoordinateReferenceSystem()) | ||
|
||
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry) | ||
features = vector.features(layer, request) | ||
total = 100.0 / len(features) | ||
|
||
for current, input_feature in enumerate(features): | ||
writer.addFeature(input_feature) | ||
progress.setPercentage(int(current * total)) | ||
|
||
del writer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
python/plugins/processing/tests/testdata/expected/dropped_geometry.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fid,name,intval,floatval | ||
polys.0,aaaaa,33,44.123456 | ||
polys.1,Aaaaa,-33,0 | ||
polys.2,bbaaa,,0.123 | ||
polys.3,ASDF,0, | ||
polys.4,,120,-100291.43213 | ||
polys.5,elim,2,3.33 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters