def listRIds(self,i=-1,j=-1):
     if (i != -1):
         if (self.getMode()=='row'): 
             connstring=str(conn.getConnString(self,self.getCurrentConnection()))
             rids=conn.listRIDs(self, connstring, str(self.tableWidget.item(i,0).text())+"."+str(self.tableWidget.item(i,1).text()) )
             self.ridComboBox.clear()
             self.ridComboBox.addItems(rids)
Beispiel #2
0
 def loadRaster(self):
     QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
     
     connstring = str(conn.getConnString(self,self.getCurrentConnection()))
     self.checkPostgisRasterExtension(connstring)
     self.plainTextEdit.appendPlainText("Checking parameters...")
     #running gdal2postgis.py
     fileName=str(self.lineEdit.text())
     tablename=str(self.lineEdit_3.text())#(os.path.split(fileName)[-1])[:-4]
     epsg=str(self.lineEdit_2.text())
     """if (self.checkBox_4.isChecked()):
         blocksizex=str(self.spinBox_2.value())
         blocksizey=str(self.spinBox_3.value())
     else:
         blocksizex=blocksizey=None
     nover=self.spinBox.value()
     isexternal=self.checkBox_2.isChecked()
     isAppend=self.checkBox_3.isChecked()"""
     blocksizex=blocksizey=None
     nover=1
     isexternal=False
     isAppend=False
     self.process=rasterLoaderProcess(connstring, fileName, tablename, epsg, blocksizex, blocksizey, nover, isexternal,isAppend)
     QtCore.QObject.connect(self.process,QtCore.SIGNAL('writeText(PyQt_PyObject)'),self.plainTextEdit.appendPlainText)
     QtCore.QObject.connect(self.process,QtCore.SIGNAL('finished()'),self.finishLoadRaster)
     #self.process.run()
     self.process.start()
 def listTables(self,i=0):
     """This method connects to the database using a python Postgres connection and reads the raster_columns table"""
     connstring=conn.getConnString(self,self.getCurrentConnection())
     tables=conn.listTables(self,connstring) #returns a list of pairs (index, value)
     self.tableWidget.clearContents()
     self.tableWidget.setRowCount(0)
     for table in tables:
         self.tableWidget.insertRow(0)
         for pair in table:
             self.tableWidget.setItem(0,pair[0],pair[1])
 def listRIds(self, i=-1, j=-1):
     if (i != -1):
         if (self.getMode() == 'row'):
             connstring = str(
                 conn.getConnString(self, self.getCurrentConnection()))
             rids = conn.listRIDs(
                 self, connstring,
                 str(self.tableWidget.item(i, 0).text()) + "." +
                 str(self.tableWidget.item(i, 1).text()))
             self.ridComboBox.clear()
             self.ridComboBox.addItems(rids)
 def listTables(self, i=0):
     """This method connects to the database using a python Postgres connection and reads the raster_columns table"""
     connstring = conn.getConnString(self, self.getCurrentConnection())
     tables = conn.listTables(
         self, connstring)  #returns a list of pairs (index, value)
     self.tableWidget.clearContents()
     self.tableWidget.setRowCount(0)
     for table in tables:
         self.tableWidget.insertRow(0)
         for pair in table:
             self.tableWidget.setItem(0, pair[0], pair[1])
    def run(self):
        QtGui.QApplication.setOverrideCursor(
            QtGui.QCursor(QtCore.Qt.WaitCursor))

        table = str(self.getTable()).split(".")  #splits table name from schema
        if (table[0] == "GDAL does not support external tables yet"):
            QtGui.QMessageBox.warning(
                self, "Error", "GDAL does not support external tables yet")
            return False
        connstring = str(conn.getConnString(self, self.getCurrentConnection()))
        mode = self.getMode()
        name = ""

        #setting table name and mode
        if (
                mode != 'db'
        ):  #connection string doesn't include table and schema if the whole db is being read
            if len(table) > 1:  #checking if there is schema in the table name
                name += str(table[0])
                connstring += " schema=" + str(table[0])
            connstring += ' table=' + str(table[-1])
            name += "." + str(table[-1])
            if (mode == 'row'):
                connstring += ' mode=1 where=\'rid=' + str(
                    self.ridComboBox.currentText()) + '\''
            elif (mode == 'table'):
                connstring += ' mode=2'
        rlayer = None
        try:
            if (mode == 'convexhull'):  #asked for a vector layer
                uri = QgsDataSourceURI(
                    connstring[4:])  #removes the PG: from the connstring
                uri.setDataSource(
                    "", "(select rid,st_convexhull(rast) as geom from " +
                    name + ")", "geom", "", "rid")
                rlayer = QgsVectorLayer(uri.uri(), name, 'postgres')
            else:
                rlayer = QgsRasterLayer(connstring, name)
                rlayer.setNoDataValue(-32768)
                rlayer.rasterTransparency().initializeTransparentPixelList(
                    -32768)
        except:
            QtGui.QMessageBox.warning(None, "Error", "Could not load layer.")
            #workaround for the nodata problem sets properties to fix the bug

        #try to add layer to qgis.
        if rlayer:
            if rlayer.isValid():
                status = QgsMapLayerRegistry.instance().addMapLayer(rlayer)
            else:
                QtGui.QMessageBox.warning(self, "Error",
                                          "Could not load " + connstring)
        QtGui.QApplication.restoreOverrideCursor()
 def loadRaster(self):
     QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
     
     connstring = str(conn.getConnString(self,self.getCurrentConnection()))
     self.checkPostgisRasterExtension(connstring)
     self.plainTextEdit.appendPlainText("Checking parameters...")
     #running gdal2postgis.py
     fileName=str(self.lineEdit.text())
     tablename=str(self.lineEdit_3.text())#(os.path.split(fileName)[-1])[:-4]
     epsg=str(self.lineEdit_2.text())
     """if (self.checkBox_4.isChecked()):
         blocksizex=str(self.spinBox_2.value())
         blocksizey=str(self.spinBox_3.value())
     else:
         blocksizex=blocksizey=None
     nover=self.spinBox.value()
     isexternal=self.checkBox_2.isChecked()
     isAppend=self.checkBox_3.isChecked()"""
     blocksizex=blocksizey=None
     nover=1
     isexternal=False
     isAppend=False
     import raster2pgsql
     
     cmd=['wktraster','-r',fileName,"-t",tablename,"-s",epsg,"-I","-M"]
     (opts, args)=raster2pgsql.no_command_line(cmd)
     buff=buffer(connstring)
     opts.output=buff
     parmlist=connstring.split(" ")
     buff.write('BEGIN;\n')
     
     if (blocksizex!=None):
         self.cmd+=["-k",blocksizex+"x"+blocksizey]
     if (isexternal): self.cmd.append("-R")
     if (isAppend): self.cmd.append('-a')
     self.connstring=connstring
     self.nover=nover
     #self.sql='python raster2pgsql.py -r '+self.cmd[2]+" -t "+tablename+" -s "+epsg+"-I -M"
     #if( (blocksizex!=None) and (blocksizey!=None)):
     #    self.sql+="-k "+blocksizex+"x"+blocksizey
     raster2pgsql.make_sql_create_table(opts)
     raster2pgsql.wkblify_raster(opts, fileName.replace( '\\', '/') , 0, None)
     buffer.write('END;\n')
     res=buffer.commit()
     if (res!=""): self.plainTextEdit.appendPlainText(str(res)) 
     #self.process=rasterLoaderProcess(connstring, fileName, tablename, epsg, blocksizex, blocksizey, nover, isexternal,isAppend)
     QtCore.QObject.connect(self.process,QtCore.SIGNAL('writeText(PyQt_PyObject)'),self.plainTextEdit.appendPlainText)
     QtCore.QObject.connect(self.process,QtCore.SIGNAL('finished()'),self.finishLoadRaster)
     #self.process.run()
     self.process.start()
 def run(self): 
     QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
     
     table=str(self.getTable()).split(".") #splits table name from schema
     if (table[0]=="GDAL does not support external tables yet"):
         QtGui.QMessageBox.warning(self,"Error", "GDAL does not support external tables yet")
         return False
     connstring = str(conn.getConnString(self,self.getCurrentConnection()))
     mode=self.getMode()
     name=""
     
     #setting table name and mode 
     if (mode!='db'): #connection string doesn't include table and schema if the whole db is being read
         if len(table)>1: #checking if there is schema in the table name
             name+=str(table[0])
             connstring+=" schema="+str(table[0])
         connstring+=' table='+str(table[-1])
         name+="."+str(table[-1])
         if (mode=='row'):
             connstring+=' mode=1 where=\'rid='+str(self.ridComboBox.currentText())+'\''
         elif (mode=='table'):
             connstring+=' mode=2'
     rlayer=None
     try:
         if (mode=='convexhull'):#asked for a vector layer
             uri=QgsDataSourceURI(connstring[4:]) #removes the PG: from the connstring
             uri.setDataSource("", "(select rid,st_convexhull(rast) as geom from "+name+")", "geom", "", "rid")
             rlayer=QgsVectorLayer(uri.uri(),name,'postgres')
         else:
             rlayer = QgsRasterLayer(connstring, name)
             rlayer.setNoDataValue(-32768)
             rlayer.rasterTransparency().initializeTransparentPixelList(-32768)
     except :
         QtGui.QMessageBox.warning(None,"Error","Could not load layer.")        
             #workaround for the nodata problem sets properties to fix the bug
     
     
     #try to add layer to qgis.
     if rlayer: 
         if rlayer.isValid():
             status=QgsMapLayerRegistry.instance().addMapLayer(rlayer)
         else:
             QtGui.QMessageBox.warning(self,"Error", "Could not load "+connstring)
     QtGui.QApplication.restoreOverrideCursor()