
i4Vdc           @   s   d  Z  d d l 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 d l m Z d d l m Z d e e f d     YZ d S(   s   
SQL functions reference lists:
http://www.gaia-gis.it/spatialite-2.4.0/spatialite-sql-2.4.html
http://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-sql-3.0.0.html
http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.2.1.html
iN(   t   BaseSpatialOperations(   t   SpatiaLiteAdapter(   t   SpatialOperator(   t
   aggregates(   t   Geometry(   t   Distance(   t   ImproperlyConfigured(   t   DatabaseOperations(   t   DatabaseError(   t   six(   t   cached_propertyt   SpatiaLiteOperationsc           B   s  e  Z d  Z e Z e j d  Z e Z	 e	 Z
 d Z d Z d Z d Z d Z d Z d Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z  d Z! i e" d d  d 6e" d d  d 6e" d d  d 6e" d d  d  6e" d d!  d" 6e" d d#  d$ 6e" d d%  d& 6e" d d'  d( 6e" d d)  d* 6e" d d  d+ 6e" d d,  d- 6e" d d.  d/ 6e" d d  d0 6e" d d  d1 6e" d d d2 d3  d4 6e" d d d2 d5  d6 6e" d d d2 d7  d8 6e" d d d2 d9  d: 6Z# e$ d;    Z% e$ d<    Z& e$ d=    Z' e( d>    Z) e$ d?    Z* e$ d@    Z+ e$ dA    Z, e$ dB    Z- dC   Z. dD   Z/ dE   Z0 dF   Z1 dG   Z2 dH   Z3 dI   Z4 dJ   Z5 dK   Z6 dL   Z7 dM   Z8 dN   Z9 dO   Z: dP   Z; dQ   Z< RS(R   t
   spatialites/   ^(?P<major>\d)\.(?P<minor1>\d)\.(?P<minor2>\d+)t   Areat   Centroidt   Collectt	   MbrWithint
   DifferenceR   t   Envelopet   Extentt   Intersectiont   GLengtht   NumGeometriest	   NumPointst   PointOnSurfacet   ScaleCoordst   AsSVGt   SymDifferencet	   Transformt   ShiftCoordst   GUniont   GeomFromTextt   GeomFromWKBs
   AsText(%s)t   funct   Equalst   equalst   Disjointt   disjointt   Touchest   touchest   Crossest   crossest   Withint   withint   Overlapst   overlapst   Containst   containst
   Intersectst
   intersectst   Relatet   relatet	   containedt   MbrContainst
   bbcontainst   MbrOverlapst
   bboverlapst   same_ast   exactt   opt   >t   distance_gts   >=t   distance_gtet   <t   distance_lts   <=t   distance_ltec         C   s<   i d d 6d d 6d d 6|  j  d k r- d
 n d d 6d d 6S(   Nt	   ST_Lengtht   Lengtht
   ST_Reverset   ReverseR   t   Scalei   i   i    t   ST_TranslateR   t	   Translatet   ST_Uniont   Union(   i   i   i    (   t   spatial_version(   t   self(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   function_namesS   s    c         C   s   d d d d h } |  j  s+ | j d  n  |  j sD | j d  n  |  j d k  rc | j d	  n  |  j d k  r | j d  n  |  j d k  r | j d d h  n  | S(   Nt   BoundingCirclet   ForceRHRt   GeoHasht   MemSizet   AsGMLt   AsKMLi   i    t	   AsGeoJSONi   t
   SnapToGridi   t	   PerimeterRE   (   i   i    i    (   i   i   i    (   i   i    i    (   t   gmlt   addt   kmlRK   t   update(   RL   t   unsupported(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   unsupported_functions]   s    		c         C   s   y |  j    d } WnP t k
 rf } d |  j j d | f } t j t t |  t j   d  n X| d k  r t d   n  | S(	   s0   Determine the version of the SpatiaLite library.i   s   Cannot determine the SpatiaLite version for the "%s" database (error was "%s").  Was the SpatiaLite initialization SQL loaded on this database?t   NAMEi   i   i    s;   GeoDjango only supports SpatiaLite versions 2.4.0 and above(   i   i   i    (	   t   spatialite_version_tuplet	   Exceptiont
   connectiont   settings_dictR	   t   reraiseR   t   syst   exc_info(   RL   t   versiont   msgt   new_msg(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyRK   l   s    'c         C   sA   |  j  d k r t Sy |  j d  Wn t k
 r8 t SXt Sd  S(   Ni   i   i   s!   AsGML(GeomFromText('POINT(1 1)'))(   i   i   i   (   RK   t   Truet   _get_spatialite_funcR   t   False(   RL   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   _version_greater_2_4_0_rc4|   s    c         C   s>   t  j t  j f } |  j d k  r: | t  j t  j f 7} n  | S(   Ni   i    (   i   i    i    (   R   t   Extent3Dt   MakeLineRK   R   R   (   RL   t
   disallowed(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   disallowed_aggregates   s    c         C   s   |  j  r d Sd  S(   NRR   (   Rk   t   None(   RL   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyRW      s    c         C   s   |  j  r d Sd  S(   NRS   (   Rk   Rp   (   RL   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyRY      s    c         C   s   |  j  d k r d Sd  S(   Ni   i    RT   (   i   i    i    (   RK   Rp   (   RL   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   geojson   s    c         C   sZ   | d k r d St | |  j } | d d  \ } } | d d  \ } } | | | | f S(   sV   
        Convert the polygon data received from Spatialite to min/max values.
        i    i   N(   Rp   R   t   shell(   RL   t   boxt   sridRr   t   xmint   ymint   xmaxt   ymax(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   convert_extent   s    c         C   s   | r t  | | j  Sd Sd S(   sM   
        Converts geometry WKT returned from a SpatiaLite aggregate.
        N(   R   Rt   Rp   (   RL   t   wktt	   geo_field(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   convert_geom   s    c         C   s   d S(   s   
        Returns None because geometry columns are added via the
        `AddGeometryColumn` stored procedure on SpatiaLite.
        N(   Rp   (   RL   t   f(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   geo_db_type   s    c         C   sx   | s
 g  S| d } t  | t  rk | j |  j  rD t d   qq t | t j | j |  j    } n | } | g S(   s  
        Returns the distance parameters for the given geometry field,
        lookup value, and lookup type.  SpatiaLite only supports regular
        cartesian-based queries (no spheroid/sphere calculations for point
        geometries like PostGIS).
        i    s   SpatiaLite does not support distance queries on geometry fields with a geodetic coordinate system. Distance objects; use a numeric value of your distance in degrees instead.(   t
   isinstanceR   t   geodeticR`   t
   ValueErrort   getattrt   unit_attnamet
   units_name(   RL   R}   t   valuet   lookup_typet
   dist_param(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   get_distance   s    
'c         C   s   d   } t  | d  rf | | | j  rC d |  j | j f } n d } | j |  \ } } | | S| | | j  r d |  j |  j | j | j f Sd |  j | j f 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
        Transform() and GeomFromText() function call(s).
        c         S   s   |  d  k p |  j | k S(   N(   Rp   Rt   (   R   Rt   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   transform_value   s    t   as_sqls   %s(%%s, %s)s   %ss   %s(%s(%%s,%s), %s)s
   %s(%%s,%s)N(   t   hasattrRt   t	   transformt   compilet	   from_text(   RL   R}   R   t   compilerR   t   placeholdert   sqlt   _(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   get_geom_placeholder   s    	 c         C   sF   |  j  j   } z! | j d |  | j   } Wd | j   X| d S(   s   
        Helper routine for calling SpatiaLite functions and returning
        their result.
        Any error occurring in this method should be handled by the caller.
        s	   SELECT %sNi    (   R`   t   _cursort   executet   fetchonet   close(   RL   R!   t   cursort   row(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyRi      s    c         C   s   |  j  d  S(   s;   Returns the version of GEOS used by SpatiaLite as a string.s   geos_version()(   Ri   (   RL   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   geos_version   s    c         C   s   |  j  d  S(   s=   Returns the version of the PROJ.4 library used by SpatiaLite.s   proj4_version()(   Ri   (   RL   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   proj4_version   s    c         C   s   |  j  d  S(   s3   Returns the SpatiaLite library version as a string.s   spatialite_version()(   Ri   (   RL   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   spatialite_version   s    c         C   s   |  j    } |  j j |  } | rf t | j d   } t | j d   } t | j d   } n t d |   | | | | f S(   sm   
        Returns the SpatiaLite version as a tuple (version string, major,
        minor, subminor).
        t   majort   minor1t   minor2s-   Could not parse SpatiaLite version string: %s(   R   t   version_regext   matcht   intt   groupR_   (   RL   Re   t   mR   R   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyR^      s    c         C   s1   | j    d k r d n	 | j    } t |  |  S(   ss   
        Returns the spatial aggregate SQL template and function for the
        given Aggregate instance.
        t   uniont   unionagg(   t   lowerR   (   RL   t   agg_name(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   spatial_aggregate_name  s    $c         C   s   d d l  m } | S(   Ni(   t   SpatialiteGeometryColumns(   t0   django.contrib.gis.db.backends.spatialite.modelsR   (   RL   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   geometry_columns  s    c         C   s   d d l  m } | S(   Ni(   t   SpatialiteSpatialRefSys(   R   R   (   RL   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   spatial_ref_sys  s    c         C   sA   t  t |   j |  } t | j d  r= | j |  j  n  | S(   Nt	   geom_type(   t   superR   t   get_db_convertersR   t   output_fieldt   appendt   convert_geometry(   RL   t
   expressiont
   converters(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyR   "  s    c         C   s5   | r1 t  |  } d | k r1 | d | _ q1 n  | S(   Nt   transformed_srid(   R   Rt   (   RL   R   R   R`   t   context(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyR   (  s
    (=   t   __name__t
   __module__t   nameRh   R   t   reR   R   R   t   Adaptert   Adaptort   areat   centroidt   collectR4   t
   differencet   distancet   envelopet   extentt   intersectiont   lengtht   num_geomt
   num_pointst   point_on_surfacet   scalet   svgt   sym_differenceR   t	   translateR   R   R   t   from_wkbt   selectR   t   gis_operatorsR
   RM   R\   RK   t   propertyRk   Ro   RW   RY   Rq   Ry   R|   R~   R   R   Ri   R   R   R   R^   R   R   R   R   R   (    (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyR      s   
																(   t   __doc__R   Rc   t.   django.contrib.gis.db.backends.base.operationsR    t1   django.contrib.gis.db.backends.spatialite.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.core.exceptionsR   t%   django.db.backends.sqlite3.operationsR   t   django.db.utilsR   t   django.utilsR	   t   django.utils.functionalR
   R   (    (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyt   <module>   s   