
J~Pc           @@  s   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 m Z m Z m Z m Z d  d l m Z d d	 l m Z m Z m Z m Z m Z m Z m Z d
 e f d     YZ d S(   i    (   t   absolute_import(   t
   connection(   t   Q(   t   GEOSGeometryt
   LineString(   t   D(   t   oraclet   postgist
   spatialitet	   no_oraclet   no_spatialite(   t   TestCasei   (   t   AustraliaCityt
   Interstatet   SouthTexasInterstatet   SouthTexasCityt   SouthTexasCityFtt   CensusZipcodet   SouthTexasZipcodet   DistanceTestc           B@  s   e  Z e d  d  Z e d d  Z d   Z d   Z e d    Z d   Z	 e d    Z
 e d    Z d	   Z d
   Z d   Z d   Z e d    Z d   Z RS(   s.   POINT (-95.370401017314293 29.704867409475465)i  s   POINT (150.791 -34.4919)c         C@  s*   g  | D] } | j  ^ q } | j   | S(   N(   t   namet   sort(   t   selft   qst   ct   cities(    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt	   get_names   s    
c         C@  s   |  j  d t j j    |  j  d t j j    |  j  d t j j    |  j  d t j j    |  j  d t j j    |  j  d t j j    |  j  d t	 j j    d S(   s'   Test initialization of distance models.i	   i   i   i   N(
   t   assertEqualR   t   objectst   countR   R   R   R   R   R   (   R   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test01_init   s    c      	   C@  s  d t  d d  t  d d  g } d t  d d	  t  d d
  g } d d g } d d d d g } x | D] } t | t  r | \ } } n
 | } } t j j d |  j | f  } t j j d |  j | f  }	 x- | |	 f D] }
 |  j | |  j	 |
   q Wqg Wx | D] } t | t   r1t
 r1t } n t } t | t  rft
 rY| d } qf| d } n  t j j d  }
 | r|  j t t j j d |  j | f  j  q|  j | |  j	 |
 j d |  j | f    qWd S(   s"   Testing the `dwithin` lookup type.iX  gQum@t   kmi   t   migL7A`e@g      ?i }  i    gM3@s   Downtown Houstons   Southside Placet	   Mittagongt   Shellharbourt   Thirroult
   Wollongongt   point__dwithini   i    R   N(   iX  gQum@(   g      ?i }  (   R   t
   isinstancet   tupleR   R   t   filtert   stx_pntR   R   R   R   t   Truet   FalseR   t   order_byt   assertRaisest
   ValueErrort   au_pntR   (   R   t   tx_distst   au_distst	   tx_citiest	   au_citiest   distt   dist1t   dist2t   qs1t   qs2R   t
   type_error(    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test02_dwithin'   s0    !! 
! 	 .c      	   C@  sP  t  d d  } d d d d d d d	 d
 d g	 } d d d d d d d d d g	 } t j j | d d } t j j |  } t s t r | | g } n9 t j j | j  } t j j |  } | | | | g } t r d }	 n d }	 xe | D]] }
 xT t |
  D]F \ } } |  j	 | | | j j
 |	  |  j	 | | | j j |	  q Wq Wd S(   sJ   Testing the `distance` GeoQuerySet method on projected coordinate systems.s   POINT(-96.876369 29.905320)i  g?AgVbqAg	0l2AgF<y Ag{V)SAg'G	AgBcM@g..AgK Ag*sAgAgq_6Ag$pAg,'iAga>%Ag9
bAg8Bۍ Ag؟At
   field_namet   pointi   i   N(   R   R   R   t   distanceR   R   R   t   ewktt	   enumeratet   assertAlmostEqualt   mt	   survey_ft(   R   t   lagranget   m_distancest   ft_distancesR5   R6   t   dist_qst   dist3t   dist4t   tolR   t   iR   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test03a_distance_methodP   s*    				 	c         C@  s  t  r d } n d } t d@ dA f  } t  s9 t j j r d d d	 d
 d d d d d d d g } t j j |  j d  } xn t	 | |  D]% \ } } |  j
 | | j j d  q Wn5 |  j t t j j |  |  j t t j j | j  t j j rXt j j   dB k rXd d d d d d d d d d g
 } d d d  d! d" d# d$ d% d& d' g
 } nH d( d) d* d+ d, d- d. d/ d0 d1 g
 } d2 d3 d4 d5 d6 d7 d8 d9 d: d; g
 } t j j d d<  }	 t j j d= |	 j  j |	 j d> t } x7 t |  D]) \ }
 } |  j
 | |
 | j j |  qWt rt j j d= |	 j  j |	 j  } x: t |  D]) \ }
 } |  j
 | |
 | j j |  qPWn  d? S(C   sH   Testing the `distance` GeoQuerySet method on geodetic coordnate systems.i   i   g/b@guV6Agp=
b@g+eJAgY1Agm(AgthS#Agɉ3@gr-AgY!Agem@i    g
<@gD=+@R   i   i   g=@g?
/@g#Q`\ @gZ-@g~։
Ag0x%Agd#AgrƵ\@gk/Ag|gF1Ag3@gIK@g!@gL+@g`
Ag%A%Ag*wP#AgSYj@gt0AgK1Ag9"@gv.@g3C`\ @g4_-@gSͱ~։
Age x%AgSJ#Ag֏\@ghk/AgZhF1AgD\@g>Zt|@gm@g~G+@g#
Aga%Ag룆#Ag)Āj@gvp0Agͺ{1At	   Hillsdalet   idt   spheroidN(   g/b@guV6A(   gp=
b@g+eJA(   i   i   i    (   R   R   R   t   opst	   geographyR   R   R=   R,   t   zipR@   RA   R-   R.   t   wktR   t   proj_version_tuplet   gett   excludeRM   R<   R*   R?   (   R   RI   t   lst	   distancesR   t   cityR=   t   spheroid_distancest   sphere_distancest	   hillsdaleRJ   R   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test03b_distance_methodw   sL     			 !															*!$c   	      C@  s  t  j j s+ |  j t t j j |  j  n  t	 j j
 d d  } d d d g } | j j j d  } | j d d t } d	 d
 d g } x | | g D] } t j j d d  j d  j |  } |  j | |  j |   x7 t |  D]) \ } } |  j | j j | | d  q Wq Wd S(   sV   Testing the `distance` GeoQuerySet method used with `transform` on a geographic field.R   t   77005g0«@g^GTl@g6O@id   i  t   clonet   77002t   77025t   77401i}  i   N(   R   RO   RP   R-   R.   R   R   R=   R)   R   RT   t   polyt   centroidt   buffert	   transformR*   RU   R   R   R?   R@   RA   (	   R   t   zt   dists_mt   buf1t   buf2t   ref_zipst   bufR   RJ   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test03c_distance_method   s    'c         C@  s  t  j j d |  j t d d  f  j d |  j t d d  f  } t sQ t r] | f } nQ t j j d |  j t d d  f  j d |  j t d d  f  } | | f } x6 | D]. } |  j |  } |  j	 | d d d g  q Wt
 j j d	 d
  } t
 j j d	 d
  j d | j t d d  f  } |  j	 d d g |  j |   t
 j j d	 d
  j d | j t d d  f  } |  j	 d d d g |  j |   d S(   sZ   Testing the `distance_lt`, `distance_gt`, `distance_lte`, and `distance_gte` lookup types.t   point__distance_gteR   i   t   point__distance_ltei   t   Bellairet   Pearlands   West University PlaceR   R]   t   poly__distance_lteRA   i  R`   Ra   i,  R_   N(   R   R   R(   R)   R   R   R   R   R   R   R   RT   RU   Rb   (   R   R7   RF   R8   R   R   Rf   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test04_distance_lookups   s    EE33c         C@  s  t  d d  } t j j d | t d d  f  } t sE t j j r |  j	 d | j
    |  j	 d d d	 d
 d d d d d g	 |  j |   n |  j t | j
  t r d S|  j t t t j j d d t d d  d d f   |  j t t t j j d d   t j j d d  } t j j d d  j d | j t d d  f  } |  j |  } |  j	 | d d d
 g  t j j d d  } t d d  t d d  } } t d | j | f  }	 t d | j | f  }
 t j j d d  j |	 |
 B } t rkt d | j | d f  } t d | j | d f  } t j j d d  j | | B } | | g } n	 | g } x9 | D]1 } |  j |  } |  j	 | d d d d g  q{Wd S(   s8   Testing distance lookups on geodetic coordinate systems.s/   LINESTRING(144.9630 -37.8143,151.2607 -33.8870)i  Rn   R   id   i	   s   Batemans Bayt   CanberraRL   t	   MelbourneR!   R"   t   SydneyR#   R$   Ns   POINT(5 23)RN   t   4R   t   HobartR    i&  t   ydi,L  t   nmi  Rm   t   Adelaide(   s   POINT(5 23)(   R   R   R   R(   R   R   R   RO   RP   R   R   R   R-   R.   R   t   lenRT   RU   R<   R   R   (   R   t   lineRF   t   hobartR   R   t
   wollongongt   d1t   d2t   gq1t   gq2R7   t   gq3t   gq4R8   t	   querysets(    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt    test05_geodetic_distance_lookups   sB    $	 +3""	c         C@  s_   d d d d g } d } x@ t  t j j    D]) \ } } |  j | | | j j |  q. Wd S(   s&   Testing the `area` GeoQuerySet method.g  9uTAg.lcAg;XweAg  ^bAi   N(   R?   R   R   t   areaR@   t   sq_m(   R   t	   area_sq_mRI   RJ   Rf   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test06_area/  s    "c         C@  s   d } d } t  r+ |  j t t j j  nA t j j   } t rI d } n d } |  j | | d j j |  t	 j j   j
 d d  } |  j | | j j d  d S(	   s(   Testing the `length` GeoQuerySet method.g-AgI	@i   i   i    R   s   I-10N(   R   R-   R.   R   R   t   lengthR   R@   RA   R   RT   (   R   t   len_m1t   len_m2R   RI   t   i10(    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test07_length:  s     	c         C@  s   d d d d g } t  r! d } n d } x@ t t j j    D]) \ } } |  j | | | j j |  q= Wx? t t j j d d   D]" \ } } |  j d	 | j	 j  q Wd
 S(   s+   Testing the `perimeter` GeoQuerySet method.gƹ@gL@g#&@g`@i   i   t	   model_attt   perimi    N(
   R   R?   R   R   t	   perimeterR@   RA   R   R   R   (   R   t   perim_mRI   RJ   Rf   R   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test08_perimeterN  s     	"!(c         C@  sy   t  j j d d  t j j d d  } t  j j | j  j   j d d  } |  j d | j  |  j d | j  d S(   sG   Testing the measurement GeoQuerySet methods on fields with NULL values.R   t   78212s   Downtown HoustonN(
   R   R   t   createR   RT   R=   R<   R   R   t   None(   R   t   htownRf   (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   test09_measurement_null_fields]  s
    '(   t   __name__t
   __module__R   R)   R/   R   R   R
   R:   RK   R\   R	   Rl   Rr   R   R   R   R   R   (    (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyR      s   		
)	'=!		?		N(   t
   __future__R    t	   django.dbR   t   django.db.modelsR   t   django.contrib.gis.geosR   R   t   django.contrib.gis.measureR   t   django.contrib.gis.tests.utilsR   R   R   R	   R
   t   django.testR   t   modelsR   R   R   R   R   R   R   R   (    (    (    s?   ../Django//lib/python/django/contrib/gis/tests/distapp/tests.pyt   <module>   s   (4