예제 #1
0
 def accept(self):
     if self.rbOutputZip.isChecked():
         output = self.leZipFileName.text()
     else:
         output = self.leDirectoryName.text()
     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(self, self.tr('Directory not empty'), self.tr('Selected directory is not empty. Continue?'), QMessageBox.Yes | QMessageBox.No)
         if res == QMessageBox.No:
             return
     if self.spnZoomMin.value() > self.spnZoomMax.value():
         QMessageBox.warning(self, self.tr('Wrong zoom'), self.tr('Maximum zoom value is lower than minimum. Please correct this and try again.'))
         return
     self.settings.setValue('rootDir', self.leRootDir.text())
     self.settings.setValue('outputToZip', self.rbOutputZip.isChecked())
     self.settings.setValue('outputToDir', self.rbOutputDir.isChecked())
     self.settings.setValue('extentCanvas', self.rbExtentCanvas.isChecked())
     self.settings.setValue('extentFull', self.rbExtentFull.isChecked())
     self.settings.setValue('extentLayer', self.rbExtentLayer.isChecked())
     self.settings.setValue('minZoom', self.spnZoomMin.value())
     self.settings.setValue('maxZoom', self.spnZoomMax.value())
     self.settings.setValue('keepRatio', self.chkLockRatio.isChecked())
     self.settings.setValue('tileWidth', self.spnTileWidth.value())
     self.settings.setValue('tileHeight', self.spnTileHeight.value())
     self.settings.setValue('format', self.cmbFormat.currentIndex ())
     self.settings.setValue('transparency', self.spnTransparency.value())
     self.settings.setValue('quality', self.spnQuality.value())
     self.settings.setValue('enable_antialiasing', self.chkAntialiasing.isChecked())
     self.settings.setValue('use_tms_filenames', self.chkTMSConvention.isChecked())
     self.settings.setValue('write_mapurl', self.chkWriteMapurl.isChecked())
     self.settings.setValue('write_viewer', self.chkWriteViewer.isChecked())
     canvas = self.iface.mapCanvas()
     if self.rbExtentCanvas.isChecked():
         extent = canvas.extent()
     elif self.rbExtentFull.isChecked():
         extent = canvas.fullExtent()
     else:
         layer = utils.getLayerById(self.cmbLayers.itemData(self.cmbLayers.currentIndex()))
         extent = canvas.mapRenderer().layerExtentToOutputExtent(layer, layer.extent())
     extent = QgsCoordinateTransform(canvas.mapRenderer().destinationCrs(), QgsCoordinateReferenceSystem('EPSG:4326')).transform(extent)
     arctanSinhPi = math.degrees(math.atan(math.sinh(math.pi)))
     extent = extent.intersect(QgsRectangle(-180, -arctanSinhPi, 180, arctanSinhPi))
     layers = canvas.mapSettings().layers()
     writeMapurl = self.chkWriteMapurl.isEnabled() and self.chkWriteMapurl.isChecked()
     writeViewer = self.chkWriteViewer.isEnabled() and self.chkWriteViewer.isChecked()
     self.workThread = tilingthread.TilingThread(layers,extent,self.spnZoomMin.value(),self.spnZoomMax.value(),self.spnTileWidth.value(),self.spnTileHeight.value(), self.spnTransparency.value(),self.spnQuality.value(),self.cmbFormat.currentText(),fileInfo,self.leRootDir.text(),self.chkAntialiasing.isChecked(),self.chkTMSConvention.isChecked(),writeMapurl,writeViewer)
     self.workThread.rangeChanged.connect(self.setProgressRange)
     self.workThread.updateProgress.connect(self.updateProgress)
     self.workThread.processFinished.connect(self.processFinished)
     self.workThread.processInterrupted.connect(self.processInterrupted)
     self.btnOk.setEnabled(False)
     self.btnClose.setText(self.tr('Cancel'))
     self.buttonBox.rejected.disconnect(self.reject)
     self.btnClose.clicked.connect(self.stopProcessing)
     self.workThread.start()
