Skip to content

Commit

Permalink
[FEATURE][processing] New 'drop geometries' algorithm
Browse files Browse the repository at this point in the history
Simply removes any geometries from an input layer and returns
the features with attributes only
  • Loading branch information
nyalldawson committed Nov 23, 2016
1 parent 38a0ea0 commit 1e661e3
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
4 changes: 3 additions & 1 deletion python/plugins/processing/algs/help/qgis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ qgis:dissolve: >
qgis:distancematrix: >
This algorithms creates a table containing a distance matrix, with distances between all the points in a points layer.


qgis:distancetonearesthub: >
Given a layer with source point and another one representing destination points, this algorithm computes the distance between each source point and the closest detination one.

The resulting layer can contain only source points with an additional field indicating the distance to the nearest point and the name of the destination point, or lines linking each source point with its nearest destination point.

qgis:dropgeometries: >
This algorithm removes any geometries from an input layer and returns a layer containing only the feature attributes.

qgis:eliminatesliverpolygons: >
This algorithm combines selected polygons of the input layer with certain adjacent polygons by erasing their common boundary. Eliminate can either use an existing selection or a logical query based on one of the layer's fields to make the selection itself. The adjacent polygon can be either the one with the largest or smallest area or the one sharing the largest common boundary with the polygon to be eliminated. Eliminate is normally used to get rid of sliver polygons, i.e. tiny polygons that are a result of polygon intersection processes where boundaries of the inputs are similar but not identical.

Expand Down
68 changes: 68 additions & 0 deletions python/plugins/processing/algs/qgis/DropGeometry.py
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
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
from .SnapGeometries import SnapGeometriesToLayer
from .PoleOfInaccessibility import PoleOfInaccessibility
from .CreateAttributeIndex import CreateAttributeIndex
from .DropGeometry import DropGeometry

pluginPath = os.path.normpath(os.path.join(
os.path.split(os.path.dirname(__file__))[0], os.pardir))
Expand Down Expand Up @@ -227,7 +228,7 @@ def __init__(self):
PostGISExecuteSQL(), ImportIntoPostGIS(),
SetVectorStyle(), SetRasterStyle(),
SelectByExpression(), HypsometricCurves(),
SplitWithLines(), SplitLinesWithLines(), CreateConstantRaster(),
SplitWithLines(), SplitLinesWithLines(), CreateConstantRaster(),
FieldsMapper(), SelectByAttributeSum(), Datasources2Vrt(),
CheckValidity(), OrientedMinimumBoundingBox(), Smooth(),
ReverseLineDirection(), SpatialIndex(), DefineProjection(),
Expand All @@ -242,7 +243,7 @@ def __init__(self):
TinInterpolationZValue(), TinInterpolationAttribute(),
RemoveNullGeometry(), ExtractByExpression(), ExtendLines(),
ExtractSpecificNodes(), GeometryByExpression(), SnapGeometriesToLayer(),
PoleOfInaccessibility(), CreateAttributeIndex()
PoleOfInaccessibility(), CreateAttributeIndex(), DropGeometry()
]

if hasMatplotlib:
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/qgis/RemoveNullGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class RemoveNullGeometry(GeoAlgorithm):
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Remove null geometries')
self.group, self.i18n_group = self.trAlgorithm('Vector selection tools')
self.tags = self.tr('remove,drop,delete,empty,geometry')

self.addParameter(ParameterVector(self.INPUT_LAYER,
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_ANY]))
Expand Down
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
11 changes: 11 additions & 0 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1637,3 +1637,14 @@ tests:
OUTPUT:
name: expected/split_lines_with_lines_same.gml
type: vector

- algorithm: qgis:dropgeometries
name: Drop geometries
params:
INPUT_LAYER:
name: polys.gml
type: vector
results:
OUTPUT_TABLE:
name: expected/dropped_geometry.csv
type: vector

0 comments on commit 1e661e3

Please sign in to comment.