Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper naming for Chaikin's algorithm #7

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
aca6434
Update dialogs.py
kikislater Nov 6, 2019
b3b8e2a
Update generalizer.py
kikislater Nov 6, 2019
808f98e
Update generalizerdialog.py
kikislater Nov 6, 2019
8ddf0e3
Update __init__.py
kikislater Nov 6, 2019
ea9a258
Update points.py
kikislater Nov 6, 2019
316e806
Update metadata.txt
kikislater Nov 6, 2019
a0fff07
Update simplify.py
kikislater Nov 6, 2019
1dc0fcc
Update smooth.py
kikislater Nov 6, 2019
ca79a90
Update ui_generalizer.py
kikislater Nov 6, 2019
5e3805c
Update matrix.py
kikislater Nov 6, 2019
e666f2e
Update resources.py
kikislater Nov 6, 2019
de4e458
Create README.md
kikislater Nov 8, 2019
a1b8c90
Update README.md
kikislater Nov 8, 2019
b24406a
Better readme based on Grass GIS doc
kikislater Nov 10, 2019
0b2945e
Correction to make sliding working
kikislater Nov 10, 2019
ac11316
Correction to make sliding working
kikislater Nov 10, 2019
658800e
Comments update
kikislater Nov 10, 2019
ef69350
Comments update
kikislater Nov 10, 2019
8948aab
Correct error on first load
kikislater Nov 10, 2019
ec1ebf6
Release 0.6
kikislater Nov 10, 2019
31f4ba2
release 0.6
kikislater Nov 10, 2019
2d4a4ea
Update metadata.txt
kikislater Nov 10, 2019
96c5d06
release 0.6
kikislater Nov 10, 2019
528f42d
Update CHANGELOG
kikislater Nov 10, 2019
5c748ed
0.6 release
kikislater Nov 10, 2019
8eb82ea
Delete resources.py
kikislater Nov 11, 2019
10df340
Delete ui_generalizer.py
kikislater Nov 11, 2019
6ed7e1e
fix save layer and unattended column
kikislater May 17, 2020
37cebb4
Merge pull request #3 from giscan/0.7
kikislater May 17, 2020
d99840d
Add files via upload
kikislater May 23, 2020
496c828
Add files via upload
kikislater May 23, 2020
cf749b2
0.8
kikislater May 23, 2020
9c296c8
0.8
kikislater May 23, 2020
85640cd
Merge pull request #4 from giscan/master
kikislater May 23, 2020
16cdf87
Merge pull request #5 from giscan/0.8
kikislater May 23, 2020
6bce7fc
generated py from ui
kikislater May 23, 2020
cf4c775
Move plugin to his self toolbar
kikislater Nov 9, 2020
04cbad5
Merge pull request #8 from giscan/0.9
kikislater Nov 9, 2020
ddd0ccb
Update metadata.txt
kikislater Nov 9, 2020
5716f11
Update generalizer.py
kikislater Nov 9, 2020
26c615e
Merge pull request #9 from giscan/0.9
kikislater Nov 9, 2020
1acb04c
Fix https://github.com/giscan/Generalizer/issues/7
kikislater Nov 17, 2020
1072b5c
Merge pull request #10 from giscan/1.0
kikislater Nov 17, 2020
7cb62e6
Update generalizerdialog.py
kikislater Nov 17, 2020
86cbbf1
Merge pull request #12 from giscan/1.0
kikislater Nov 17, 2020
2cf5d4f
Update generalizerdialog.py
kikislater Nov 18, 2020
50158e0
Proper naming for Chaikin's algorithm
dubravat Jul 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
0.9 (09.11.2020)
- Move plugin to his self toolbar

0.8 (23.05.2020)
- fix import resources

0.7 (17.05.2020)
- fix save layer to file
- remove unattended column in temporary layer

0.6 (10.11.2019)
- updated to QGIS 3.x
- fix projection according to project coordinates
- quick documentation

