ó
i4Vdc           @   s–   d  d l  m Z 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 e f d	 „  ƒ  YZ d
 S(   iÿÿÿÿ(   t   byreft   c_uint(   t
   prototypes(   t   GEOSGeometry(   t   GEOM_PTRt   get_pointer_arr(   t
   LinearRing(   t   six(   t   ranget   Polygonc           B   sÝ   e  Z d  Z d „  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z	 d d „ Z
 d	 „  Z d
 „  Z d „  Z e j Z e j Z e d „  ƒ Z d „  Z d „  Z e e e ƒ Z e Z e d „  ƒ Z e Z e d „  ƒ Z RS(   i   c         O   sì   | s t  d ƒ ‚ n  | d } | d } t | ƒ } | d k r² t | d t t f ƒ r² t | d ƒ d k r d } d } q² t | d d t ƒ r² | d } t | ƒ } q² n  |  j | d | f | ƒ } t t |  ƒ j	 | |  d S(   sÔ  
        Initializes on an exterior ring and a sequence of holes (both
        instances may be either LinearRing instances, or a tuple/list
        that may be constructed into a LinearRing).

        Examples of initialization, where shell, hole1, and hole2 are
        valid LinearRing geometries:
        >>> from django.contrib.gis.geos import LinearRing, Polygon
        >>> shell = hole1 = hole2 = LinearRing()
        >>> poly = Polygon(shell, hole1, hole2)
        >>> poly = Polygon(shell, (hole1, hole2))

        >>> # Example where a tuple parameters are used:
        >>> poly = Polygon(((0, 0), (0, 10), (10, 10), (0, 10), (0, 0)),
        ...                ((4, 4), (4, 6), (6, 6), (6, 4), (4, 4)))
        sJ   Must provide at least one LinearRing, or a tuple, to initialize a Polygon.i    i   N(    (
   t	   TypeErrort   lent
   isinstancet   tuplet   listR   t   _create_polygont   superR	   t   __init__(   t   selft   argst   kwargst   ext_ringt
   init_holest   n_holest   polygon(    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyR      s    

%	
c         c   s*   x# t  t |  ƒ ƒ D] } |  | Vq Wd S(   s'   Iterates over each ring in the polygon.N(   R   R   (   R   t   i(    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyt   __iter__3   s    c         C   s   |  j  d S(   s,   Returns the number of rings in this Polygon.i   (   t   num_interior_rings(   R   (    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyt   __len__8   s    c         C   sŸ   | \ } } } } xS | D]K } t  | t j t f ƒ s t d | | | | | | | | | | f
 ƒ Sq Wt | | f | | f | | f | | f | | f f ƒ S(   s3   Constructs a Polygon from a bounding box (4-tuple).s,   POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))(   R   R   t   integer_typest   floatR   R	   (   t   clst   bboxt   x0t   y0t   x1t   y1t   z(    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyt	   from_bbox<   s    *c   
      C   sÞ   g  } xC | D]; } t  | t ƒ r2 | j | ƒ q | j |  j | ƒ ƒ q W|  j | j d ƒ ƒ } | d } | r¿ t | ƒ } xB t | ƒ D]+ \ } } |  j | ƒ | | <t | ƒ }	 q Wn d  }	 t
 j | |	 t | ƒ ƒ S(   Ni    i   (   R   R   t   appendt   _construct_ringt   _clonet   popR   t	   enumerateR    t   Nonet   capit   create_polygonR   (
   R   t   lengtht   itemst   ringst   rt   shellR   t   holesR   t   holes_param(    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyR   G   s    
c         C   s0   t  | t ƒ r t j | ƒ St j | j ƒ Sd  S(   N(   R   R   R-   t
   geom_clonet   ptr(   R   t   g(    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyR)   `   s    sY   Parameter must be a sequence of LinearRings or objects that can initialize to LinearRingsc         C   sK   t  | t ƒ r | Sy t | ƒ } | SWn t k
 rF t | ƒ ‚ n Xd S(   sG   Helper routine for trying to construct a ring from the given parameter.N(   R   R   R
   (   R   t   paramt   msgt   ring(    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyR(   f   s    c         C   sJ   |  j  } |  j } |  j | | ƒ |  _  | r9 | |  _ n  t j | ƒ d  S(   N(   R7   t   sridR   R-   t   destroy_geom(   R   R/   R0   t   prev_ptrR<   (    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyt	   _set_listq   s    		c         C   s7   | d k r t  j |  j ƒ St  j |  j | d ƒ Sd S(   sN  
        Returns the ring at the specified index.  The first index, 0, will
        always return the exterior ring.  Indices > 0 will return the
        interior ring at the given index (e.g., poly[1] and poly[2] would
        return the first and second interior ring, respectively).

        CAREFUL: Internal/External are not the same as Interior/Exterior!
        _get_single_internal returns a pointer from the existing geometries for use
        internally by the object's methods.  _get_single_external returns a clone
        of the same geometry for use by external code.
        i    i   N(   R-   t   get_extringR7   t   get_intring(   R   t   index(    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyt   _get_single_internal{   s    c         C   s%   t  t j |  j | ƒ ƒ d |  j ƒS(   NR<   (   R   R-   R6   RC   R<   (   R   RB   (    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyt   _get_single_external   s    c         C   s   t  j |  j ƒ S(   s%   Returns the number of interior rings.(   R-   t
   get_nringsR7   (   R   (    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyR   ”   s    c         C   s   |  d S(   s&   Gets the exterior ring of the Polygon.i    (    (   R   (    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyt   _get_ext_ringš   s    c         C   s   | |  d <d S(   s&   Sets the exterior ring of the Polygon.i    N(    (   R   R;   (    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyt   _set_ext_ringž   s    c            s&   t  ‡  f d †  t t ˆ  ƒ ƒ Dƒ ƒ S(   s-   Gets the tuple for each ring in this Polygon.c         3   s   |  ] } ˆ  | j  Vq d  S(   N(   R   (   t   .0R   (   R   (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pys	   <genexpr>©   s    (   R   R   R   (   R   (    (   R   sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyR   ¦   s    c            s=   d j  ‡  f d †  t ˆ  j ƒ Dƒ ƒ } d ˆ  d j | f S(   s/   Returns the KML representation of this Polygon.t    c         3   s$   |  ] } d  ˆ  | d j  Vq d S(   s%   <innerBoundaryIs>%s</innerBoundaryIs>i   N(   t   kml(   RH   R   (   R   (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pys	   <genexpr>¯   s   s:   <Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>i    (   t   joinR   R   RJ   (   R   t	   inner_kml(    (   R   sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyRJ   ¬   s    (   t   __name__t
   __module__t
   _minlengthR   R   R   t   classmethodR&   R   R)   R(   R?   RC   RD   R   t   _set_single_rebuildt   _set_singlet   _assign_extended_slice_rebuildt   _assign_extended_slicet   propertyR   RF   RG   t   exterior_ringR3   R   t   coordsRJ   (    (    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyR	      s*   	%				
	
						N(   t   ctypesR    R   t   django.contrib.gis.geosR   R-   t    django.contrib.gis.geos.geometryR   t   django.contrib.gis.geos.libgeosR   R   t"   django.contrib.gis.geos.linestringR   t   django.utilsR   t   django.utils.six.movesR   R	   (    (    (    sm   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyt   <module>   s   