ó
®â0_c           @   sI  d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(   sU  
 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.
iÿÿÿÿN(   t   BaseSpatialOperations(   t   OracleSpatialAdapter(   t   SpatialOperator(   t
   aggregates(   t   Geometry(   t   Distance(   t   DatabaseOperations(   t   six(   t   cached_propertys   0.05t   SDOOperatorc           B   s   e  Z d  Z RS(   s#   %(func)s(%(lhs)s, %(rhs)s) = 'TRUE'(   t   __name__t
   __module__t   sql_template(    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyR	      s   t   SDODistancec           B   s   e  Z d  e Z RS(   s@   SDO_GEOM.SDO_DISTANCE(%%(lhs)s, %%(rhs)s, %s) %%(op)s %%(value)s(   R
   R   t   DEFAULT_TOLERANCER   (    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyR      s   t
   SDODWithinc           B   s   e  Z d  Z RS(   s3   SDO_WITHIN_DISTANCE(%(lhs)s, %(rhs)s, %%s) = 'TRUE'(   R
   R   R   (    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyR   #   s   t   SDODisjointc           B   s   e  Z d  e Z RS(   s@   SDO_GEOM.RELATE(%%(lhs)s, 'DISJOINT', %%(rhs)s, %s) = 'DISJOINT'(   R
   R   R   R   (    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyR   '   s   t	   SDORelatec           B   s    e  Z d  Z d „  Z d „  Z RS(   s6   SDO_RELATE(%(lhs)s, %(rhs)s, 'mask=%(mask)s') = 'TRUE'c         C   s_   d } t  j d | | f t  j ƒ } t | t j ƒ sH | j | ƒ r[ t d | ƒ ‚ n  d  S(   Nsb   TOUCH|OVERLAPBDYDISJOINT|OVERLAPBDYINTERSECT|EQUAL|INSIDE|COVEREDBY|CONTAINS|COVERS|ANYINTERACT|ONs   ^(%s)(\+(%s))*$s   Invalid SDO_RELATE mask: "%s"(   t   ret   compilet   It
   isinstanceR   t   string_typest   matcht
   ValueError(   t   selft   argt   maskst
   mask_regex(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   check_relate_argument.   s    #c         C   s/   | j  ƒ  | d <t t |  ƒ j | | | | ƒ S(   Nt   mask(   t   popt   superR   t   as_sql(   R   t
   connectiont   lookupt   template_paramst
   sql_params(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyR!   4   s    (   R
   R   R   R   R!   (    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyR   +   s   	t
   SDOIsValidc           B   s   e  Z d  e Z RS(   s    %%(func)s(%%(lhs)s, %s) = 'TRUE'(   R
   R   R   R   (    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyR&   9   s   t   OracleOperationsc           B   s§  e  Z d  Z e Z e j e j e j f Z	 e
 Z d Z d Z d Z d Z d Z d Z d Z d Z d	 Z e Z d
 Z d Z d Z d Z d Z d Z d Z i d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d	 d 6d d 6d
 d 6d d  6d d! 6d d" 6d d# 6Z d$ Z i e d% d& ƒ d' 6e d% d( ƒ d) 6e d% d* ƒ d+ 6e  ƒ  d, 6e d% d- ƒ d. 6e! d% d ƒ d/ 6e d% d0 ƒ d1 6e d% d0 ƒ d2 6e d% d3 ƒ d4 6e d% d0 ƒ d5 6e" ƒ  d6 6e d% d7 ƒ d8 6e d% d9 ƒ d: 6e# d; d< ƒ d= 6e# d; d> ƒ d? 6e# d; d@ ƒ dA 6e# d; dB ƒ dC 6e$ ƒ  dD 6Z% i dQ d6 6Z' e( dE „  ƒ Z) dF „  Z* dG „  Z+ dH „  Z, dI „  Z- dJ „  Z. dK „  Z/ dL „  Z0 dM „  Z1 dN „  Z2 dO „  Z3 dP „  Z4 RS(R   t   oracles   SDO_GEOM.SDO_AREAs   SDO_UTIL.TO_GMLGEOMETRYs   SDO_GEOM.SDO_CENTROIDs   SDO_GEOM.SDO_DIFFERENCEs   SDO_GEOM.SDO_DISTANCEt   SDO_AGGR_MBRs   SDO_GEOM.SDO_INTERSECTIONs   SDO_GEOM.SDO_LENGTHs   SDO_UTIL.GETNUMVERTICESs   SDO_GEOM.SDO_POINTONSURFACEs   SDO_UTIL.REVERSE_LINESTRINGs   SDO_GEOM.SDO_XORs   SDO_CS.TRANSFORMs   SDO_GEOM.SDO_UNIONt   SDO_AGGR_UNIONt   SDO_GEOMETRYt   Areas   SDO_GEOM.SDO_MBCt   BoundingCirclet   Centroidt
   DifferenceR   t   Intersections'   SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXTt   IsValidt   Lengths   SDO_UTIL.GETNUMELEMt   NumGeometriest	   NumPointst	   Perimetert   PointOnSurfacet   Reverset   SymDifferencet	   Transformt   Unions   SDO_UTIL.TO_WKTGEOMETRY(%s)t   funct   SDO_CONTAINSt   containst   SDO_COVEREDBYt	   coveredbyt
   SDO_COVERSt   coverst   disjointt   SDO_OVERLAPBDYINTERSECTt
   intersectst   isvalidt	   SDO_EQUALt   equalst   exactt   SDO_OVERLAPSt   overlapst   same_ast   relatet	   SDO_TOUCHt   touchest
   SDO_INSIDEt   withint   opt   >t   distance_gts   >=t   distance_gtet   <t   distance_lts   <=t   distance_ltet   dwithinc         C   sM   d d d d d d d d d	 d
 d h } |  j  j d k  rI | j d ƒ n  | S(   Nt	   AsGeoJSONt   AsKMLt   AsSVGt   Envelopet   ForceRHRt   GeoHasht	   MakeValidt   MemSizet   Scalet
   SnapToGridt	   Translates   12.1.0.2R-   (   R"   t   oracle_full_versiont   add(   R   t   unsupported(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   unsupported_functions‰   s
    c         C   s   t  t |  ƒ j | ƒ j ƒ  S(   N(   R    R'   t   geo_quote_namet   upper(   R   t   name(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyRh   “   s    c      
   C   su   t  t |  ƒ j | ƒ } | j j ƒ  } d } | | k rL | j |  j ƒ n  t | j d ƒ rq | j |  j ƒ n  | S(   Nt
   PointFieldt   GeometryFieldt   LineStringFieldt   PolygonFieldt   MultiPointFieldt   MultiLineStringFieldt   MultiPolygonFieldt   GeometryCollectionFieldt	   GeomFieldt   GMLFieldt	   geom_type(
   Rk   Rl   Rm   Rn   Ro   Rp   Rq   Rr   Rs   Rt   (	   R    R'   t   get_db_converterst   output_fieldt   get_internal_typet   appendt   convert_textfield_valuet   hasattrt   convert_geometry(   R   t
   expressiont
   converterst   internal_typet   geometry_fields(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyRv   –   s       c         C   s5   | r1 t  | ƒ } d | k r1 | d | _ q1 n  | S(   Nt   transformed_srid(   R   t   srid(   R   t   valueR}   R"   t   context(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyR|   ¥   s
    c         C   sÁ   | r¹ t  | j ƒ  | ƒ } t | j ƒ } | d k r_ | j } | d d  | d d  } } n2 | d k r | j d  } | } n t d | ƒ ‚ | \ } }	 | \ }
 } | |	 |
 | f Sd  Sd  S(   Nt   Polygoni    i   t   Points0   Unexpected geometry type returned for extent: %s(   R   t   readt   strRu   t   shellt   coordst	   Exceptiont   None(   R   t   clobR‚   t   ext_geomt   gtypeR‰   t   llt   urt   xmint   ymint   xmaxt   ymax(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   convert_extent¬   s    	 	c         C   s   d S(   s»   
        Returns the geometry database type for Oracle.  Unlike other spatial
        backends, no stored procedure is necessary and it's the same for all
        geometry types.
        s   MDSYS.SDO_GEOMETRY(    (   R   t   f(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   geo_db_typeÂ   s    c         K   sŽ   | s
 g  S| d } t  | t ƒ rh | j |  j ƒ rA | j } qn t | t j | j |  j ƒ ƒ ƒ } n | } | d k r‡ d | } n  | g S(   s  
        Returns the distance parameters given the value and the lookup type.
        On Oracle, geometry columns with a geodetic coordinate system behave
        implicitly like a geography column, and thus meters will be used as
        the distance parameter on them.
        i    RX   s   distance=%s(   R   R   t   geodeticR"   t   mt   getattrt   unit_attnamet
   units_name(   R   R—   Rƒ   t   lookup_typet   kwargst
   dist_param(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   get_distanceÊ   s    
'c         C   s±   | d k r d Sd „  } t | d ƒ rv | | | j ƒ rS d |  j | j f } n d } | j | ƒ \ } } | | S| | | j ƒ r¢ d |  j | j | j f Sd | j Sd S(	   sÑ   
        Provides a proper substitution value for Geometries that are not in the
        SRID of the field.  Specifically, this routine will substitute in the
        SDO_CS.TRANSFORM() function call.
        t   NULLc         S   s   |  j  | k S(   N(   R‚   (   t   valR‚   (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   transform_valueì   s    R!   s   %s(%%s, %s)s   %ss   %s(SDO_GEOMETRY(%%s, %s), %s)s   SDO_GEOMETRY(%%s, %s)N(   RŒ   R{   R‚   t	   transformR   (   R   R—   Rƒ   t   compilerR¤   t   placeholdert   sqlt   _(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   get_geom_placeholderã   s    	c         C   s1   | j  ƒ  d k r d n	 | j  ƒ  } t |  | ƒ S(   s9   
        Returns the spatial aggregate SQL name.
        t   uniont   unionagg(   t   lowerR›   (   R   t   agg_name(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   spatial_aggregate_nameþ   s    $c         C   s   d d l  m } | S(   Niÿÿÿÿ(   t   OracleGeometryColumns(   t,   django.contrib.gis.db.backends.oracle.modelsR°   (   R   R°   (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   geometry_columns  s    c         C   s   d d l  m } | S(   Niÿÿÿÿ(   t   OracleSpatialRefSys(   R±   R³   (   R   R³   (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   spatial_ref_sys
  s    c         C   s)   | d k r g  St  t |  ƒ j | | ƒ S(   sr   Drop out insert parameters for NULL placeholder. Needed for Oracle Spatial
        backend due to #10888.
        R¢   (   R    R'   t   modify_insert_params(   R   R§   t   params(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyRµ     s    N(5   R
   R   Rj   t   TrueR(   R   t   Collectt   Extent3Dt   MakeLinet   disallowed_aggregatesR   t   Adaptert   areat   gmlt   centroidt
   differencet   distancet   extentt   intersectiont   lengtht
   num_pointst	   perimetert   point_on_surfacet   reverset   sym_differenceR¥   R«   R¬   t	   from_textt   function_namest   selectR	   R   R&   R   R   R   t   gis_operatorsRŒ   t   truncate_paramsR   Rg   Rh   Rv   R|   R–   R˜   R¡   Rª   R¯   R²   R´   Rµ   (    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyR'   =   sŽ   



										(   t   __doc__R   t.   django.contrib.gis.db.backends.base.operationsR    t-   django.contrib.gis.db.backends.oracle.adapterR   t$   django.contrib.gis.db.backends.utilsR   t   django.contrib.gis.db.modelsR   t#   django.contrib.gis.geometry.backendR   t   django.contrib.gis.measureR   t$   django.db.backends.oracle.operationsR   t   django.utilsR   t   django.utils.functionalR   R   R	   R   R   R   R   R&   R'   (    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/oracle/operations.pyt   <module>	   s$   