예제 #2
0
    def accept(self):
        if self.rbOutputZip.isChecked():
            output = self.leZipFileName.text()
        else:
            output = self.leDirectoryName.text()
        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(
                self,
                self.tr("Directory not empty"),
                self.tr("Selected directory is not empty. Continue?"),
                QMessageBox.Yes | QMessageBox.No,
            )
            if res == QMessageBox.No:
                return
        if self.spnZoomMin.value() > self.spnZoomMax.value():
            QMessageBox.warning(
                self,
                self.tr("Wrong zoom"),
                self.tr("Maximum zoom value is lower than minimum. Please correct this and try again."),
            )
            return
        self.settings.setValue("rootDir", self.leRootDir.text())
        self.settings.setValue("outputToZip", self.rbOutputZip.isChecked())
        self.settings.setValue("outputToDir", self.rbOutputDir.isChecked())
        self.settings.setValue("extentCanvas", self.rbExtentCanvas.isChecked())
        self.settings.setValue("extentFull", self.rbExtentFull.isChecked())
        self.settings.setValue("extentLayer", self.rbExtentLayer.isChecked())
        self.settings.setValue("minZoom", self.spnZoomMin.value())
        self.settings.setValue("maxZoom", self.spnZoomMax.value())
        self.settings.setValue("keepRatio", self.chkLockRatio.isChecked())
        self.settings.setValue("tileWidth", self.spnTileWidth.value())
        self.settings.setValue("tileHeight", self.spnTileHeight.value())
        self.settings.setValue("format", self.cmbFormat.currentIndex())
        self.settings.setValue("transparency", self.spnTransparency.value())
        self.settings.setValue("quality", self.spnQuality.value())
        self.settings.setValue("enable_antialiasing", self.chkAntialiasing.isChecked())
        self.settings.setValue("use_tms_filenames", self.chkTMSConvention.isChecked())
        self.settings.setValue("write_mapurl", self.chkWriteMapurl.isChecked())
        self.settings.setValue("write_viewer", self.chkWriteViewer.isChecked())
        canvas = self.iface.mapCanvas()
        if self.rbExtentCanvas.isChecked():
            extent = canvas.extent()
        elif self.rbExtentFull.isChecked():
            extent = canvas.fullExtent()
        else:
            layer = utils.getLayerById(self.cmbLayers.itemData(self.cmbLayers.currentIndex()))
            extent = canvas.mapRenderer().layerExtentToOutputExtent(layer, layer.extent())
        extent = QgsCoordinateTransform(
            canvas.mapRenderer().destinationCrs(), QgsCoordinateReferenceSystem("EPSG:4326")
        ).transform(extent)
        arctanSinhPi = math.degrees(math.atan(math.sinh(math.pi)))
        extent = extent.intersect(QgsRectangle(-180, -arctanSinhPi, 180, arctanSinhPi))
        layers = canvas.mapSettings().layers()
        writeMapurl = self.chkWriteMapurl.isEnabled() and self.chkWriteMapurl.isChecked()
        writeViewer = self.chkWriteViewer.isEnabled() and self.chkWriteViewer.isChecked()
        self.workThread = tilingthread.TilingThread(
            layers,
            extent,
            self.spnZoomMin.value(),
            self.spnZoomMax.value(),
            self.spnTileWidth.value(),
            self.spnTileHeight.value(),
            self.spnTransparency.value(),
            self.spnQuality.value(),
            self.cmbFormat.currentText(),
            fileInfo,
            self.leRootDir.text(),
            self.chkAntialiasing.isChecked(),
            self.chkTMSConvention.isChecked(),
            writeMapurl,
            writeViewer,
        )

        self.workThread.rangeChanged.connect(self.setProgressRange)
        self.workThread.updateProgress.connect(self.updateProgress)
        self.workThread.processFinished.connect(self.processFinished)
        self.workThread.processInterrupted.connect(self.processInterrupted)
        self.btnOk.setEnabled(False)
        self.btnClose.setText(self.tr("Cancel"))
        self.buttonBox.rejected.disconnect(self.reject)
        self.btnClose.clicked.connect(self.stopProcessing)
        self.workThread.start()