0.5 (24.11.2013)
-updated to QGIS 2.0 API (thanks to Matthew Petroff)
-fix unicode error
Expand All @@ -21,4 +36,4 @@ smoothing: Hermite Spline Interpolation
-supported algorithms:
generalization: Remove small objects
simplifying: Douglas-Peucker, Lang, Vertex Reduction
smoothing: Boyle's Forward-Looking, Chaiken's, McMaster's Distance-Weighting, McMaster's Sliding Averaging
smoothing: Boyle's Forward-Looking, Chaiken's, McMaster's Distance-Weighting, McMaster's Sliding Averaging
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ![Logo Generalizer](icon.png)Generalizer
Generalizer plugin for QGIS 3. Originally written by Piotr Pociask

Plugin to Generalize, Simplify or Smooth lines in QGIS

Functions :
- Remove small objects

- Simplify :
* Douglas-Peucker Algorithm

![Douglas](https://grass.osgeo.org/grass79/manuals/v_generalize_simplify.png "Original line is black")

* Jenk's Algorithm
* Lang Algorithm
* Reumann-Witkam Algorithm
* Vertex Reduction

- Smooth :
* Boyle's Forward-Looking Algorithm

![Boyle's](https://grasswiki.osgeo.org/w/images/thumb/V.generalize.pic15.png/400px-V.generalize.pic15.png "Original line is black")

* Chaikin's Algorithm

![Chaikin's smooth](https://grass.osgeo.org/grass79/manuals/v_generalize_smooth.png "Original line is black")

![Chaikin's](https://grasswiki.osgeo.org/w/images/thumb/V.generalize.pic7.png/400px-V.generalize.pic7.png "Original is black")

* Hermite Spline Interpolation

![Hermite](https://grasswiki.osgeo.org/w/images/thumb/V.generalize.pic8.png/400px-V.generalize.pic8.png "Original is black")

![Hermite and Chaikin](https://grasswiki.osgeo.org/w/images/thumb/V.generalize.pic9.png/400px-V.generalize.pic9.png "Original = black, Green = Chaikin, Blue = Hermite")

* McMaster's Distance-Weighting Algorithm

![Distance Weighting](https://grasswiki.osgeo.org/w/images/thumb/V.generalize.pic13.png/400px-V.generalize.pic13.png "Original line is black")

* McMaster's Sliding Averaging Algorithm

![Sliding](https://grasswiki.osgeo.org/w/images/thumb/V.generalize.pic11.png/400px-V.generalize.pic11.png "Original line is black")

![Sliding2](https://grasswiki.osgeo.org/w/images/thumb/V.generalize.pic12.png/400px-V.generalize.pic12.png "Original line is black")

* Snakes Algorithm :
Slowest smoothing algorithm

![Snakes](https://grasswiki.osgeo.org/w/images/thumb/V.generalize.pic14.png/400px-V.generalize.pic14.png "Original line is black")



Which algorithm to choose : https://grasswiki.osgeo.org/wiki/V.generalize_tutorial
3 changes: 2 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
from __future__ import absolute_import
def classFactory(iface):
# load generalizer class from file generalizer
from generalizer import generalizer
from .generalizer import generalizer
return generalizer(iface)
16 changes: 9 additions & 7 deletions dialogs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from builtins import str
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

from os.path import splitext, dirname

Expand All @@ -9,14 +11,14 @@ def saveDialog(parent):
key = '/UI/lastShapefileDir'
outDir = settings.value(key)

filter = 'Shapefiles (*.shp)'
outFilePath = QFileDialog.getSaveFileName(parent, parent.tr('Save output shapefile'), outDir, filter)
outFilePath = unicode(outFilePath)
filter = 'GeoPackage (*.gpkg)'
outFilePath, __ = QFileDialog.getSaveFileName(parent, parent.tr('Save output GeoPackage'), outDir, filter)
outFilePath = str(outFilePath)

if outFilePath:
root, ext = splitext(outFilePath)
if ext.upper() != '.SHP':
outFilePath = '%s.shp' % outFilePath
if ext.upper() != '.GPKG':
outFilePath = '%s.gpkg' % outFilePath
outDir = dirname(outFilePath)
settings.setValue(key, outDir)

Expand Down
157 changes: 142 additions & 15 deletions generalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
begin : 2011-08-17
copyright : (C) 2011 by Piotr Pociask
email : ppociask (at) o2 pl
adapted to QGIS 3 : 2019-11-10 by Sylvain POULAIN
email : sylvain.poulain (at) giscan.com
***************************************************************************/

/***************************************************************************
Expand All @@ -18,36 +20,161 @@
* *
***************************************************************************/
"""
from __future__ import absolute_import
# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from builtins import object
from PyQt5.QtCore import *
from PyQt5.QtGui import *

from PyQt5.QtWidgets import QAction, QMessageBox


from qgis.core import *
# Initialize Qt resources from file resources.py
import resources
from .resources import *
# Import the code for the dialog
from generalizerdialog import generalizerDialog, getLayersNames
from .generalizerdialog import generalizerDialog, getLayersNames
import os.path


class generalizer:

def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface

self.canvas = iface.mapCanvas()

# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)

# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&Generalizer')
# TODO: We are going to let the user set this up in a future iteration
self.toolbar = self.iface.addToolBar(u'Generalizer')
self.toolbar.setObjectName(u'Generalizer')

#print "** INITIALIZING Generalizer"

self.pluginIsActive = False
self.dockwidget = None

self.output_layer = None

# noinspection PyMethodMayBeStatic
def tr(self, message):
"""Get the translation for a string using Qt translation API.

We implement this ourselves since we do not inherit QObject.

:param message: String for translation.
:type message: str, QString

:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('Generalizer', message)

def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None):
"""Add a toolbar icon to the toolbar.

:param icon_path: Path to the icon for this action. Can be a resource
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
:type icon_path: str

:param text: Text that should be shown in menu items for this action.
:type text: str

:param callback: Function to be called when the action is triggered.
:type callback: function

:param enabled_flag: A flag indicating if the action should be enabled
by default. Defaults to True.
:type enabled_flag: bool

:param add_to_menu: Flag indicating whether the action should also
be added to the menu. Defaults to True.
:type add_to_menu: bool

:param add_to_toolbar: Flag indicating whether the action should also
be added to the toolbar. Defaults to True.
:type add_to_toolbar: bool

:param status_tip: Optional text to show in a popup when mouse pointer
hovers over the action.
:type status_tip: str

:param parent: Parent widget for the new action. Defaults None.
:type parent: QWidget

:param whats_this: Optional text to show in the status bar when the
mouse pointer hovers over the action.

:returns: The action that was created. Note that the action is also
added to self.actions list.
:rtype: QAction
"""

icon = QIcon(icon_path)
text = "Generalizer"
action = QAction(icon, text, parent)
action.triggered.connect(callback)
action.setEnabled(enabled_flag)

if status_tip is not None:
action.setStatusTip(status_tip)

if whats_this is not None:
action.setWhatsThis(whats_this)

if add_to_toolbar:
self.toolbar.addAction(action)

if add_to_menu:
self.iface.addPluginToVectorMenu(
self.menu,
action)

self.actions.append(action)

return action


def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(QIcon(":/plugins/generalizer/icon.png"), \
"Generalizer", self.iface.mainWindow())
# connect the action to the run method
self.action.triggered.connect( self.run )
"""Create the menu entries and toolbar icons inside the QGIS GUI."""

icon_path = ':/plugins/Generalizer3/icon.png'
self.add_action(
icon_path,
text=self.tr(u''),
callback=self.run,
parent=self.iface.mainWindow())

# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu("&Generalizer", self.action)

def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu("&Generalizer",self.action)
self.iface.removeToolBarIcon(self.action)
"""Removes the plugin menu item and icon from QGIS GUI."""

#print "** UNLOAD Generalizer"

for action in self.actions:
self.iface.removePluginVectorMenu(
self.tr(u'&Generalizer'),
action)
self.iface.removeToolBarIcon(action)
# remove the toolbar
del self.toolbar

# run method that performs all the real work
def run(self):
Expand Down
Loading