示例#1
0
    def saveOrtho(self):
        reply = QtGui.QMessageBox.question(
            self,
            "Message",
            "Continue with the current purple bounding box ?",
            QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
            QtGui.QMessageBox.No,
        )
        if reply == QMessageBox.Yes:
            meterPerPixel = self.ui.spinBox.value()
            totPixN = (self.l_nord / meterPerPixel) * self.viewOrtho.resolution
            totPixE = (self.l_est / meterPerPixel) * self.viewOrtho.resolution
            self.viewOrtho.getViewPortZoom()
            orthoSavedParam = [totPixN, totPixE, self.viewOrtho.ParamViewport]
            a = self.viewOrtho.getMaxBufferSize()

            try:
                if not self.isFrameBufferSupported:
                    QMessageBox.warning(
                        self,
                        "OpenGL Version",
                        "The current openGL Version does not support frame buffer.\n Raster with less pixel than screen can be saved only.",
                    )
                    if self.resolution.height() < totPixN or self.resolution.width() < totPixE:
                        raise ValueError
                if totPixE > a or totPixN > a:
                    raise ValueError
            except ValueError:
                QMessageBox.warning(self, "Value Error", "Failed to save raster.\nConsider increasing the resolution.")
            else:
                self.orthoSaveInstance = viewOrtho_class(
                    self.pointBuffer,
                    self.picture_name,
                    self.modelview,
                    self.projection,
                    self.viewport,
                    self.texture,
                    orthoSavedParam,
                    self.crs,
                    meterPerPixel,
                    self.demName,
                    self.isFrameBufferSupported,
                )

                if not self.isFrameBufferSupported:
                    totPixN = int(orthoSavedParam[0])
                    totPixE = int(orthoSavedParam[1])
                    self.orthoSaveInstance.show()
                    self.orthoSaveInstance.resize(totPixE, totPixN)
                    self.orthoSaveInstance.resizeGL(totPixE, totPixN)
                    self.orthoSaveInstance.updateGL()
                self.orthoSaveInstance.saveOrtho()
                self.orthoSaveInstance.close()
                self.close()
示例#2
0
 def __init__(self, pointBuffer, picture_name,
                                       modelview,
                                       projection,
                                       viewport,
                                       texture,
                                       crs,
                                       demName,
                                       isFrameBufferSupported,
                                       Xmat,
                                       Ymat,
                                       parent = None):#20150923
                                       
     QtGui.QMainWindow.__init__(self)
     self.ui = Ui_drapping()
     self.ui.setupUi(self)
     self.pointBuffer = pointBuffer
     self.modelview = modelview
     self.projection = projection
     self.viewport = viewport
     self.texture = texture
     self.picture_name = picture_name
     self.crs = crs
     self.demName = demName
     self.isFrameBufferSupported = isFrameBufferSupported
     
     self.Xmat = Xmat
     self.Ymat = Ymat
     
     self.viewOrtho = viewOrtho_class(pointBuffer, picture_name,
                                       modelview,
                                       projection,
                                       viewport,
                                       texture)
     
     self.viewOrtho.makeCurrent()
     self.setCentralWidget(self.viewOrtho)
     self.resolution = QDesktopWidget().screenGeometry()
     size = [0,0]
     size[1] = self.resolution.height()/2
     l_nord =  pointBuffer.l_nord
     self.l_nord = l_nord
     l_est =  pointBuffer.l_est
     self.l_est = l_est
     ratio =  l_nord /float(l_est)
     size[0] = size[1]/ratio
     self.resize(size[0]+200,size[1])
     
     self.viewOrtho.getBound.connect(self.displayBound)
     
     self.ui.saveButton.clicked.connect(self.saveOrtho)
    def createMaskClip(self, path):
        name = path + "raster12.tiff"
        self.getOrtho(True)
        meterPerPixel = 10
        totPixN = (self.qgl_window.l_nord / meterPerPixel) * self.qgl_window.resolution
        totPixE = (self.qgl_window.l_est / meterPerPixel) * self.qgl_window.resolution
        ParamViewport = [0, 0, 1, 1]
        orthoSavedParam = [totPixN, totPixE, ParamViewport]
        """
        a = self.viewOrtho.getMaxBufferSize()
        try:
            if not self.isFrameBufferSupported:
                QMessageBox.warning(self, "OpenGL Version","The current openGL Version does not support frame buffer.\n Raster with less pixel than screen can be saved only.")
                if self.resolution.height() < totPixN or self.resolution.width() < totPixE:
                    raise ValueError
            if totPixE > a or totPixN > a:
                raise ValueError
        except ValueError:
            QMessageBox.warning(self, "Value Error","Failed to save raster.\nConsider increasing the resolution.")"""
        self.orthoSaveInstance = viewOrtho_class(
            self.pointBuffer,
            self.picture_name,
            self.qgl_window.modelview,
            self.qgl_window.projection,
            self.qgl_window.viewport,
            self.texture,
            orthoSavedParam,
            self.crs,
            meterPerPixel,
            self.demName,
            self.isFrameBufferSupported,
        )

        if not self.isFrameBufferSupported:
            totPixN = int(orthoSavedParam[0])
            totPixE = int(orthoSavedParam[1])
            self.orthoSaveInstance.show()
            self.orthoSaveInstance.resize(totPixE, totPixN)
            self.orthoSaveInstance.resizeGL(totPixE, totPixN)
            self.orthoSaveInstance.updateGL()
        self.orthoSaveInstance.saveOrtho(name)
        self.orthoSaveInstance.close()

        try:
            sourceRaster = gdal.Open(name)
            band = sourceRaster.GetRasterBand(4)
            bandArray = band.ReadAsArray()
            outShapefile = path + "polygonized"
            driver = ogr.GetDriverByName("ESRI Shapefile")

            if os.path.exists(outShapefile + ".shp"):
                driver.DeleteDataSource(outShapefile + ".shp")
            outShapefile = path + "polygonized"
            outDatasource = driver.CreateDataSource(outShapefile + ".shp")

            outLayer = outDatasource.CreateLayer("polygonized", None)
            newField = ogr.FieldDefn("MYFLD", ogr.OFTInteger)

            outLayer.CreateField(newField)
            gdal.Polygonize(band, None, outLayer, 0, [], callback=None)

            layer = outDatasource.GetLayer()
            indice = 0
            for feature in layer:
                indice += 1
                if feature.GetField("MYFLD") == 0:
                    layer.DeleteFeature(feature.GetFID())

        finally:
            outLayer = None
            outShapefile = None
            sourceRaster = None
            if "outDatasource" in locals():
                outDatasource.Destroy()