diff --git a/CHANGELOG b/CHANGELOG index 8b8a2b9..e2c3265 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +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 diff --git a/dialogs.py b/dialogs.py index 6209e40..5f4f0b9 100644 --- a/dialogs.py +++ b/dialogs.py @@ -1,6 +1,7 @@ from builtins import str from PyQt5.QtGui import * from PyQt5.QtCore import * +from PyQt5.QtWidgets import * from os.path import splitext, dirname @@ -10,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) + 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) diff --git a/generalizerdialog.py b/generalizerdialog.py index 3fad443..928247e 100644 --- a/generalizerdialog.py +++ b/generalizerdialog.py @@ -478,8 +478,8 @@ def LoadLayers(self, fileList): else: out_name = filePath[(len(filePath) - filePath.rfind("/")) - 1:] - if out_name.endswith(".shp"): - out_name = out_name[:len(out_name) - 4] + if out_name.endswith(".gpkg"): + out_name = out_name[:len(out_name) - 5] self.iface.addVectorLayer(filePath, out_name, "ogr") @@ -497,9 +497,11 @@ def doGeneralize(self, iLayerName, iLayer, oPath, func, arguments): #else: # mLayer = QgsVectorLayer('MultiLineString', iLayerName + '_memory', 'memory')#self.NameFromFunc(func, arguments), 'memory') if iLayer.wkbType() == QgsWkbTypes.LineString: - mLayer = QgsVectorLayer('LineString?crs=' + crs.authid() + '&field=MYNYM:integer&field=MYTXT:string', iLayerName + '_memory', 'memory')#self.NameFromFunc(func, arguments), 'memory') + #mLayer = QgsVectorLayer('LineString?crs=' + crs.authid() + '&field=MYNYM:integer&field=MYTXT:string', iLayerName + '_memory', 'memory')#self.NameFromFunc(func, arguments), 'memory') + mLayer = QgsVectorLayer('LineString?crs=' + crs.authid(), iLayerName + '_memory', 'memory') else: - mLayer = QgsVectorLayer('MultiLineString?crs=' + crs.authid() + '&field=MYNYM:integer&field=MYTXT:string', iLayerName + '_memory', 'memory')#self.NameFromFunc(func, arguments), 'memory') + #mLayer = QgsVectorLayer('MultiLineString?crs=' + crs.authid() + '&field=MYNYM:integer&field=MYTXT:string', iLayerName + '_memory', 'memory')#self.NameFromFunc(func, arguments), 'memory') + mLayer = QgsVectorLayer('MultiLineString?crs=' + crs.authid(), iLayerName + '_memory', 'memory') mProvider = mLayer.dataProvider() mProvider.addAttributes( [key for key in fields] ) @@ -517,7 +519,7 @@ def doGeneralize(self, iLayerName, iLayer, oPath, func, arguments): if len(l2) > 1: l.append(l2) if len(l) > 1: - fet.setGeometry(QgsGeometry.fromMultiPolyline(l)) + fet.setGeometry(QgsGeometry.fromMultiPolylineXY(l)) elif len(l) == 1: #jesli z obiektu wieloczesciowego zostaje tylko jedna linia (np. przy usuwaniu malych obiektow) fet.setGeometry(QgsGeometry.fromPolyline(l[0])) else: @@ -537,7 +539,8 @@ def doGeneralize(self, iLayerName, iLayer, oPath, func, arguments): return mLayer else: #write shapefile on disk - writer = QgsVectorFileWriter(oPath, iProvider.encoding(), fields, QGis.WKBLineString, iLayer.crs()) + #writer = QgsVectorFileWriter(oPath, iProvider.encoding(), fields, QGis.WKBLineString, iLayer.crs()) + writer = QgsVectorFileWriter(oPath, iProvider.encoding(), fields, QgsWkbTypes.LineString, iLayer.crs()) if writer.hasError() != QgsVectorFileWriter.NoError: QMessageBox.critical(None, 'Generalizer', 'Error when creating shapefile: %s' % (writer.hasError())) @@ -557,7 +560,7 @@ def doGeneralize(self, iLayerName, iLayer, oPath, func, arguments): l.append(l2) if len(l) > 1: #QInputDialog.getText( self.iface.mainWindow(), "m", "e", QLineEdit.Normal, str(l) ) - fet.setGeometry(QgsGeometry.fromMultiPolyline(l)) + fet.setGeometry(QgsGeometry.fromMultiPolylineXY(l)) else: ls = geom.asPolyline() #QInputDialog.getText( self.iface.mainWindow(), "m", "e", QLineEdit.Normal, str(ls) ) @@ -597,9 +600,9 @@ def batchGeneralize(self, layers): #QInputDialog.getText( self.iface.mainWindow(), "m", "e", QLineEdit.Normal, str(i) ) path = self.ui.eDir.text() if path.contains("\\"): - out_name = path + '\\' + layer + '_new.shp' + out_name = path + '\\' + layer + '_new.gpkg' else: - out_name = path + '/' + layer + '_new.shp' + out_name = path + '/' + layer + '_new.gpkg' outNames.append(out_name) vLayer = self.doGeneralize(layer, vLayer, out_name, func, arguments) else: diff --git a/metadata.txt b/metadata.txt index f5b789e..1a396f3 100644 --- a/metadata.txt +++ b/metadata.txt @@ -1,10 +1,28 @@ [general] -name=Generalizer +name=Generalizer3 +email=sylvain.poulain@giscan.com qgisMinimumVersion=3.0 description=Lines generalization and smoothing (partially based on v.generalize GRASS module) -version=0.6 +about=Plugin to Generalize, Simplify or Smooth lines in QGIS + Functions : + Remove small objects + Simplify : + Douglas-Peucker Algorithm + Jenk's Algorithm + Lang Algorithm + Reumann-Witkam Algorithm + Vertex Reduction + Smooth : + Boyle's Forward-Looking Algorithm + Chaiken's Algorithm + Hermite Spline Interpolation + McMaster's Distance-Weighting Algorithm + Distance Weighting + McMaster's Sliding Averaging Algorithm + Snakes Algorithm : Slowest smoothing algorithm +version=0.7 author=Piotr Pociask, Matthew Petroff, Sylvain POULAIN -email=sylvain.poulain (at) giscan.com + # end of mandatory metadata @@ -14,6 +32,7 @@ homepage=https://github.com/giscan/Generalizer tracker=https://github.com/giscan/Generalizer/issues repository=https://github.com/giscan/Generalizer icon=icon.png +tags=line,vector,smooth,simplify # experimental flag experimental=True @@ -22,6 +41,9 @@ experimental=True deprecated=False changelog= + 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