I am having trouble creating/reading OGR VRT files from an Oracle OCI data source.

I am running GDAL 2.2.1 on Windows 7 Professional SP1.

My data source is an Oracle 11g ( 64bit database running ArcSDE (10.2.2 Patch 290200).

I am trying to read spatial and non spatial ArcSDE tables and views. I can read non spatial data without a problem. I can even read the non spatial columns of spatial tables by isolating them using the "SrcSQL" tag. Problems occur only when a spatial column is present.

Below are some simple examples that I have come up with to illustrate/isolate the problem.

This works (non spatial data):

  <OGRVRTLayer name="TEST_tab">
    <SrcSQL>SELECT cast('This is text' AS VARCHAR(255)) AS col_text FROM dual</SrcSQL>

This doesn't work (spatial data - WKB linestring):

  <OGRVRTLayer name="TEST_tab">
    <SrcSQL>SELECT cast('This is text' AS VARCHAR(255)) AS col_text, sde.ST_GeomFromText('LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)',4269) AS col_geom FROM dual</SrcSQL>
    <GeometryField encoding="WKB" field="COL_GEOM"></GeometryField>

Ogrinfo returns the following error - "Unable to identify source field 'COL_GEOM' for geometry."

I have tried specifying "wkbLineString" in a "GeometryType" tag, but the extra tag/specification returns the same error.

After @user30184 @Albert Godfrind for the sdo_geometry cast suggestion, here is a working VRT using the sdo_geometry solution :

  <OGRVRTLayer name="test">
    <SrcSQL>SELECT cast('This is text' AS VARCHAR(255)) AS col_text, sdo_geometry(sde.st_asbinary(sde.ST_GeomFromText('LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)',4269))) AS col_geom FROM dual</SrcSQL>

Note the absence of the "GeometryField" tag. When the tag was included, ogrinfo would return the same "Unable to identify source field 'COL_GEOM' for geometry." error. I am assuming that the error is returned because there is no "SDO_GEOMETRY" encoding option - only "WKT", "WKB" or "PointFromColumns.

The VRT works in QGIS as well!

  • OCI driver expects native Oracle Spatial geometries, not ESRI SDE geometries. – user30184 Jan 4 '18 at 16:39
  • @user30184 Is there any way to cast ESRI SDE geometries so that they may be read using the OCI driver? – Brent Edwards Jan 4 '18 at 16:50
  • I am not aware of such. There is a SDE driver gdal.org/drv_sde.html but I do not know how to make it work. – user30184 Jan 4 '18 at 17:13
  • @user30184 I am aware of the GDAL ESRI ArcSDE driver. It unfortunately seems pretty involved/complex to get it to work properly. – Brent Edwards Jan 4 '18 at 18:30
  • 1
    Have you seen this gis.stackexchange.com/questions/187686/…? – user30184 Jan 4 '18 at 21:37

The OCI driver only understands SDO_GEOMETRY types. One possibility is to turn your st_geometry to wktext:

select ... sdo_geometry(sde.st_astext(shape)...) as ora_geom from ...

See no†e ST_GEOMETRY to SDO_GEOMETRY (mentioned in one comment)

You could define a view on the ESRI table to make the transformation a bit more transparent. I suspect you need some more setup (such as oracle spatial metadata).

Not sure this would work anyway: if you use the VRT from a GIS tool then that will eventually lead to some spatial filter queries being generated as the user pans and zooms. That query will find its way eventually to the OCI driver who will then turn this into an Oracle Spatial filter query (... where sdo_filter (...) ...) which will fail since the ESRI implementation will not understand that.

If all you want is to use ogr2ogr to copy the data out, then the above will not be an issue.

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.