GIS: Oracle XE read only support in django.contrib.gis

177 views
Skip to first unread message

vinh...@gmail.com

unread,
Oct 16, 2013, 12:02:01 PM10/16/13
to django-d...@googlegroups.com
Hi,
I have opened a ticket on a method that seems to work to provide read only access to spatial (sdo_geometry) fields in an oracle database using oracle xe. See https://code.djangoproject.com/ticket/21273

In short, we can use the__getattribute__ method of the CLOB field returned by cx_Oracle to access the SDO_GEOMETRY object and to generate WKT, like this:

>>> g_ewkt = "SRID:%s:POINT(%f %f)" % (str(int(g.__getattribute__('SDO_SRID'))), g.__getattribute__('SDO_POINT').X, g.__getattribute__('SDO_POINT').Y)
>>> g_ewkt
'SRID:82086:POINT(162913.389524 340748.357977)'

The Oracle documentation explains in detail how the object works, so accessing a range of geometry types (if not all types) as wkt appears to be feasible.

I'd be grateful on pointers or assistance (or would be happy to help someone who has more familiarity with django.contrib.gis) to move this on.

I understand from comments on the wiki and in the docs that this may be of use to a range of users, if only as a way to transfer legacy data to postgres (which is my use case).

Thanks
Vincent

vinh...@gmail.com

unread,
Oct 25, 2013, 12:33:21 PM10/25/13
to django-d...@googlegroups.com
Hi,
I have uploaded an initial class to handle sdo_geometry.  It is a work in progress, but is generating WKT for POINT & POLYGON geometry.  It needs to be expanded and cleaned up.

See https://code.djangoproject.com/ticket/21273
Vincent

vinh...@gmail.com

unread,
Nov 13, 2013, 9:46:10 AM11/13/13
to django-d...@googlegroups.com
Hi,
I have uploaded a more developed class to handle sdo_geometry.  It now handles the more straightforward cases for all types of geometry, except geometry collection, which is in progress.  Next step is to cover the remainder of the cases (e.g. rectangles and circles within polygons, curved segments, linestrings and polygons with a mix of straight and curved edges etc.).

I am also looking at testing against a test table with a variety of geometries in it.  Does anyone think there would be any licensing issues in using the geometries defined in the Oracle documentation?  Or would it be safer to create my own?

A further task is to try writing data to the cx_Oracle object, which doesn't look to be too difficult, but I haven't tried it yet.

See https://code.djangoproject.com/ticket/21273 (apologies for the typos).

Vincent

vinh...@gmail.com

unread,
Nov 29, 2013, 12:15:30 PM11/29/13
to django-d...@googlegroups.com
 Hi,
I have updated ticket https://code.djangoproject.com/ticket/21273 with an update class to convert oracle sdo_geometry to wkt.
Also attached is sample data covering a number of geometries, a models.py and a short test script.

I'd appreciate a couple of pointers on:
1) How I could convert my current test to a unittest.
2) The best way to integrate this with django - I'm thinking of multi inheritance in django/contrib/gis/db/backends/oracle/operations.py?
3) The best way to load the data to the database (at the moment I'm pasting into SQLPlus).

Thanks
Vincent
Reply all
Reply to author
Forward
0 new messages