1

Able to connect to Oracle Spatial 11g and print tables with SDO_GEORASTER attribute both in QGIS python console and standalone application.I get below error when loading rasters from oracle Table.

Traceback (most recent call last): File "", line 1, in Exception: unknown

    strProjetName = "C:/OSGeo4W/apache/htdocs/QGIS-Web-Client-master/projects/myworld.qgs"
    def add_LayersFromDB():
        QGISAPP = QgsApplication(sys.argv, True)     
        QgsApplication.setPrefixPath(r"C:\OSGeo4W\apps\qgis", True)
        QgsApplication.initQgis()

        #Connect to Oracle and Fetch Table Names 
        con = cx_Oracle.connect('myoradb/myoradb@189.53.61.140:1521/newdev')
        print con.version
        cur = con.cursor()
        cur.execute(u"select TABLE_NAME from user_tab_columns where data_type='SDO_GEORASTER'")

        tables = cur.fetchall()
        print tables

        QgsProject.instance().setFileName(strProjetName)
        print QgsProject.instance().fileName()
        render = QgsMapRenderer()

        uri = QgsDataSourceURI()
        uri.setConnection("189.53.61.140", "1521", "newdev", "myoradb", "myoradb")

        render = QgsMapRenderer()

        for t in tables :
           print str(t[0])      
           uri.setDataSource('',  str(t[0]), "RAST")
           uri.uri()
           vlayer = QgsRasterLayer(uri.uri(),str(t[0]), 'oracle') #FAILS HERE
           QgsMapLayerRegistry.instance().addMapLayer(vlayer)
           lst = [ vlayer.id() ]
           render.setLayerSet(lst)
           rect = QgsRectangle(render.fullExtent())            
           rect.scale(1.1)
           render.setExtent(rect)

        QgsProject.instance().write()
        cur.close()
        con.close()         
        QgsApplication.exitQgis()

    add_LayersFromDB()
0

Figured out a way to add SDO_GEORASTER to QGIS using PyQGIS.Thanks to Tim Sutton for suggesting right usage.

lyr=QgsRasterLayer("geor:testinstance/testinstance@184.54.67.146:1521/MyoraDB,RAST_RDT,2300","DEM1")

if layer.isValid():
    layer.setContrastEnhancement( QgsContrastEnhancement.StretchToMinimumMaximum )

QgsMapLayerRegistry.instance().addMapLayer( layer )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.