2

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/[email protected]: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()

1 Answer 1

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/[email protected]: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 and acknowledge you have read our privacy policy.

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