Creating and showing vector layer for Oracle GeometryCollection with PyQGIS
I have a table in my Oracle database with multiple different geometry types (ie, points and lines). Now, I want to show the data in QGIS.
I can create a new vector layer, however, its geometry type is arbitrarily defined as either point or line. Although all features are displayed in the attribute table, they aren't displayed in the map when their geometry type is different from the previously mentioned type chosen by QGIS.
I also tried a filter expression on the table that checks for the SDO_GTYPE within the layers' filter expression:
However, that prompts an error, as GET_GTYPE isn't defined (it's defined on Oracle's SDO_GEOMETRY type, but that seems inaccessible in the filter expression).
Ultimately, I want to create a Python script that does this:
writer_options = QgsVectorFileWriter.SaveVectorOptions()
writer_options.driverName = 'GPKG'
result = QgsVectorFileWriter.writeAsVectorFormatV3(layerFromOracle, outFile, QgsProject.instance().transformContext(), options=writer_options)
EDIT: From https://gis.stackexchange.com/a/197800/20297 I got, that I can create a layer from any arbitrary SQL-expression using this:
uri = QgsDataSourceURI()
uri.setConnection('host', 'port', 'database', 'username', 'password')
sql = 'SELECT * FROM myschema.mytable t WHERE t.geometrie.get_gtype() = 2'
uri.setDataSource('', '(' + sql + ')', 'geometrie', '', 'id')
vlayer = QgsVectorLayer(uri.uri(), 'LayerName','oracle')
which I'd like to save then to my output-file. However when I check if that layer is valid, it returns False. Furthermore, when adding it to my map, I get a warning that the datasource for the layer is broken. However when opening that layers' properties, it seems, QGIS is able to query the correct data, but is unable to get the appropriate geometry-type and thus to display it properly: