ó
®â0_c           @   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  t |  ƒ j |  j d d ƒ |  d S| 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)))
        i    Ni   (    (
   t   superR	   t   __init__t   _create_polygont   Nonet   lent
   isinstancet   tuplet   listR   (   t   selft   argst   kwargst   ext_ringt
   init_holest   n_holest   polygon(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/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(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyt   __iter__4   s    c         C   s   |  j  d S(   s,   Returns the number of rings in this Polygon.i   (   t   num_interior_rings(   R   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyt   __len__9   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(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyt	   from_bbox=   s    *c   
      C   sî   | s t  j ƒ  Sg  } xC | D]; } t | t ƒ rB | 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   (   t   capit   create_empty_polygonR   R   t   appendt   _construct_ringt   _clonet   popR   t	   enumerateR    R   t   create_polygonR   (
   R   t   lengtht   itemst   ringst   rt   shellR   t   holesR   t   holes_param(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyR   H   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(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyR+   d   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   t	   TypeError(   R   t   paramt   msgt   ring(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyR*   j   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=   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyt	   _set_listu   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(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyt   _get_single_internal   s    c         C   s%   t  t j |  j | ƒ ƒ d |  j ƒS(   NR=   (   R   R'   R6   RD   R=   (   R   RC   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyR   ˜   s    c         C   s   |  d S(   s&   Gets the exterior ring of the Polygon.i    (    (   R   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/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<   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/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   (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pys	   <genexpr>­   s    (   R   R   R   (   R   (    (   R   sA   /tmp/pip-unpacked-wheel-BAJOf3/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(   RI   R   (   R   (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pys	   <genexpr>´   s   s:   <Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>i    (   t   joinR   R   RK   (   R   t	   inner_kml(    (   R   sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyRK   °   s    (   t   __name__t
   __module__t
   _minlengthR   R   R   t   classmethodR&   R   R+   R*   R@   RD   RE   R   t   _set_single_rebuildt   _set_singlet   _assign_extended_slice_rebuildt   _assign_extended_slicet   propertyR   RG   RH   t   exterior_ringR3   R   t   coordsRK   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/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	   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/geos/polygon.pyt   <module>   s   