pythonpandasgiscx-oracle

How to read out geometric data from Oracle DB in MDSYS format and convert to shapely format or GeoJson?


I'm reading out an Oracle DB with geospatial geometries which I save in a pandas dataframe, say df having a geometric object of format <cx_Oracle.Object MDSYS.SDO_GEOMETRY at 0x7f28 in a column named 'geometry'. Let's store it as:

g = df.geometry[0]

What I want to do:

Transform the data stored g to present it on a folium map as a PolyLine from shapely. I know that it consists of a bunch of points representing a line object.

What I can do:

  1. I can read out the SDO_GTYPE, i.e. g.SDO_GTYPE gives 2002.

  2. I can read out SDO_ORDINATES, but it won't show me the coordinates, saying: <cx_Oracle.Object MDSYS.SDO_ORDINATE_ARRAY at 0x7f287848e4f0>.

What I cannot do:

  1. Transform geometric information with shapely and asShape:
from shapely.geometry import asShape
shape = asShape(g)

gives error: 'Context does not provide geo interface'.

  1. Use Get_WKT() or any other functions in SQL-Statements

There are colleagues reading the data with a GIS-tool, i.e. why I doubt that the data is corrupt. I would be happy about any suggestions regarding this issue.

Thanks a lot.


Solution

  • Don't have any experience with Oracle DB, but this SO question seems similar to yours.