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

Fixed a various bugs #126

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions mbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ def compression_finalize(cur):
cur.execute("""
CREATE UNIQUE INDEX images_id on images
(tile_id);""")
cur.execute("""vacuum;""")
cur.execute("""analyze;""")

def getDirs(path):
return [name for name in os.listdir(path)
Expand Down
14 changes: 13 additions & 1 deletion qtilesdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QMessageBox, QFileDialog
from qgis.PyQt import uic
from qgis.core import QgsRectangle
from qgis.gui import QgsGui

from . import tilingthread
from . import qtiles_utils as utils
Expand All @@ -50,6 +51,9 @@ def __init__(self, iface):
QDialog.__init__(self)
self.setupUi(self)

self.setObjectName("qtiles_main_window")
QgsGui.enableAutoGeometryRestore(self, "qtiles_main_window")

self.btnOk = self.buttonBox.addButton(self.tr("Run"), QDialogButtonBox.AcceptRole)

# self.spnZoomMax.setMaximum(self.MAX_ZOOM_LEVEL)
Expand Down Expand Up @@ -192,13 +196,21 @@ def accept(self):
elif self.rbOutputNGM.isChecked():
output = self.leTilesFroNGM.text()

if self.rbExtentLayer.isChecked() and self.cmbLayers.currentIndex() < 0:
if self.rbOutputZip.isChecked() and QFileInfo.exists(output):
ans = QMessageBox.question(self, self.tr('File is exists'),
self.tr('The file exists and will be overwritten. Continue?'))

if ans == QMessageBox.StandardButton.No:
return

if self.rbExtentLayer.isChecked() and self.cmbLayers.currentIndex() < 0:
QMessageBox.warning(self, self.tr('Layer not selected'), self.tr('Please select a layer and try again.'))
return

if not output:
QMessageBox.warning(self, self.tr('No output'), self.tr('Output path is not set. Please enter correct path and try again.'))
return

fileInfo = QFileInfo(output)
if fileInfo.isDir() and not len(QDir(output).entryList(QDir.Dirs | QDir.Files | QDir.NoDotAndDotDot)) == 0:
res = QMessageBox.warning(
Expand Down
11 changes: 7 additions & 4 deletions tilingthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,9 @@ def writeMapurlFile(self):

def writeLeafletViewer(self):
templateFile = QFile(':/resources/viewer.html')
if templateFile.open(QIODevice.ReadOnly | QIODevice.Text):
viewer = MyTemplate(str(templateFile.readAll()))
if templateFile.open(QIODevice.ReadOnly):
html = templateFile.readAll().data().decode()
viewer = MyTemplate(html)

tilesDir = '%s/%s' % (self.output.absoluteFilePath(), self.rootDir)
useTMS = 'true' if self.tmsConvention else 'false'
Expand All @@ -262,8 +263,10 @@ def writeLeafletViewer(self):
}

filePath = '%s/%s.html' % (self.output.absoluteFilePath(), self.rootDir)
with codecs.open(filePath, 'w', 'utf-8') as fOut:
fOut.write(viewer.substitute(substitutions))

with open(filePath, 'wb') as fOut:
s = viewer.substitute(substitutions)
fOut.write(s.encode('utf-8'))
templateFile.close()

def countTiles(self, tile):
Expand Down
51 changes: 38 additions & 13 deletions ui/qtilesdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>367</width>
<height>429</height>
<width>365</width>
<height>625</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand All @@ -82,7 +82,16 @@
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -138,17 +147,20 @@
</property>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<property name="verticalSpacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>3</number>
</property>
<item row="2" column="2">
<widget class="QLineEdit" name="leTilesFroNGM">
<property name="toolTip">
<string/>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string/>
</property>
Expand Down Expand Up @@ -232,6 +244,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -273,6 +288,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="3">
Expand All @@ -284,7 +302,7 @@
</sizepolicy>
</property>
<property name="text">
<string>...</string>
<string>Select</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -542,13 +560,13 @@
<property name="title">
<string>Parameters</string>
</property>
<property name="collapsed">
<property name="collapsed" stdset="0">
<bool>true</bool>
</property>
<property name="scrollOnExpand">
<property name="scrollOnExpand" stdset="0">
<bool>true</bool>
</property>
<property name="saveCollapsedState">
<property name="saveCollapsedState" stdset="0">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
Expand Down Expand Up @@ -650,7 +668,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -991,8 +1018,6 @@
</layout>
</item>
</layout>
<zorder>horizontalLayoutWidget_2</zorder>
<zorder>scrollArea</zorder>
</widget>
<customwidgets>
<customwidget>
Expand Down
7 changes: 5 additions & 2 deletions writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def __init__(self, outputPath, rootDir):
self.output = outputPath
self.rootDir = rootDir

if os.path.exists(self.output):
os.remove(self.output)

self.zipFile = zipfile.ZipFile(str(self.output.absoluteFilePath()), 'w', allowZip64=True)
self.tempFile = QTemporaryFile()
self.tempFile.setAutoRemove(False)
Expand Down Expand Up @@ -163,7 +166,6 @@ def writeTile(self, tile, image, format, quality):
buff.close()

def finalize(self):
optimize_database(self.connection)
self.connection.commit()
if self.compression:
# start compression
Expand All @@ -173,8 +175,9 @@ def finalize(self):
total_tiles = res[0]
compression_do(self.cursor, self.connection, total_tiles)
compression_finalize(self.cursor)
optimize_database(self.connection)
self.connection.commit()
# end compression

optimize_database(self.connection)
self.connection.close()
self.cursor = None