Skip to content
Permalink
Browse files

start refactoring of the Processing mmqgis backend: Delete column and

Delete duplicate geometries
  • Loading branch information
alexbruy committed Oct 2, 2014
1 parent 25fa170 commit 07d584d264c38efa2e1fd0844f7bd7841ad3dd37
@@ -73,7 +73,8 @@
from ftools.Eliminate import Eliminate
from ftools.SpatialJoin import SpatialJoin

from mmqgisx.MMQGISXAlgorithms import *
from mmqgisx.DeleteColumn import DeleteColumn
from mmqgisx.DeleteDuplicateGeometries import DeleteDuplicateGeometries

from ConcaveHull import ConcaveHull
from Polygonize import Polygonize
@@ -138,17 +139,17 @@ def __init__(self):
RandomExtractWithinSubsets(), ExtractByLocation(),
SpatialJoin(),
# ------ mmqgisx ------
mmqgisx_delete_columns_algorithm(),
mmqgisx_delete_duplicate_geometries_algorithm(),
mmqgisx_geometry_convert_algorithm(),
mmqgisx_grid_algorithm(),
mmqgisx_gridify_algorithm(),
mmqgisx_hub_distance_algorithm(),
mmqgisx_hub_lines_algorithm(),
mmqgisx_merge_algorithm(),
mmqgisx_select_algorithm(),
mmqgisx_extract_algorithm(),
mmqgisx_text_to_float_algorithm(),
DeleteColumn(), DeleteDuplicateGeometries(),
#mmqgisx_delete_duplicate_geometries_algorithm(),
#mmqgisx_geometry_convert_algorithm(),
#mmqgisx_grid_algorithm(),
#mmqgisx_gridify_algorithm(),
#mmqgisx_hub_distance_algorithm(),
#mmqgisx_hub_lines_algorithm(),
#mmqgisx_merge_algorithm(),
#mmqgisx_select_algorithm(),
#mmqgisx_extract_algorithm(),
#mmqgisx_text_to_float_algorithm(),
# ------ native algs ------
AddTableField(), FieldsCalculator(),
SaveSelectedFeatures(), JoinAttributes(),
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
DeleteColumn.py
---------------------
Date : May 2010
Copyright : (C) 2010 by Michael Minn
Email : pyqgis at michaelminn 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__ = 'Michael Minn'
__date__ = 'May 2010'
__copyright__ = '(C) 2010, Michael Minn'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from PyQt4.QtCore import *
from qgis.core import *
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTableField
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector


class DeleteColumn(GeoAlgorithm):
INPUT = 'INPUT'
COLUMN = 'COLUMN'
OUTPUT = 'OUTPUT'

def defineCharacteristics(self):
self.name = 'Delete column'
self.group = 'Vector table tools'

self.addParameter(ParameterVector(
self.INPUT, 'Input layer', [ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterTableField(
self.COLUMN, 'Field to delete', self.INPUT))
self.addOutput(OutputVector(self.OUTPUT, 'Output'))

def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT))
idx = layer.fieldNameIndex(self.getParameterValue(self.COLUMN))

fields = layer.pendingFields()
fields.remove(idx)

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
layer.wkbType(), layer.crs())

features = vector.features(layer)
count = len(features)
total = 100.0 / float(count)

feat = QgsFeature()
for count, f in enumerate(features):
feat.setGeometry(f.geometry())
attributes = f.attributes()
del attributes[idx]
feat.setAttributes(attributes)
writer.addFeature(feat)

progress.setPercentage(int(count * total))

del writer

@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
DeleteColumn.py
---------------------
Date : May 2010
Copyright : (C) 2010 by Michael Minn
Email : pyqgis at michaelminn 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__ = 'Michael Minn'
__date__ = 'May 2010'
__copyright__ = '(C) 2010, Michael Minn'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from PyQt4.QtCore import *
from qgis.core import *
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 DeleteDuplicateGeometries(GeoAlgorithm):
INPUT = 'INPUT'
OUTPUT = 'OUTPUT'

def defineCharacteristics(self):
self.name = 'Delete duplicate geometries'
self.group = 'Vector general tools'

self.addParameter(ParameterVector(
self.INPUT, 'Input layer', [ParameterVector.VECTOR_TYPE_ANY]))
self.addOutput(OutputVector(self.OUTPUT, 'Output'))

def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT))

fields = layer.pendingFields()

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
layer.wkbType(), layer.crs())

features = vector.features(layer)

count = len(features)
total = 100.0 / float(count)
geoms = dict()
for count, f in enumerate(features):
geoms[f.id()] = QgsGeometry(f.geometry())
progress.setPercentage(int(count * total))

cleaned = dict(geoms)

for i, g in geoms.iteritems():
for j in cleaned.keys():
if i == j or i not in cleaned:
continue
if g.isGeosEqual(cleaned[j]):
del cleaned[j]

count = len(cleaned)
total = 100.0 / float(count)
request = QgsFeatureRequest().setFilterFids(cleaned.keys())
for count, f in enumerate(layer.getFeatures(request)):
writer.addFeature(f)
progress.setPercentage(int(count * total))

del writer
@@ -1,15 +1,13 @@
Copyright notice
-------------------
MMQGIS Wrapper

----------------
MMQGIS (c) 2012 by Michael Minn

http://michaelminn.com

MMQGIS is free software and is offered without guarantee
or warranty. You can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public
License (GPL v2) as published by the Free Software
or warranty. You can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public
License (GPL v2) as published by the Free Software
Foundation (www.gnu.org).

QGIS processing framework (c) 2012 by Victor Olaya
QGIS Processing framework (c) 2012 by Victor Olaya

0 comments on commit 07d584d

Please sign in to comment.
You can’t perform that action at this time.