#21273: Add read only support for Oracle XE to django.contrib.gis
--------------------------------------+------------------------------------
     Reporter:  vinhussey             |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  GIS                   |                  Version:  master
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  1
  Needs tests:  1                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by vinhussey):

 Hi Shai,
 Thanks for the constructive comments.  I have changed from the  explicit
 use of `__getattribute__` as suggested.

 The reason for taking this approach is that Oracle XE does not provide a
 WKT function.  See these comments in
 
https://github.com/django/django/blob/master/django/contrib/gis/db/backends/oracle/operations.py
 {{{
 """
 This module contains the spatial lookup types, and the
 `get_geo_where_clause`
 routine for Oracle Spatial.

 Please note that WKT support is broken on the XE version, and thus
 this backend will not work on such platforms. Specifically, XE lacks
 support for an internal JVM, and Java libraries are required to use
 the WKT constructors.
 """
 ...
 class OracleOperations(DatabaseOperations, BaseSpatialOperations):
     compiler_module = "django.contrib.gis.db.backends.oracle.compiler"

     name = 'oracle'
     oracle = True
     valid_aggregates = {'Union', 'Extent'}

     Adapter = OracleSpatialAdapter
     Adaptor = Adapter # Backwards-compatibility alias.

     area = 'SDO_GEOM.SDO_AREA'
     gml = 'SDO_UTIL.TO_GMLGEOMETRY'
     centroid = 'SDO_GEOM.SDO_CENTROID'
     difference = 'SDO_GEOM.SDO_DIFFERENCE'
     distance = 'SDO_GEOM.SDO_DISTANCE'
     extent = 'SDO_AGGR_MBR'
     intersection = 'SDO_GEOM.SDO_INTERSECTION'
     length = 'SDO_GEOM.SDO_LENGTH'
     num_geom = 'SDO_UTIL.GETNUMELEM'
     num_points = 'SDO_UTIL.GETNUMVERTICES'
     perimeter = length
     point_on_surface = 'SDO_GEOM.SDO_POINTONSURFACE'
     reverse = 'SDO_UTIL.REVERSE_LINESTRING'
     sym_difference = 'SDO_GEOM.SDO_XOR'
     transform = 'SDO_CS.TRANSFORM'
     union = 'SDO_GEOM.SDO_UNION'
     unionagg = 'SDO_AGGR_UNION'

     # We want to get SDO Geometries as WKT because it is much easier to
     # instantiate GEOS proxies from WKT than SDO_GEOMETRY(...) strings.
     # However, this adversely affects performance (i.e., Java is called
     # to convert to WKT on every query). If someone wishes to write a
     # SDO_GEOMETRY(...) parser in Python, let me know =)

 }}}

 Once we have WKT, we can use geos, so thanks for that tip.

 Vincent

 Replying to [comment:8 shai]:
 > Hi Vincent,
 >
 > I am far from being a !GeoDjango expert; in fact, I only started looking
 into it recently. I usually handle Oracle issues, but I don't use Oracle
 XE currently, and am not sure exactly how much spatial functionality is
 available on XE. I took a look at your latest code, and I have some
 comments.
 >
 > First of all, the general scope of the work: As far as I could see, what
 you have added is a class for interpreting the SDO_GEOMETRY type; do you
 intend to also support other operations, such as geometric queries? Are
 they supported on XE? If not, the best integration into Django seems to be
 a custom field type.
 >
 > Second, technical details:
 >
 > The most glaring point in your code is the explicit use of
 `__getattribute__`: This is a "magic method" in Python, it implements
 attribute access. You should be able to replace every occurrence of
 `self.geometry.__getattribute__('NAME')` with `self.geometry.NAME`, for
 every `NAME`.
 >
 > The second is -- instead of trying to generate the WKT yourself, it
 seems better to use GEOS objects -- WKT generation is already implemented
 there, as long as a ton of other functionality. The GEOS objects are
 explained [https://docs.djangoproject.com/en/1.6/ref/contrib/gis/geos/
 here].
 >
 > So -- the right thing to achieve, apparently, is a custom field, which
 inherits `TextField` and interprets the object it gets as a GEOS object. I
 haven't looked into the !GeoDjango (Oracle backend) code, but perhaps you
 can extract some code from there which will help you; I'd be a little
 surprised if SDO_GEOMETRY objects themselves are much different between
 Oracle XE and Standard.
 >
 > Hope this helps,
 > Shai.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21273#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.7bb4486588dc840f066e43943ffd7e3f%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to