Skip to content

Commit

Permalink
fix save layer and unattended column
Browse files Browse the repository at this point in the history
0.7 (17.05.2020)
- fix save layer to file
- remove unattended column in temporary layer
  • Loading branch information
kikislater authored May 17, 2020
1 parent 10df340 commit 6ed7e1e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 5 additions & 4 deletions dialogs.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)

Expand Down
21 changes: 12 additions & 9 deletions generalizerdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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] )
Expand All @@ -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:
Expand All @@ -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()))

Expand All @@ -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) )
Expand Down Expand Up @@ -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:
Expand Down
28 changes: 25 additions & 3 deletions metadata.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
[general]
name=Generalizer
name=Generalizer3
[email protected]
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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6ed7e1e

Please sign in to comment.