예제 #3
0
    def accept(self):
        if self.rbOutputZip.isChecked():
            output = self.leZipFileName.text()
        elif self.rbOutputDir.isChecked():
            output = self.leDirectoryName.text()
            if not QFileInfo(output).exists():
                os.mkdir(QFileInfo(output).absoluteFilePath())
        elif self.rbOutputNGM.isChecked():
            output = self.leTilesFroNGM.text()

        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(
                self,
                self.tr('Directory not empty'),
                self.tr('Selected directory is not empty. Continue?'),
                QMessageBox.Yes | QMessageBox.No
            )
            if res == QMessageBox.No:
                return

        if self.spnZoomMin.value() > self.spnZoomMax.value():
            QMessageBox.warning(self, self.tr('Wrong zoom'), self.tr('Maximum zoom value is lower than minimum. Please correct this and try again.'))
            return
        self.settings.setValue('rootDir', self.leRootDir.text())
        self.settings.setValue('outputToZip', self.rbOutputZip.isChecked())
        self.settings.setValue('outputToDir', self.rbOutputDir.isChecked())
        self.settings.setValue('outputToNGM', self.rbOutputNGM.isChecked())
        self.settings.setValue('extentCanvas', self.rbExtentCanvas.isChecked())
        self.settings.setValue('extentFull', self.rbExtentFull.isChecked())
        self.settings.setValue('extentLayer', self.rbExtentLayer.isChecked())
        self.settings.setValue('minZoom', self.spnZoomMin.value())
        self.settings.setValue('maxZoom', self.spnZoomMax.value())
        self.settings.setValue('keepRatio', self.chkLockRatio.isChecked())
        self.settings.setValue('tileWidth', self.spnTileWidth.value())
        self.settings.setValue('tileHeight', self.spnTileHeight.value())
        self.settings.setValue('format', self.cmbFormat.currentIndex())
        self.settings.setValue('transparency', self.spnTransparency.value())
        self.settings.setValue('quality', self.spnQuality.value())
        self.settings.setValue('enable_antialiasing', self.chkAntialiasing.isChecked())
        self.settings.setValue('use_tms_filenames', self.chkTMSConvention.isChecked())
        self.settings.setValue('use_mbtiles_compression', self.chkMBTilesCompression.isChecked())
        self.settings.setValue('write_json', self.chkWriteJson.isChecked())
        self.settings.setValue('write_overview', self.chkWriteOverview.isChecked())
        self.settings.setValue('write_mapurl', self.chkWriteMapurl.isChecked())
        self.settings.setValue('write_viewer', self.chkWriteViewer.isChecked())
        self.settings.setValue('renderOutsideTiles', self.chkRenderOutsideTiles.isChecked())
        canvas = self.iface.mapCanvas()
        if self.rbExtentCanvas.isChecked():
            extent = canvas.extent()
        elif self.rbExtentFull.isChecked():
            extent = canvas.fullExtent()
        else:
            layer = utils.getLayerById(self.cmbLayers.itemData(self.cmbLayers.currentIndex()))
            extent = canvas.mapRenderer().layerExtentToOutputExtent(layer, layer.extent())
        extent = QgsCoordinateTransform(canvas.mapRenderer().destinationCrs(), QgsCoordinateReferenceSystem('EPSG:4326')).transform(extent)
        arctanSinhPi = math.degrees(math.atan(math.sinh(math.pi)))
        extent = extent.intersect(QgsRectangle(-180, -arctanSinhPi, 180, arctanSinhPi))
        layers = canvas.layers()
        writeMapurl = self.chkWriteMapurl.isEnabled() and self.chkWriteMapurl.isChecked()
        writeViewer = self.chkWriteViewer.isEnabled() and self.chkWriteViewer.isChecked()
        self.workThread = tilingthread.TilingThread(
            layers,
            extent,
            self.spnZoomMin.value(),
            self.spnZoomMax.value(),
            self.spnTileWidth.value(),
            self.spnTileHeight.value(),
            self.spnTransparency.value(),
            self.spnQuality.value(),
            self.cmbFormat.currentText(),
            fileInfo,
            self.leRootDir.text(),
            self.chkAntialiasing.isChecked(),
            self.chkTMSConvention.isChecked(),
            self.chkMBTilesCompression.isChecked(),
            self.chkWriteJson.isChecked(),
            self.chkWriteOverview.isChecked(),
            self.chkRenderOutsideTiles.isChecked(),
            writeMapurl,
            writeViewer
        )

        self.workThread.rangeChanged.connect(self.setProgressRange)
        self.workThread.updateProgress.connect(self.updateProgress)
        self.workThread.processFinished.connect(self.processFinished)
        self.workThread.processInterrupted.connect(self.processInterrupted)
        self.btnOk.setEnabled(False)
        self.btnClose.setText(self.tr('Cancel'))
        self.buttonBox.rejected.disconnect(self.reject)
        self.btnClose.clicked.connect(self.stopProcessing)
        self.workThread.start()
