ó
ø¢TQc           @   s	  d  d l  m Z d  d l m Z m Z m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z m Z 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
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   connections(   t   QuerySett   ValuesQuerySett   ValuesListQuerySet(   t
   memoryview(   t
   aggregates(   t   get_srid_infot
   PointFieldt   LineStringField(   t	   AreaFieldt   DistanceFieldt	   GeomFieldt   GeoQuery(   t   Geometry(   t   Areat   Distance(   t   sixt   GeoQuerySetc           B   sÊ  e  Z d  Z d/ d/ d/ d „ Z d „  Z d „  Z d d „ Z d „  Z d „  Z	 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 „  Z d d „ Z d  „  Z e d d! „ Z  d" „  Z! d d# „ Z" d$ d% „ Z# d& „  Z$ d' „  Z% d/ d/ d/ d( „ Z& d/ d/ d d) „ Z' d/ d/ d* „ Z( d/ d e d+ „ Z) d d, „ Z* d d- „ Z+ d. „  Z, RS(0   s   The Geographic QuerySet.c         C   sA   t  t |  ƒ j d | d | d | ƒ | p7 t |  j ƒ |  _ d  S(   Nt   modelt   queryt   using(   t   superR   t   __init__R   R   R   (   t   selfR   R   R   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR      s    %c         G   s   |  j  d t d t d | ƒ S(   Nt   klasst   setupt   _fields(   t   _clonet   GeoValuesQuerySett   True(   R   t   fields(    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyt   values   s    c      
   O   s}   | j  d t ƒ } | r4 t d t | ƒ f ƒ ‚ n  | r[ t | ƒ d k r[ t d ƒ ‚ n  |  j d t d t d | d | ƒ S(   Nt   flats/   Unexpected keyword arguments to values_list: %si   sH   'flat' is not valid when values_list is called with more than one field.R   R   R   (   t   popt   Falset	   TypeErrort   listt   lenR   t   GeoValuesListQuerySetR   (   R   R   t   kwargsR    (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyt   values_list   s    gš™™™™™©?c         K   s  |  j  d d | j d 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_fieldR   s   %(geo_col)s,%(tolerance)st   procedure_fmtt	   tolerancet   sq_mt   select_fields2   Area on geodetic coordinate systems not supported.N(   t   _spatial_setupt   gett   NoneR"   R    t   dbt   opst   oracleR	   t   postgist
   spatialitet	   geographyt   geodeticR   t   unit_attnamet
   units_namet	   Exceptiont   _spatial_attribute(   R   R.   R'   R+   R,   t   st
   connectiont   backend(    (    s;   ../Django//lib/python/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'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRB   B   s    c         K   s   |  j  t j |  S(   sÄ   
        Performs an aggregate collect operation on the given geometry field.
        This is analagous to a union operation, but much faster because
        boundaries are not dissolved.
        (   t   _spatial_aggregateR   t   Collect(   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyt   collectI   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'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRG   Q   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   RI   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRJ   X   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(   RC   (   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRL   j   s    c         K   s   |  j  t j |  S(   s¯   
        Returns the extent (aggregate) of the features in the GeoQuerySet.  The
        extent will be returned as a 4-tuple, consisting of (xmin, ymin, xmax, ymax).
        (   RD   R   t   Extent(   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyt   extentr   s    c         K   s   |  j  t j |  S(   s»   
        Returns the aggregate extent, in 3D, of the features in the
        GeoQuerySet. It is returned as a 6-tuple, comprising:
          (xmin, ymin, zmin, xmax, ymax, zmax).
        (   RD   R   t   Extent3D(   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyt   extent3dy   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(   RC   (   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRQ      s    i   c         K   s	  t  |  j j } | j s( t d ƒ ‚ n  t | t j ƒ sI t d ƒ ‚ n  | j	 d k r” d } | rs | rs d } qÍ | r‚ d } qÍ | rÍ d } qÍ n9 d } | r¯ | r¯ d } n | r¾ 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 geomtry field in a `geojson`
        attribute on each element of the GeoQuerySet.

        The `crs` and `bbox` keywords may be set to True if the users wants
        the coordinate reference system and the bounding box to be included
        in the GeoJSON representation of the geometry.
        sF   Only PostGIS 1.3.4+ and SpatiaLite 3.0+ support GeoJSON serialization.s.   Precision keyword must be set with an integer.i   i   i    i   i   t   GeoJSONt   desct	   precisiont   optionsR+   s%   %(geo_col)s,%(precision)s,%(options)sR-   t   geojson(   i   i   i    (   R    R4   R5   RV   t   NotImplementedErrort
   isinstanceR   t   integer_typesR#   t   spatial_versionR>   (   R   RT   t   crst   bboxR'   RA   RU   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRV   Š   s0    		 	 	  	 	 	

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   GeoHashRS   RT   R+   s   %(geo_col)s,%(precision)sR-   t   geohash(   R>   (   R   RT   R'   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR^   ­   s    

i   c         K   sˆ   t  |  j j } i d d 6i | d 6d 6} | j ru | j d k rP d | d <n
 d	 | d <i | d 6| d
 6| d <n  |  j d | |  S(   s€   
        Returns GML representation of the given field in a `gml` attribute
        on each element of the GeoQuerySet.
        t   GMLRS   RT   R+   i   i   s%   %(version)s,%(geo_col)s,%(precision)sR-   s%   %(geo_col)s,%(precision)s,%(version)st   versiont   gml(   i   i   i   (   R    R4   R5   R7   RZ   R>   (   R   RT   R`   R'   RA   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRa   »   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(   RH   (   R   RI   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRb   Í   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   KMLRS   s   %(geo_col)s,%(precision)sR-   RT   i   R+   t   kml(   R!   R>   (   R   R'   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRd   Õ   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(   RK   R3   (   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRe   à   s    c         K   s   |  j  t j d t | S(   sà   
        Creates a linestring from all of the PointField geometries in the
        this GeoQuerySet and returns it.  This is a spatial aggregate
        method, and thus returns a geometry rather than a GeoQuerySet.
        t   geo_field_type(   RD   R   t   MakeLineR   (   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyt	   make_lineç   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'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRi   ï   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'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRj   ö   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'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRk   ÿ   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(   RK   R3   (   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRl     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(   RC   (   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRm     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.
        R0   t	   model_attt   reverse_geomRf   t   reverse(   R   t
   setdefaultR    R4   R5   R6   R   R>   (   R   R'   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRo     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+   R0   s   %(geo_col)s,%(x)s,%(y)s,%(z)st   zt   scale(   R    R4   R5   R8   RW   R   R>   (   R   Rr   Rs   Rt   R'   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRu   !  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+   R0   t   snap_to_grid(
   R"   RX   t   floatR   RY   R#   R%   t
   ValueErrorR   R>   (   R   t   argsR'   t   argt   nargsRv   R-   R+   Rw   Rx   Ry   Rz   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR{   4  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   SVGRS   s!   %(geo_col)s,%(rel)s,%(precision)sR-   t   relRT   R+   t   svg(   t   intt   boolRX   R   RY   R#   R>   (   R   t   relativeRT   R'   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRƒ   X  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(   RH   (   R   RI   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR‡   o  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-   Rr   Rs   R+   R0   s   %(geo_col)s,%(x)s,%(y)s,%(z)sRt   t	   translate(   R    R4   R5   R8   RW   R   R>   (   R   Rr   Rs   Rt   R'   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRˆ   v  s    

iæ  c   	      K   s¾   t  | t j ƒ s! t d ƒ ‚ n  | j d d ƒ } |  j d d | ƒ\ } } |  j | | ƒ } |  j j	 j | | ƒ } d t
 |  j j j | | f } | |  j _ | |  j j	 | <|  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	   transforms
   %s(%s, %s)N(   RX   R   RY   R#   R2   R3   R1   t   _geocol_selectR   t   custom_selectR    R4   R5   R‰   t   transformed_sridR   (	   R   t   sridR'   R*   t   tmpR,   t	   field_colt   geo_colt
   custom_sel(    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR‰   ‰  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(   RH   (   R   RI   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR’   ¥  s    c         K   s   |  j  t j |  S(   s»   
        Performs an aggregate union on the given geometry field.  Returns
        None if the GeoQuerySet is empty.  The `tolerance` keyword is for
        Oracle backends only.
        (   RD   R   t   Union(   R   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyt   unionagg¬  s    c   	      C   sì   t  |  j } t | j | t ƒ } | d k r7 | } n  | s\ t d | | j j f ƒ ‚ n  i | d 6} |  j 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.R   N(   R    R4   t   getattrR5   R"   R3   RW   t   nameR   t
   _geo_fieldR#   RX   t   __name__RŠ   (	   R   t   attRS   R*   Rf   R@   t   funcR+   R,   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR1   µ  s     	c         C   s»   |  j  j | ƒ } | s. t d | j ƒ ‚ n  | d k	 ri t | | ƒ ri t d | j | j f ƒ ‚ n  | pu | j } i  } t |  j j	 j
 rž | | d <n  |  j d | | |  ƒ d S(   s   
        DRY routine for calling aggregate spatial stored procedures and
        returning their result to the caller of the function.
        s.   %s aggregate only available on GeometryFields.s'   %s aggregate may only be called on %ss.R.   t   geoaggN(   R   R˜   R#   R—   R3   RX   R™   R    R4   R5   R6   t	   aggregate(   R   R   R*   Rf   R.   R,   t   agg_colt
   agg_kwargs(    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRD   Õ  s     c      
   C   s\  | j  d d ƒ | j  d d ƒ | j  d d ƒ | j  d i  ƒ | j  d d ƒ | j  d g  ƒ t |  j } | j } | j d t ƒ rö |  j | d | d d	 | d
 | j d
 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 j | | ƒ | d <| d j | ƒ q&Wd | d } | j d t ƒ r3| d } t
 | t ƒ r| j r| j |  j j | <n  | j j r t | _ n  | |  j j | <n  |  j d i | | d | 6d | 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:
          Dictonary 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.
        RS   t	   geom_argst
   geom_fieldR+   R-   s   %(geo_col)st   select_paramsR   R*   Rf   R,   t   containsR@   s   %%(%s)ss   %%ss   %%(function)s(%s)R0   t   selectN(    (   Rq   R3   R    R4   R5   R2   R   R1   R   t	   iteritemsRX   t   string_typest   get_prep_valuet   get_db_prep_lookupt   get_placeholdert   replacet   extendR"   R   R¤   R   R‹   R6   t   empty_strings_allowedt   extra_select_fieldst   extra(   R   Rš   t   settingsR*   Rn   R@   RA   t   default_argsR,   t   kt   vR—   RI   t   paramst   geom_placeholdert   old_fmtt   new_fmtt   fmtt   sel_fld(    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR>   ñ  sD    	 
 	


c         K   s°  |  j  | d | j d d% ƒ ƒ\ } } t |  j } | j | ƒ }	 | j }
 |	 r[ 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…| rcd } n | so| rxd } n  | | d <n©|  j j rÁt |  j j | ƒ \ } } } | | j k }	 n  | j rß|	 rßt
 d ƒ ‚ n  | r…|  j j r¿t } d | j |  j j f } | j d% k s4| j |  j j k rj| j r]| d | j |  j j f 7} q¼| d 7} qÅ| j rŸ| d | j | j | j |  j j f 7} qÅ| d | j |  j j f 7} n d } |
 r.|	 r.| j s3t | t ƒ sùt
 d ƒ ‚ n  t t t  | d	 j! ƒ ƒ j" ƒ d k s3t
 d ƒ ‚ q3n  | rh| d 7} | j# i | j$ d 6| d d
 6ƒ q‚| 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 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} | r~d& | d# <| | d  d" <n | r| j* | ƒ g | d$ <n  |  j+ | | |  S('   sJ   
        DRY routine for GeoQuerySet distance attribute routines.
        R*   t   mRJ   Re   Rl   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.   sT   SQLite 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'R•   i   s   %(geo_col)sR0   R   R,   R+   R-   RI   R    R¢   N(   s   geom(,   R1   R2   R3   R    R4   R:   R9   R   R;   R<   R}   t   dimR5   R7   t   appendR§   R¨   R…   R6   R   RŒ   R   t   geodetic_unitsR8   R"   R‰   R   t	   from_textRX   R   t   strR   R   t   ewkbt	   geom_typet   updatet   distance_spheroidt   distance_spheret   length_spheroidt   perimeter3dt   length3dR
   t   AdapterR>   (   R   R›   RI   R.   Rº   R'   R+   R,   R@   R:   R9   t   dist_attRJ   Re   Rl   t   geom_3dt   lookup_paramsRA   R³   R    R-   t   ut	   unit_nameR?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRK   @  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`).
        R0   s   %(geo_col)s,%(tolerance)sR-   R.   R+   (   R   R    R4   R5   R6   R>   (   R   R›   R.   R'   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRC   Ñ  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).
        RI   R    R0   s   %(geo_col)s,%(geom)sR-   R+   s   ,%(tolerance)sR.   (   s   geom(   R   R    R4   R5   R6   R>   (   R   R›   RI   R.   R'   R?   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRH   Ü  s    

c         C   sô   |  j  j } | | j k r‚ |  j j | g ƒ |  j j |  j ƒ } | j ƒ  |  j j |  j j	 j
 | ƒ \ } } | j | | ƒ S| | j k rÔ | j | j ƒ \ } } }	 }
 |  j j |  j ƒ j | | j j ƒ S|  j j |  j ƒ 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.
        N(   R   t   _metaR   R   t   add_select_relatedt   get_compilerR4   t   pre_sql_setupt   related_select_colst   related_select_fieldst   indext   _field_columnt   local_fieldst   get_field_by_nameR—   t   db_table(   R   R,   R*   t   optst   compilert	   rel_tablet   rel_colt   tmp_fldt   parent_modelt   directt   m2m(    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyRŠ   í  s    
%%N(-   R™   t
   __module__t   __doc__R3   R   R   R(   R)   RB   RF   RG   RJ   RL   RN   RP   RQ   R"   RV   R^   Ra   Rb   Rd   Re   Rh   Ri   Rj   Rk   Rl   Rm   Ro   Ru   R{   Rƒ   R‡   Rˆ   R‰   R’   R”   R1   RD   R>   RK   RC   RH   RŠ   (    (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR      sT   											#												$				 O‘R   c           B   s   e  Z d  „  Z RS(   c         O   s)   t  t |  ƒ j | | Ž  t |  j _ d  S(   N(   R   R   R   R   R   t
   geo_values(   R   R~   R'   (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR     s    (   R™   Rã   R   (    (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR     s   R&   c           B   s   e  Z RS(    (   R™   Rã   (    (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyR&     s   N(   t	   django.dbR    t   django.db.models.queryR   R   R   t   django.contrib.gisR   t   django.contrib.gis.db.modelsR   t#   django.contrib.gis.db.models.fieldsR   R   R   t    django.contrib.gis.db.models.sqlR	   R
   R   R   t#   django.contrib.gis.geometry.backendR   t   django.contrib.gis.measureR   R   t   django.utilsR   R   R   R&   (    (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/query.pyt   <module>   s   "ÿ ÿ ù