
i4Vdc           @   s1  d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d  d l m Z 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 m Z d d l m Z d e f d     YZ d e f d     YZ d e e f d     YZ d S(   iN(   t   settings(   t   BaseSpatialOperations(   t   PostGISAdapter(   t   from_pgrastert   to_pgraster(   t   SpatialOperator(   t   Geometry(   t   Distance(   t   ImproperlyConfigured(   t   DatabaseOperations(   t   ProgrammingError(   t   cached_propertyi   (   t   PostGISGeometryColumnst   PostGISSpatialRefSys(   t   get_pgraster_sridt   PostGISOperatorc           B   s   e  Z e d   Z d   Z RS(   c         K   s#   | |  _  t t |   j |   d  S(   N(   t	   geographyt   superR   t   __init__(   t   selfR   t   kwargs(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR      s    	c         G   sW   | j  j j r; |  j r; t d |  j p. |  j f   n  t t |   j | | |  S(   Ns>   PostGIS geography does not support the "%s" function/operator.(	   t   lhst   output_fieldR   t
   ValueErrort   funct   opR   R   t   as_sql(   R   t
   connectiont   lookupt   args(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR      s    (   t   __name__t
   __module__t   FalseR   R   (    (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR      s   t   PostGISDistanceOperatorc           B   s   e  Z d  Z d   Z RS(   s%   %(func)s(%(lhs)s, %(rhs)s) %(op)s %%sc         C   s   | j  j j r | j  j j |  r |  j } t | j  d k r} | j d d k r} | j i |  j d 6d d 6 d } n | j i |  j d 6d d 6 | | | f St	 t
 |   j | | | |  S(	   Ni   it   spheroidR   t   ST_Distance_SpheroidR   s*   %(func)s(%(lhs)s, %(rhs)s, %%s) %(op)s %%st   ST_Distance_Sphere(   R   R   R   t   geodetict   sql_templatet   lent   rhst   updateR   R   R!   R   (   R   R   R   t   template_paramst
   sql_paramsR&   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR   '   s    %	(	(   R   R   R&   R   (    (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR!   $   s   t   PostGISOperationsc           B   sV  e  Z d  Z e Z e Z d Z e j d  Z	 e
 Z e Z i e d d  d 6e d d d e  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  d  6e d d!  d" 6e d d# d e  d$ 6e d d% d e  d& 6e d d'  d( 6e d d)  d* 6e d d+  d, 6e d d- d e  d. 6e d d/  d0 6e d d1  d2 6e d d3  d4 6e d d5  d6 6e d d7 d e  d8 6e d d9 d d: d e  d; 6e d d9 d d< d e  d= 6e d d9 d d> d e  d? 6e d d9 d d@ d e  dA 6Z e   Z i dB dC 6dD dE 6dF dG 6Z dH   Z e dI    Z dJ   Z dK   Z dL   Z dM   Z dN   Z dO   Z dP   Z dQ   Z dR   Z dS   Z dT   Z  dU   Z! dV   Z" dW   Z# dX   Z$ dY   Z% dZ   Z& d[   Z' d\   Z( RS(]   t   postgist   ST_s/   ^(?P<major>\d)\.(?P<minor1>\d)\.(?P<minor2>\d+)R   t   ~t
   bbcontainss   &&R   t
   bboverlapst   @t	   containedR   t   ST_Containst   containss   &<t   overlaps_lefts   &>t   overlaps_rights   &<|t   overlaps_belows   |&>t   overlaps_aboves   <<t   lefts   >>t   rights   <<|t   strictly_belows   |>>t   strictly_aboves   ~=t   same_ast   exactt   ST_ContainsProperlyt   contains_properlyt   ST_CoveredByt	   coveredbyt	   ST_Coverst   coverst
   ST_Crossest   crossest   ST_Disjointt   disjointt	   ST_Equalst   equalst   ST_Intersectst
   intersectst   ST_Overlapst   overlapst	   ST_Relatet   relatet
   ST_Touchest   touchest	   ST_Withint   withint
   ST_DWithint   dwithint   ST_Distancet   >t   distance_gts   >=t   distance_gtet   <t   distance_lts   <=t   distance_ltet   ST_MinimumBoundingCirclet   BoundingCirclet   ST_Mem_Sizet   MemSizet
   ST_NPointst	   NumPointsc         C   s  t  t |   j |  |  j } | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _	 | d |  _
 | d |  _ | d	 |  _ | d
 |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _  | d |  _! | d |  _" | d  |  _# | d! |  _$ | d" |  _% | d# |  _& | d$ |  _' | d$ |  _( d  S(%   Nt   Areat   MinimumBoundingCirclet   Centroidt   Collectt
   DifferenceR   t   distance_spheret   distance_spheroidt   Envelopet   Extentt   3DExtentt   ForceRHRt   GeoHasht	   AsGeoJsont   AsGMLt   Intersectiont   AsKMLt   Lengtht   3DLengtht   length_spheroidt   MakeLinet   mem_sizet   NumGeometriest   npointst	   Perimetert   3DPerimetert   PointOnSurfacet
   Polygonizet   Reverset   Scalet
   SnapToGridt   AsSVGt   SymDifferencet	   Transformt	   Translatet   Union()   R   R,   R   t   geom_func_prefixt   areat   bounding_circlet   centroidt   collectt
   differencet   distanceRj   Rk   t   envelopet   extentt   extent3dt	   force_rhrt   geohasht   geojsont   gmlt   intersectiont   kmlt   lengtht   length3dRw   t   makelineRy   t   num_geomt
   num_pointst	   perimetert   perimeter3dt   point_on_surfacet
   polygonizet   reverset   scalet   snap_to_gridt   svgt   sym_differencet	   transformt	   translatet   uniont   unionagg(   R   R   t   prefix(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR   e   sN    	c         C   st   t  t d  r t j } nU |  j d  y |  j   } Wn+ t k
 re t d |  j j d   n X| d } | S(   s-   Determine the version of the PostGIS library.t   POSTGIS_VERSIONt   versions   Cannot determine PostGIS version for database "%s" using command "SELECT postgis_lib_version()". GeoDjango requires at least PostGIS version 2.0. Was the database created from a spatial database template?t   NAMEi   (	   t   hasattrR    R   t   _get_postgis_funct   postgis_version_tupleR
   R   R   t   settings_dict(   R   R   t   vtup(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   spatial_version   s    	
c   	      C   sr   | d k r d S| d d !j d  \ } } t t | j    \ } } t t | j    \ } } | | | | f S(   s   
        Returns a 4-tuple extent for the `Extent` aggregate by converting
        the bounding box text returned by PostGIS (`box` argument), for
        example: "BOX(-90.0 30.0, -85.0 40.0)".
        i   it   ,N(   t   Nonet   splitt   mapt   float(	   R   t   boxt   sridt   llt   urt   xmint   ymint   xmaxt   ymax(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   convert_extent   s    c         C   s~   | d k r d S| d d !j d  \ } } t t | j    \ } } } t t | j    \ } }	 }
 | | | | |	 |
 f S(   s   
        Returns a 6-tuple extent for the `Extent3D` aggregate by converting
        the 3d bounding-box text returned by PostGIS (`box3d` argument), for
        example: "BOX3D(-90.0 30.0 1, -85.0 40.0 2)".
        i   iR   N(   R   R   R   R   (   R   t   box3dR   R   R   R   R   t   zminR   R   t   zmax(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   convert_extent3d   s    c         C   s!   | r t  | d | j Sd Sd S(   sI   
        Converts the geometry returned from PostGIS aggregates.
        R   N(   R   R   R   (   R   t   hext	   geo_field(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   convert_geom   s    c         C   s   | j  d k r d S| j rN | j d k r: t d   n  d | j  | j f S| j d k rm | j  d } n	 | j  } d | | j f Sd	 S(
   sM   
        Return the database field type for the given spatial field.
        t   RASTERt   rasteri  s=   PostGIS only supports geography columns with an SRID of 4326.s   geography(%s,%d)i   t   Zs   geometry(%s,%d)N(   t	   geom_typeR   R   t   NotImplementedErrort   dim(   R   t   fR   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   geo_db_type   s    		c   	      C   s  t  |  d k r& | d d } } n | \ } } | j |  j  } | j } t | t  r | rn | j } q | r | d k r t d   n  | j } q t	 | t j
 | j |  j    } n | } | r | r | d k r | d k r | j | g S| g Sd S(   s  
        Retrieve the distance parameters for the given geometry field,
        distance lookup value, and the distance lookup type.

        This is the most complex implementation of the spatial backends due to
        what is supported on geodetic geometry columns vs. what's available on
        projected geometry columns.  In addition, it has to take into account
        the geography column type.
        i   i    RW   sN   Only numeric values of degree units are allowed on geographic DWithin queries.R"   N(   R'   R   R%   R   R   t
   isinstanceR   t   mR   t   getattrt   unit_attnamet
   units_namet	   _spheroid(	   R   R   t   dist_valt   lookup_typet   valuet   optionR%   R   t
   dist_param(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   get_distance   s$    	'c         C   s   | d k r d } n' | j d k r3 t |  } n	 | j } | d k sW | | j k r` d } n> | j d k r d |  j | j f } n d |  j | j f } t | d  r | j |  \ } } | | } n  | 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
        ST_Transform() function call.
        R   s   %ss   %s((%%s)::raster, %s)s   %s(%%s, %s)R   N(   R   R   R   R   R   R   t   compile(   R   R   R   t   compilert
   value_sridt   placeholdert   sqlt   _(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   get_geom_placeholder  s    			c         C   s;   |  j  j   & } | j d |  | j   d SWd QXd S(   sZ   
        Helper routine for calling PostGIS functions and returning their result.
        s   SELECT %s()i    N(   R   t   temporary_connectiont   executet   fetchone(   R   R   t   cursor(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR   /  s    c         C   s   |  j  d  S(   s:   Returns the version of the GEOS library used with PostGIS.t   postgis_geos_version(   R   (   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR   8  s    c         C   s   |  j  d  S(   sG   Returns the version number of the PostGIS library used with PostgreSQL.t   postgis_lib_version(   R   (   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR   <  s    c         C   s   |  j  d  S(   s<   Returns the version of the PROJ.4 library used with PostGIS.t   postgis_proj_version(   R   (   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR   @  s    c         C   s   |  j  d  S(   s8   Returns PostGIS version number and compile-time options.t   postgis_version(   R   (   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR   D  s    c         C   s   |  j  d  S(   s8   Returns PostGIS version number and compile-time options.t   postgis_full_version(   R   (   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyR   H  s    c         C   s   |  j    } |  j j |  } | rf t | j d   } t | j d   } t | j d   } n t d |   | | | | f S(   sj   
        Returns the PostGIS version as a tuple (version string, major,
        minor, subminor).
        t   majort   minor1t   minor2s*   Could not parse PostGIS version string: %s(   R   t   version_regext   matcht   intt   groupt	   Exception(   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/postgis/operations.pyR   L  s    c         C   sw   t  j d  } |  j   } | j |  } | rg t t t | j d  | j d  | j d  g   St d   d S(   s   
        Return the version of PROJ.4 used by PostGIS as a tuple of the
        major, minor, and subminor release numbers.
        s   (\d+)\.(\d+)\.(\d+)i   i   i   s0   Could not determine PROJ.4 version from PostGIS.N(	   t   reR   R   t   searcht   tupleR   R   R   R   (   R   t
   proj_regext   proj_ver_strR   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   proj_version_tuple^  s    7c         C   s"   | d k r |  j  S|  j | Sd  S(   Nt   Extent3D(   R   R   (   R   t   agg_name(    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   spatial_aggregate_namek  s    c         C   s   t  S(   N(   R   (   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   geometry_columnsr  s    c         C   s   t  S(   N(   R   (   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   spatial_ref_sysu  s    c         C   s
   t  |  S(   N(   R   (   R   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   parse_rasterz  s    c         C   s
   t  |  S(   N(   R   (   R   R   (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   deconstruct_raster}  s    ()   R   R   t   namet   TrueR-   R   R   R   R   R   R   t   Adaptert   AdaptorR   R!   t   gis_operatorst   sett   unsupported_functionst   function_namesR   R   R   R   R   R   R   R   R   R   R   R   R   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/postgis/operations.pyR,   3   s   	
	+						*	 													(    R   t   django.confR    t.   django.contrib.gis.db.backends.base.operationsR   t.   django.contrib.gis.db.backends.postgis.adapterR   t/   django.contrib.gis.db.backends.postgis.pgrasterR   R   t$   django.contrib.gis.db.backends.utilsR   t#   django.contrib.gis.geometry.backendR   t   django.contrib.gis.measureR   t   django.core.exceptionsR   t(   django.db.backends.postgresql.operationsR	   t   django.db.utilsR
   t   django.utils.functionalR   t   modelsR   R   t   pgrasterR   R   R!   R,   (    (    (    s   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/operations.pyt   <module>   s    