예제 #4
0
    def accept(self):
        if self.rbOutputZip.isChecked():
            output = self.leZipFileName.text()
        elif self.rbOutputDir.isChecked():
            output = self.leDirectoryName.text()
            if not QFileInfo(output).exists():
                os.mkdir(QFileInfo(output).absoluteFilePath())
        elif self.rbOutputNGM.isChecked():
            output = self.leTilesFroNGM.text()

        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(
                self,
                self.tr('Directory not empty'),
                self.tr('Selected directory is not empty. Continue?'),
                QMessageBox.Yes | QMessageBox.No
            )
            if res == QMessageBox.No:
                return

        if self.spnZoomMin.value() > self.spnZoomMax.value():
            QMessageBox.warning(self, self.tr('Wrong zoom'), self.tr('Maximum zoom value is lower than minimum. Please correct this and try again.'))
            return
        self.settings.setValue('rootDir', self.leRootDir.text())
        self.settings.setValue('outputToZip', self.rbOutputZip.isChecked())
        self.settings.setValue('outputToDir', self.rbOutputDir.isChecked())
        self.settings.setValue('outputToNGM', self.rbOutputNGM.isChecked())
        self.settings.setValue('extentCanvas', self.rbExtentCanvas.isChecked())
        self.settings.setValue('extentFull', self.rbExtentFull.isChecked())
        self.settings.setValue('extentLayer', self.rbExtentLayer.isChecked())
        self.settings.setValue('minZoom', self.spnZoomMin.value())
        self.settings.setValue('maxZoom', self.spnZoomMax.value())
        self.settings.setValue('keepRatio', self.chkLockRatio.isChecked())
        self.settings.setValue('tileWidth', self.spnTileWidth.value())
        self.settings.setValue('tileHeight', self.spnTileHeight.value())
        self.settings.setValue('format', self.cmbFormat.currentIndex())
        self.settings.setValue('transparency', self.spnTransparency.value())
        self.settings.setValue('quality', self.spnQuality.value())
        self.settings.setValue('enable_antialiasing', self.chkAntialiasing.isChecked())
        self.settings.setValue('use_tms_filenames', self.chkTMSConvention.isChecked())
        self.settings.setValue('use_mbtiles_compression', self.chkMBTilesCompression.isChecked())
        self.settings.setValue('write_json', self.chkWriteJson.isChecked())
        self.settings.setValue('write_overview', self.chkWriteOverview.isChecked())
        self.settings.setValue('write_mapurl', self.chkWriteMapurl.isChecked())
        self.settings.setValue('write_viewer', self.chkWriteViewer.isChecked())
        self.settings.setValue('renderOutsideTiles', self.chkRenderOutsideTiles.isChecked())
        canvas = self.iface.mapCanvas()
        if self.rbExtentCanvas.isChecked():
            extent = canvas.extent()
        elif self.rbExtentFull.isChecked():
            extent = canvas.fullExtent()
        else:
            layer = utils.getLayerById(self.cmbLayers.itemData(self.cmbLayers.currentIndex()))
            extent = canvas.mapRenderer().layerExtentToOutputExtent(layer, layer.extent())
        extent = QgsCoordinateTransform(canvas.mapRenderer().destinationCrs(), QgsCoordinateReferenceSystem('EPSG:4326')).transform(extent)
        arctanSinhPi = math.degrees(math.atan(math.sinh(math.pi)))
        extent = extent.intersect(QgsRectangle(-180, -arctanSinhPi, 180, arctanSinhPi))
        layers = canvas.layers()
        writeMapurl = self.chkWriteMapurl.isEnabled() and self.chkWriteMapurl.isChecked()
        writeViewer = self.chkWriteViewer.isEnabled() and self.chkWriteViewer.isChecked()

        options = {
            "extent" : extent,
            "mapUrl" : writeMapurl,
            "layers" : canvas.layers(),
            "rootDir": self.leRootDir.text(),
            "quality": self.spnQuality.value(),
            "minZoom": self.spnZoomMin.value(),
            "maxZoom": self.spnZoomMax.value(),
            "width"  : self.spnTileWidth.value(),
            "height" : self.spnTileHeight.value(),
            "format" : self.cmbFormat.currentText(),
            "outputPath"   : fileInfo,
            "mapViewer"    : writeViewer,
            "transparency" : self.spnTransparency.value(),
            "antialiasing" : self.chkAntialiasing.isChecked(),
            "tmsConvention": self.chkTMSConvention.isChecked(),
            "jsonFile"          : self.chkWriteJson.isChecked(),
            "overview"          : self.chkWriteOverview.isChecked(),
            "renderOutsideTiles": self.chkRenderOutsideTiles.isChecked(),
            "mbtilesCompression": self.chkMBTilesCompression.isChecked(),
        }

        self.progressBar.setFormat(self.tr('Compute number of tiles...'))
        useTMS = 1 if options['tmsConvention'] else -1
        self.countTilesToCompute(Tile(0, 0, 0, useTMS), options)
        self.progressBar.setFormat(self.tr('Rendering: %v from %m (%p%)'))
        self.progressBar.setRange(0, len(self.tilesToCompute))

        tileQueue = []
        tilesPerThread = len(self.tilesToCompute)/(self.threadsAvailable)
        remainingTiles = len(self.tilesToCompute)%(self.threadsAvailable)

        for i in range(self.threadsAvailable):
            thread = i+1
            tileRange = self.tilesToCompute[i*tilesPerThread:thread*tilesPerThread]
            if thread == self.threadsAvailable:
                tileRange.extend(self.tilesToCompute[thread*tilesPerThread:])
            tileQueue.append(tileRange);

        for tiles in tileQueue:
            thread = tilingthread.TilingThread(options, tiles)
            thread.updateProgress.connect(self.updateProgress)
            thread.processFinished.connect(self.processFinished)
            thread.processInterrupted.connect(self.processInterrupted)
            thread.start()
            self.threads.append(thread)

        self.btnOk.setEnabled(False)
        self.btnClose.setText(self.tr('Cancel'))
        self.buttonBox.rejected.disconnect(self.reject)
        self.btnClose.clicked.connect(self.stopProcessing)