ó
J~‰Pc           @   sx   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d e f d „  ƒ  YZ	 e d e f d	 „  ƒ  Yƒ Z
 d S(
   sk   
Base/mixin classes for the spatial backend database operations and the
`SpatialRefSys` model the backend.
iÿÿÿÿN(   t   gdal(   t   six(   t   python_2_unicode_compatiblet   BaseSpatialOperationsc           B   s¦  e  Z d  Z i  Z i  Z i  Z i  Z i  Z i  Z i  Z	 e
 Z e
 Z e
 Z e
 Z d Z d Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z e
 Z  e
 Z! e
 Z" e
 Z# e
 Z$ e
 Z% e
 Z& e
 Z' e
 Z( e
 Z) e
 Z* e
 Z+ e
 Z, e
 Z- e
 Z. e
 Z/ e
 Z0 e
 Z1 e
 Z2 e
 Z3 e
 Z4 e
 Z5 e
 Z6 d „  Z7 d „  Z8 d „  Z9 d „  Z: d „  Z; d „  Z< d „  Z= d „  Z> d	 „  Z? d
 „  Z@ d „  ZA d „  ZB RS(   sš   
    This module holds the base `BaseSpatialBackend` object, which is
    instantiated by each spatial database backend with the features
    it has.
    c         C   s   t  d ƒ ‚ d  S(   Ns:   Aggregate extent not implemented for this spatial backend.(   t   NotImplementedError(   t   selft   box(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   convert_extentS   s    c         C   s   t  d ƒ ‚ d  S(   Ns=   Aggregate 3D extent not implemented for this spatial backend.(   R   (   R   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   convert_extent3dV   s    c         C   s   t  d ƒ ‚ d  S(   Ns:   Aggregate method not implemented for this spatial backend.(   R   (   R   t   geom_valt
   geom_field(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   convert_geomY   s    c         C   s   d | S(   Ns   '%s'(    (   R   t   name(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   geo_quote_name]   s    c         C   s
   t  ‚ d S(   si   
        Returns the database column type for the geometry field on
        the spatial backend.
        N(   R   (   R   t   f(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   geo_db_typea   s    c         C   s   t  d ƒ ‚ d S(   sv   
        Returns the distance parameters for the given geometry field,
        lookup value, and lookup type.
        s:   Distance operations not available on this spatial backend.N(   R   (   R   R   t   valuet   lookup_type(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   get_distanceh   s    c         C   s
   t  ‚ d S(   s  
        Returns the placeholder for the given geometry field with the given
        value.  Depending on the spatial backend, the placeholder may contain a
        stored procedure call to the transformation function of the spatial
        backend.
        N(   R   (   R   R   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   get_geom_placeholdero   s    c         C   sS   x@ | j  D]5 \ } } | | j k r
 d t t |  j | ƒ ƒ Sq
 Wt d ƒ ‚ d S(   sq   
        Helper method to return the quoted column string from the evaluator
        for its expression.
        s   %s.%ss-   Could not find the column for the expression.N(   t   colst
   expressiont   tuplet   mapt
   quote_namet	   Exception(   R   t	   evaluatort   exprt   col_tup(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   get_expression_columnx   s    c         C   s   t  d ƒ ‚ d  S(   Ns;   Aggregate support not implemented for this spatial backend.(   R   (   R   t   agg(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   spatial_aggregate_sqlƒ   s    c         C   s
   t  ‚ d  S(   N(   R   (   R   t   lvalueR   R   t   field(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   spatial_lookup_sql†   s    c         C   s
   t  ‚ d  S(   N(   R   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   geometry_columnsŠ   s    c         C   s
   t  ‚ d  S(   N(   R   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   spatial_ref_sys   s    N(C   t   __name__t
   __module__t   __doc__t   distance_functionst   geometry_functionst   geometry_operatorst   geography_operatorst   geography_functionst	   gis_termst   truncate_paramst   Falset   postgist
   spatialitet   mysqlt   oraclet   Nonet   spatial_versiont   selectt	   geographyt   geometryt   areat   centroidt
   differencet   distancet   distance_spheret   distance_spheroidt   envelopet	   force_rhrt   mem_sizet   bounding_circlet   num_geomt
   num_pointst	   perimetert   perimeter3dt   point_on_surfacet
   polygonizet   reverset   scalet   snap_to_gridt   sym_differencet	   transformt	   translatet   uniont   collectt   extentt   extent3dt	   make_linet   unionaggt   geohasht   geojsont   gmlt   kmlt   svgt	   from_textt   from_wkbR   R   R   R   R   R   R   R   R   R"   R#   R$   (    (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyR   
   s~   												t   SpatialRefSysMixinc           B   s  e  Z d  Z e j d ƒ Z e j d ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e e d „ ƒ Z d „  Z RS(   s   
    The SpatialRefSysMixin is a class used by the database-dependent
    SpatialRefSys objects to reduce redundnant code.
    sO   .+SPHEROID\[\"(?P<name>.+)\",(?P<major>\d+(\.\d+)?),(?P<flattening>\d{3}\.\d+),s×   .+UNIT ?\["(?P<unit_name>[\w \'\(\)]+)", ?(?P<unit>[\d\.]+)(,AUTHORITY\["(?P<unit_auth_name>[\w \'\(\)]+)","(?P<unit_auth_val>\d+)"\])?\]([\w ]+)?(,AUTHORITY\["(?P<auth_name>[\w \'\(\)]+)","(?P<auth_val>\d+)"\])?\]$c         C   s½   t  j r­ t |  d ƒ r% |  j j ƒ  Sy  t  j |  j ƒ |  _ |  j SWn t k
 rZ } n Xy  t  j |  j	 ƒ |  _ |  j SWn t k
 r } n Xt d |  j | f ƒ ‚ n t d ƒ ‚ d S(   sO   
        Returns a GDAL SpatialReference object, if GDAL is installed.
        t   _srss9   Could not get OSR SpatialReference from WKT: %s
Error:
%ss   GDAL is not installed.N(
   R    t   HAS_GDALt   hasattrR]   t   clonet   SpatialReferencet   wktt   srsR   t	   proj4text(   R   t   msg(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyRc   ¢   s    	c         C   s^   t  j r |  j j S|  j j |  j ƒ } | rV t | j d ƒ ƒ t | j d ƒ ƒ f Sd Sd S(   s€   
        Returns a tuple of the ellipsoid parameters:
        (semimajor axis, semiminor axis, and inverse flattening).
        t   majort
   flatteningN(
   R    R^   Rc   t	   ellipsoidt   spheroid_regext   matchRb   t   floatt   groupR4   (   R   t   m(    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyRh   À   s    	
 (c         C   s
   |  j  j S(   s   Returns the projection name.(   Rc   R   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyR   Í   s    c         C   s   |  j  d S(   s5   Returns the spheroid name for this spatial reference.t   spheroid(   Rc   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyRn   Ò   s    c         C   s   |  j  d S(   s-   Returns the datum for this spatial reference.t   datum(   Rc   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyRo   ×   s    c         C   s'   t  j r |  j j S|  j j d ƒ Sd S(   s$   Is this Spatial Reference projected?t   PROJCSN(   R    R^   Rc   t	   projectedRb   t
   startswith(   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyRq   Ü   s    	
c         C   s'   t  j r |  j j S|  j j d ƒ Sd S(   s    Is this Spatial Reference local?t   LOCAL_CSN(   R    R^   Rc   t   localRb   Rr   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyRt   ä   s    	
c         C   s'   t  j r |  j j S|  j j d ƒ Sd S(   s%   Is this Spatial Reference geographic?t   GEOGCSN(   R    R^   Rc   t
   geographicRb   Rr   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyRv   ì   s    	
c         C   sF   t  j r |  j j S|  j r  d S|  j j |  j ƒ } | j	 d ƒ Sd S(   s   Returns the linear units name.t	   unit_nameN(
   R    R^   Rc   t   linear_nameRv   R4   t   units_regexRj   Rb   Rl   (   R   Rm   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyRx   ô   s    	
	c         C   sF   t  j r |  j j S|  j r  d S|  j j |  j ƒ } | j	 d ƒ Sd S(   s   Returns the linear units.t   unitN(
   R    R^   Rc   t   linear_unitsRv   R4   Ry   Rj   Rb   Rl   (   R   Rm   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyR{   ÿ   s    	
	c         C   sF   t  j r |  j j S|  j r  d S|  j j |  j ƒ } | j	 d ƒ Sd S(   s&   Returns the name of the angular units.Rw   N(
   R    R^   Rc   t   angular_nameRq   R4   Ry   Rj   Rb   Rl   (   R   Rm   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyR|   
  s    	
	c         C   sF   t  j r |  j j S|  j r  d S|  j j |  j ƒ } | j	 d ƒ Sd S(   s   Returns the angular units.Rz   N(
   R    R^   Rc   t   angular_unitsRq   R4   Ry   Rj   Rb   Rl   (   R   Rm   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyR}     s    	
	c         C   sC   |  j  s |  j r" |  j |  j f S|  j r; |  j |  j f Sd Sd S(   s*   Returns a tuple of the units and the name.N(   NN(   Rq   Rt   R{   Rx   Rv   R}   R|   R4   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   units   s
    	c         C   sK   t  j r t  j | ƒ j S|  j j | ƒ } | j d ƒ | j d ƒ f Sd S(   s¯   
        Class method used by GeometryField on initialization to
        retrive the units on the given WKT, without having to use
        any of the database fields.
        Rz   Rw   N(   R    R^   Ra   R~   Ry   Rj   Rl   (   t   clsRb   Rm   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt	   get_units*  s    	c   	      C   sá   t  j r. t  j | ƒ } | j } | d } nX |  j j | ƒ } | r‚ t | j d ƒ ƒ t | j d ƒ ƒ f } | j d ƒ } n d	 S| s– | | f St	 | ƒ d k rÀ | d | d } } n | \ } } d | | | f Sd	 S(
   sŒ   
        Class method used by GeometryField on initialization to
        retrieve the `SPHEROID[..]` parameters from the given WKT.
        Rn   Rf   Rg   R   i   i    i   s   SPHEROID["%s",%s,%s]N(
   R    R^   Ra   Rh   Ri   Rj   Rk   Rl   R4   t   len(	   R   Rb   t   stringRc   t   sphere_paramst   sphere_nameRm   t   radiusRg   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   get_spheroid7  s    		*
c         C   s/   y t  j |  j ƒ SWn t  j |  j ƒ SXd S(   sp   
        Returns the string representation.  If GDAL is installed,
        it will be 'pretty' OGC WKT.
        N(   R   t	   text_typeRc   Rb   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   __str__S  s    (   R%   R&   R'   t   ret   compileRi   Ry   t   propertyRc   Rh   R   Rn   Ro   Rq   Rt   Rv   Rx   R{   R|   R}   R~   t   classmethodR€   t   TrueR†   Rˆ   (    (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyR\      s(   
(   R'   R‰   t   django.contrib.gisR    t   django.utilsR   t   django.utils.encodingR   t   objectR   R\   (    (    (    s<   ../Django//lib/python/django/contrib/gis/db/backends/base.pyt   <module>   s   †