ó
®â0_c           @   s  d  d l  Z  d  d l m Z m Z m Z m Z d  d l m Z d  d l m	 Z	 m
 Z
 m Z 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 e f d „  ƒ  YZ  d S(   iÿÿÿÿN(   t   GeometryFieldt   LineStringFieldt
   PointFieldt   get_srid_info(   t	   GISLookup(   t	   AreaFieldt   DistanceFieldt	   GeomFieldt   GMLField(   t   Geometry(   t   Areat   Distance(   t   connections(   t
   LOOKUP_SEP(   t   RawSQL(   t   Field(   t   QuerySet(   t   six(   t   RemovedInDjango20Warningt   GeoQuerySetc           B   s‚  e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d e	 e	 d	 „ Z
 d
 d „ Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z e	 d d „ Z d „  Z d d „ Z d d „ Z d „  Z d( d( d( d  „ Z d( d( d! „ Z d( d e	 d" „ Z  d d# „ Z! d d$ „ Z" d% „  Z# d( d& „ Z$ d( d( d' „ Z% RS()   s   The Geographic QuerySet.gš™™™™™©?c         K   s  |  j  d d | j d ƒ ƒ\ } } i | d 6| d 6t d 6} t |  j } | j } | j r‰ d | d <| | d d <t d	 ƒ | d
 <nq | j s› | j	 rú | j
 r· t d	 ƒ | d
 <qú | j | ƒ së t t j | j | ƒ ƒ ƒ | d
 <qú t d ƒ ‚ n  |  j d | |  S(   s~   
        Returns the area of the geographic field in an `area` attribute on
        each element of this GeoQuerySet.
        t   areat
   field_namet   procedure_argst	   geo_fieldt   setups   %(geo_col)s,%(tolerance)st   procedure_fmtt	   tolerancet   sq_mt   select_fields2   Area on geodetic coordinate systems not supported.(   t   _spatial_setupt   gett   FalseR   t   dbt   opst   oracleR   t   postgist
   spatialitet	   geographyt   geodeticR
   t   unit_attnamet
   units_namet	   Exceptiont   _spatial_attribute(   t   selfR   t   kwargsR   R   t   st
   connectiont   backend(    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR      s$    

		
	%c         K   s   |  j  d |  S(   s…   
        Returns the centroid of the geographic field in a `centroid`
        attribute on each element of this GeoQuerySet.
        t   centroid(   t   _geom_attribute(   R+   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR0   8   s    c         K   s   |  j  d | |  S(   s‘   
        Returns the spatial difference of the geographic field in a `difference`
        attribute on each element of this GeoQuerySet.
        t
   difference(   t   _geomset_attribute(   R+   t   geomR,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR2   ?   s    c         K   s   |  j  d | |  S(   s~  
        Returns the distance from the given geographic field name to the
        given geometry in a `distance` attribute on each element of the
        GeoQuerySet.

        Keyword Arguments:
         `spheroid`  => If the geometry field is geodetic and PostGIS is
                        the spatial database, then the more accurate
                        spheroid calculation will be used instead of the
                        quicker sphere calculation.

         `tolerance` => Used only for Oracle. The tolerance is
                        in meters -- a default of 5 centimeters (0.05)
                        is used.
        t   distance(   t   _distance_attribute(   R+   R4   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR5   F   s    c         K   s   |  j  d |  S(   s§   
        Returns a Geometry representing the bounding box of the
        Geometry field in an `envelope` attribute on each element of
        the GeoQuerySet.
        t   envelope(   R1   (   R+   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR7   X   s    c         K   s   |  j  d |  S(   sø   
        Returns a modified version of the Polygon/MultiPolygon in which
        all of the vertices follow the Right-Hand-Rule.  By default,
        this is attached as the `force_rhr` attribute on each element
        of the GeoQuerySet.
        t	   force_rhr(   R1   (   R+   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR8   `   s    i   c         K   s¾   t  |  j j } | j s( t d ƒ ‚ n  t | t j ƒ sI t d ƒ ‚ n  d } | rd | rd d } n | rs d } n | r‚ d } n  i d d 6i | d	 6| d
 6d 6d d 6} |  j	 d | |  S(   s\  
        Returns a GeoJSON representation of the geometry field in a `geojson`
        attribute on each element of the GeoQuerySet.

        The `crs` and `bbox` keywords may be set to True if the user wants
        the coordinate reference system and the bounding box to be included
        in the GeoJSON representation of the geometry.
        s:   Only PostGIS and SpatiaLite support GeoJSON serialization.s.   Precision keyword must be set with an integer.i    i   i   i   t   GeoJSONt   desct	   precisiont   optionsR   s%   %(geo_col)s,%(precision)s,%(options)sR   t   geojson(
   R   R    R!   R=   t   NotImplementedErrort
   isinstanceR   t   integer_typest	   TypeErrorR*   (   R+   R;   t   crst   bboxR,   R/   R<   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR=   i   s     					

i   c         K   s5   i d d 6i | d 6d 6d d 6} |  j  d | |  S(   s  
        Returns a GeoHash representation of the given field in a `geohash`
        attribute on each element of the GeoQuerySet.

        The `precision` keyword may be used to custom the number of
        _characters_ used in the output GeoHash, the default is 20.
        t   GeoHashR:   R;   R   s   %(geo_col)s,%(precision)sR   t   geohash(   R*   (   R+   R;   R,   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRE   †   s    

i   c         K   s…   t  |  j j } i d d 6i | d 6d 6} | j rY d | d <i | d 6| d 6| d <n  | j rr t ƒ  | d <n  |  j d	 | |  S(
   s€   
        Returns GML representation of the given field in a `gml` attribute
        on each element of the GeoQuerySet.
        t   GMLR:   R;   R   s%   %(version)s,%(geo_col)s,%(precision)sR   t   versionR   t   gml(   R   R    R!   R#   R"   R   R*   (   R+   R;   RG   R,   R/   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRH   ”   s    	
	c         K   s   |  j  d | |  S(   sœ   
        Returns the spatial intersection of the Geometry field in
        an `intersection` attribute on each element of this
        GeoQuerySet.
        t   intersection(   R3   (   R+   R4   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRI   £   s    c         K   sA   i d d 6d d 6i | j  d d ƒ d 6d 6} |  j d | |  S(	   s„   
        Returns KML representation of the geometry field in a `kml`
        attribute on each element of this GeoQuerySet.
        t   KMLR:   s   %(geo_col)s,%(precision)sR   R;   i   R   t   kml(   t   popR*   (   R+   R,   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRK   «   s    
c         K   s   |  j  d d |  S(   s   
        Returns the length of the geometry field as a `Distance` object
        stored in a `length` attribute on each element of this GeoQuerySet.
        t   lengthN(   R6   t   None(   R+   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRM   ¶   s    c         K   s   |  j  d i  |  S(   s¡   
        Returns the memory size (number of bytes) that the geometry field takes
        in a `mem_size` attribute  on each element of this GeoQuerySet.
        t   mem_size(   R*   (   R+   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRO   ½   s    c         K   s   |  j  d i  |  S(   sÜ   
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        t   num_geom(   R*   (   R+   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRP   Ä   s    c         K   s   |  j  d i  |  S(   sÇ   
        Returns the number of points in the first linestring in the
        Geometry field in a `num_points` attribute on each element of
        this GeoQuerySet; otherwise sets with None.
        t
   num_points(   R*   (   R+   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRQ   Í   s    c         K   s   |  j  d d |  S(   s£   
        Returns the perimeter of the geometry field as a `Distance` object
        stored in a `perimeter` attribute on each element of this GeoQuerySet.
        t	   perimeterN(   R6   RN   (   R+   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRR   Õ   s    c         K   s   |  j  d |  S(   sÒ   
        Returns a Point geometry guaranteed to lie on the surface of the
        Geometry field in a `point_on_surface` attribute on each element
        of this GeoQuerySet; otherwise sets with None.
        t   point_on_surface(   R1   (   R+   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRS   Ü   s    c         K   sS   i t  ƒ  d 6} | j d d ƒ t |  j j j r@ t | d <n  |  j d | |  S(   s“   
        Reverses the coordinate order of the geometry, and attaches as a
        `reverse` attribute on each element of this GeoQuerySet.
        R   t	   model_attt   reverse_geomt   geo_field_typet   reverse(   R   t
   setdefaultR   R    R!   R"   R   R*   (   R+   R,   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRU   ä   s
    g        c         K   s£   t  |  j j j r] | d k r. t d ƒ ‚ n  i d d 6i | d 6| d 6d 6t ƒ  d 6} n3 i d	 d 6i | d 6| d 6| d
 6d 6t ƒ  d 6} |  j d | |  S(   s|   
        Scales the geometry to a new size by multiplying the ordinates
        with the given x,y,z scale factors.
        g        s'   SpatiaLite does not support 3D scaling.s   %(geo_col)s,%(x)s,%(y)sR   t   xt   yR   R   s   %(geo_col)s,%(x)s,%(y)s,%(z)st   zt   scale(   R   R    R!   R$   R>   R   R*   (   R+   RY   RZ   R[   R,   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR\   ï   s    

c         O   s4  t  g  | D] } t | t f t j ƒ ^ q
 k rA t d ƒ ‚ n  t | ƒ } | d k ry | d } d } i | d 6} nŠ | d k r® | \ } }	 d } i | d 6|	 d	 6} nU | d
 k r÷ | \ } }	 }
 } d } i | d 6|	 d	 6|
 d 6| d 6} n t d ƒ ‚ i | d 6| d 6t ƒ  d 6} |  j	 d | |  S(   sg  
        Snap all points of the input geometry to the grid.  How the
        geometry is snapped to the grid depends on how many arguments
        were given:
          - 1 argument : A single size to snap both the X and Y grids to.
          - 2 arguments: X and Y sizes to snap the grid to.
          - 4 arguments: X, Y sizes and the X, Y origins.
        s@   Size argument(s) for the grid must be a float or integer values.i   i    s   %(geo_col)s,%(size)st   sizei   s   %(geo_col)s,%(xsize)s,%(ysize)st   xsizet   ysizei   s7   %(geo_col)s,%(xorigin)s,%(yorigin)s,%(xsize)s,%(ysize)st   xorigint   yorigins4   Must provide 1, 2, or 4 arguments to `snap_to_grid`.R   R   R   t   snap_to_grid(
   R   R?   t   floatR   R@   RA   t   lent
   ValueErrorR   R*   (   R+   t   argsR,   t   argt   nargsR]   R   R   R^   R_   R`   Ra   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRb     s*    	2

c         K   so   t  t | ƒ ƒ } t | t j ƒ s3 t d ƒ ‚ n  i d d 6d d 6i | d 6| d 6d 6} |  j d	 | |  S(
   sº  
        Returns SVG representation of the geographic field in a `svg`
        attribute on each element of this GeoQuerySet.

        Keyword Arguments:
         `relative`  => If set to True, this will evaluate the path in
                        terms of relative moves (rather than absolute).

         `precision` => May be used to set the maximum number of decimal
                        digits used in output (defaults to 8).
        s2   SVG precision keyword argument must be an integer.t   SVGR:   s!   %(geo_col)s,%(rel)s,%(precision)sR   t   relR;   R   t   svg(   t   intt   boolR?   R   R@   RA   R*   (   R+   t   relativeR;   R,   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRk   &  s    c         K   s   |  j  d | |  S(   s—   
        Returns the symmetric difference of the geographic field in a
        `sym_difference` attribute on each element of this GeoQuerySet.
        t   sym_difference(   R3   (   R+   R4   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRo   ?  s    c         K   s£   t  |  j j j r] | d k r. t d ƒ ‚ n  i d d 6i | d 6| d 6d 6t ƒ  d 6} n3 i d	 d 6i | d 6| d 6| d
 6d 6t ƒ  d 6} |  j d | |  S(   sr   
        Translates the geometry to a new location using the given numeric
        parameters as offsets.
        g        s+   SpatiaLite does not support 3D translation.s   %(geo_col)s,%(x)s,%(y)sR   RY   RZ   R   R   s   %(geo_col)s,%(x)s,%(y)s,%(z)sR[   t	   translate(   R   R    R!   R$   R>   R   R*   (   R+   RY   RZ   R[   R,   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRp   F  s    

iæ  c         K   s`   t  | t j ƒ s! t d ƒ ‚ n  | j d ƒ } |  j d d | ƒ|  j j d | ƒ |  j ƒ  S(   s    
        Transforms the given geometry field to the given SRID.  If no SRID is
        provided, the transformation will default to using 4326 (WGS84).
        s!   An integer SRID must be provided.R   t	   transformt   transformed_srid(	   R?   R   R@   RA   R   R   t   queryt   add_contextt   _clone(   R+   t   sridR,   R   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRq   Y  s    c         K   s   |  j  d | |  S(   s—   
        Returns the union of the geographic field with the given
        Geometry in a `union` attribute on each element of this GeoQuerySet.
        t   union(   R3   (   R+   R4   R,   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRw   e  s    c   	      C   sé   t  |  j } t | j | t ƒ } | d k r7 | } n  | s\ t d | | j j f ƒ ‚ n  i | d 6} |  j | ƒ } | s‘ t	 d | ƒ ‚ n  | d k	 rÉ t
 | | ƒ rÉ t	 d | | j f ƒ ‚ n  |  j | | ƒ | d <| | f S(   sE   
        Performs set up for executing the spatial function.
        s4   %s stored procedure not available on the %s backend.t   functions+   %s output only available on GeometryFields.s1   "%s" stored procedures may only be called on %ss.t   geo_colN(   R   R    t   getattrR!   R   RN   R>   t   namet
   _geo_fieldRA   R?   t   __name__t   _geocol_select(	   R+   t   attR:   R   RV   R.   t   funcR   R   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR   m  s    	c      	   C   s;  t  j d | t d d ƒ| j d d ƒ | j d d ƒ | j d d ƒ | j d i  ƒ | j d d	 ƒ | j d
 g  ƒ t |  j } | j d t ƒ r|  j	 | d | d d | d | j d ƒ ƒ\ } } x> t
 j | ƒ D]  \ } }	 | d j | |	 ƒ qÝ Wn
 | d } t | t
 j ƒ s)| } n  x• | d D]‰ }
 | j | d |
 ƒ } | j d | d | ƒ} | j | d | ƒ } d |
 } | d } | d j | | ƒ | d <| d
 j | ƒ q4Wd | d } | j d ƒ r| d } | j j rt | _ qn	 t ƒ  } |  j j t | | d | d
 | ƒ | ƒ |  S(   sã  
        DRY routine for calling a spatial stored procedure on a geometry column
        and attaching its output as an attribute of the model.

        Arguments:
         att:
          The name of the spatial attribute that holds the spatial
          SQL function to call.

         settings:
          Dictionary of internal settings to customize for the spatial procedure.

        Public Keyword Arguments:

         field_name:
          The name of the geographic field to call the spatial
          function on.  May also be a lookup to a geometry field
          as part of a foreign key relation.

         model_att:
          The name of the model attribute to attach the output of
          the spatial function to.
        sx   The %s GeoQuerySet method is deprecated. See GeoDjango Functions documentation to find the expression-based replacement.t
   stackleveli   R:   t	   geom_argst
   geom_fieldR   R   s   %(geo_col)st   select_paramsR   R   RV   R   t   containsR.   s   %%(%s)ss   %%ss   %%(function)s(%s)R   N(    (   t   warningst   warnR   RX   RN   R   R    R   t   TrueR   R   t	   iteritemsR?   t   string_typest   get_prep_valuet   _get_db_prep_lookupt   get_placeholdert   replacet   extendR!   R"   R   t   empty_strings_allowedR   Rs   t   add_annotationR   (   R+   R   t   settingsR   RT   R.   t   default_argsR   t   kt   vR{   R4   t   paramst   geom_placeholdert   old_fmtt   new_fmtt   fmtR   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR*   Ž  sL    
	


		c         K   s«  |  j  | d | j d ƒ ƒ\ } } t |  j } | j | ƒ }	 | j }
 |	 rX d } n t j | j | ƒ ƒ } | d k } | d k } | d k } | p£ | p£ | s¹ t	 d | ƒ ‚ n  | j
 d k } | pÑ d d	 g } | j } | s| j r|	 r|
 r| r| j d
 ƒ n  | j | ƒ } | j d | d | ƒ} t | ƒ } | j r‚| r`d } n | sl| rud } n  | | d <n§|  j j d ƒ } | rÊt | | ƒ \ } } } | j ƒ  | j k }	 n  |	 rø| j j sé| j j røt	 d ƒ ‚ n  | r}| r´t } d | j | f } | j d& k s;| j | k rk| j r^| d | j | f 7} q±| d 7} qº| j rš| d | j | j | j | f 7} qº| d | j | f 7} n d } |
 r)|	 r)| j s+t | t  ƒ sît	 d ƒ ‚ n  t! t" t# j$ | d	 j% ƒ ƒ j& ƒ d k s+t	 d ƒ ‚ q+n  | r`| d 7} | j' i | j( d 6| d d
 6ƒ qz| j' i | j) d 6ƒ q)n¬ | s‰| r)d } |
 rÑ|	 rÑ| rÑ| d 7} | j' i | j* d 6| d d
 6ƒ q)| r)| j j+ r)| r| j' i | j, d 6ƒ q&| r&| j' i | j- d 6ƒ q&q)n  i t. | ƒ d 6t d 6| d  6| d! 6| d" 6} | ryd' | d$ <| | d! d# <n | r˜| j/ | ƒ g | d% <n  |  j0 | | |  S((   sJ   
        DRY routine for GeoQuerySet distance attribute routines.
        R   t   mR5   RM   RR   s   Unknown distance function: %si   s   POINT (0 0)i    t   spheroidt   distance_lteR.   s"   %(geo_col)s,%(geom)s,%(tolerance)ss   %(geo_col)s,%(tolerance)sR   Rr   s[   This database does not support linear distance calculations on geodetic coordinate systems.s   %s(%%(geo_col)s, %s)s   , %s(%%%%s, %s)s   , %%ss   , %s(%s(%%%%s, %s), %s)s   %(geo_col)s,%(geom)ss=   Spherical distance calculation only supported on PointFields.t   PointsL   Spherical distance calculation only supported with Point Geometry parameterss   ,'%(spheroid)s'Rx   i   s   %(geo_col)sR   R   R   R   R   R4   R‚   R„   N(   R4   (1   R   R   R   R    R&   R%   R   R'   R(   Re   t   dimR!   R#   t   appendR‹   RŒ   Rm   R"   Rs   t   get_contextR   t   lowert   geodetic_unitst   featurest   supports_distance_geodeticR$   R   Rq   Rv   RN   t	   from_textR?   R   t   strR	   R   t
   memoryviewt   ewkbt	   geom_typet   updatet   distance_spheroidt   distance_spheret   length_spheroidt   supports_3d_functionst   perimeter3dt   length3dR   t   AdapterR*   (   R+   R€   R4   R   Rœ   R,   R   R   R.   R&   R%   t   dist_attR5   RM   RR   t   geom_3dt   lookup_paramsR/   R–   R‚   R   Rv   t   ut	   unit_nameR-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR6   å  s     $									+
%
% 

c         K   sT   i t  ƒ  d 6} t |  j j j rA d | d <i | d 6| d <n  |  j | | |  S(   s”   
        DRY routine for setting up a GeoQuerySet method that attaches a
        Geometry attribute (e.g., `centroid`, `point_on_surface`).
        R   s   %(geo_col)s,%(tolerance)sR   R   R   (   R   R   R    R!   R"   R*   (   R+   R€   R   R,   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR1   ~  s
    
c         K   ss   i d	 d 6t  ƒ  d 6d d 6i | d 6d 6} t |  j j j r` | d c d 7<| | d d <n  |  j | | |  S(
   s  
        DRY routine for setting up a GeoQuerySet method that attaches a
        Geometry attribute and takes a Geoemtry parameter.  This is used
        for geometry set-like operations (e.g., intersection, difference,
        union, sym_difference).
        R4   R‚   R   s   %(geo_col)s,%(geom)sR   R   s   ,%(tolerance)sR   (   R4   (   R   R   R    R!   R"   R*   (   R+   R€   R4   R   R,   R-   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR3   ‰  s    
c         C   sþ   |  j  j |  j ƒ } |  j j } | | j k r³ |  j  j | j t d ƒ d g ƒ | j	 ƒ  x@ | j
 D]5 \ } } } | j | k rg | j | | j ƒ d Sqg Wt d | ƒ ‚ nG | | j k rê | j j j } |  j | | | j j ƒ S|  j | | ƒ Sd S(   sÈ   
        Helper routine for constructing the SQL to select the geographic
        column.  Takes into account if the geographic field is in a
        ForeignKey relation to the current model.
        i   i    s(   %r not in compiler's related_select_colsN(   Rs   t   get_compilerR    t   modelt   _metat   fieldst   add_select_relatedt   rsplitR   t   pre_sql_setupt   selectt   output_fieldt   as_sqlR.   Re   t   local_fieldst   concrete_modelt   _field_columnt   db_table(   R+   R   R   t   compilert   optst   colt   _t   parent_model(    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR~   ›  s    #
c         C   sW   | d k r= x* |  j j j D] } t | t ƒ r | Sq Wt St j |  j j | ƒ Sd S(   s'  
        Returns the first Geometry field encountered or the one specified via
        the `field_name` keyword. The `field_name` may be a string specifying
        the geometry field on this GeoQuerySet's model, or a lookup string
        to a geometry field via a ForeignKey relation.
        N(	   RN   R¹   Rº   R»   R?   R    R   R   t   _check_geo_field(   R+   R   t   field(    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR|   ¹  s    c         C   sP   | d k r! | j j ƒ  j } n  d | j | ƒ | j j j | pH | j ƒ f S(   s§  
        Helper function that returns the database column for the given field.
        The table and column are returned (quoted) in the proper format, e.g.,
        `"geoapp_city"."point"`.  If `table_alias` is not specified, the
        database table associated with the model of this `GeoQuerySet` will be
        used.  If `column` is specified, it will be used instead of the value
        in `field.column`.
        s   %s.%sN(	   RN   Rs   t   get_metaRÅ   t   quote_name_unless_aliasR.   R!   t
   quote_namet   column(   R+   RÆ   RÌ   t   table_aliasRÐ   (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyRÄ   Ë  s    	N(&   R}   t
   __module__t   __doc__R   R0   R2   R5   R7   R8   R   R=   RE   RH   RI   RK   RM   RO   RP   RQ   RR   RS   RU   R\   Rb   Rk   Ro   Rp   Rq   Rw   RN   R   R*   R6   R1   R3   R~   R|   RÄ   (    (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyR      sD   																	$		!W™	(!   R†   t#   django.contrib.gis.db.models.fieldsR    R   R   R   t$   django.contrib.gis.db.models.lookupsR   t    django.contrib.gis.db.models.sqlR   R   R   R   t#   django.contrib.gis.geometry.backendR	   t   django.contrib.gis.measureR
   R   t	   django.dbR   t   django.db.models.constantsR   t   django.db.models.expressionsR   t   django.db.models.fieldsR   t   django.db.models.queryR   t   django.utilsR   t   django.utils.deprecationR   R   (    (    (    sD   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/query.pyt   <module>   s   ""