
    Dvg6                     R    d dl mZ d dlmZ d dlmZ d dlmZ  G d de          Z	dS )    )
prototypes)GEOSGeometry)GEOM_PTR)
LinearRingc                        e Zd ZdZ f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 xZS )Polygon   c                    |s0 t                      j        |                     dd          fi | dS |^}}t          |          }|dk    rgt	          |d         t
          t          f          rE|d         sd}d}n8t	          |d         d         t                    r|d         }t          |          }|                     |dz   |g|          } t                      j        |fi | dS )a  
        Initialize 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), (10, 0), (0, 0)),
        ...                ((4, 4), (4, 6), (6, 6), (6, 4), (4, 4)))
        r   Nr	    )super__init___create_polygonlen
isinstancetuplelistr   )selfargskwargsext_ring
init_holesn_holespolygon	__class__s          \/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/gis/geos/polygon.pyr   zPolygon.__init__
   s   "  	EGGT11!T::EEfEEEF !%:j// a<<Jz!}udmDD<a= *
JqM!,j99 *']
j//&&w{X4K
4KLL++F+++++    c              #   \   K   t          t          |                     D ]}| |         V  dS )z&Iterate over each ring in the polygon.N)ranger   )r   is     r   __iter__zPolygon.__iter__0   s<      s4yy!! 	 	Aq'MMMM	 	r   c                     | j         dz   S )z+Return the number of rings in this Polygon.r	   )num_interior_ringsr   s    r   __len__zPolygon.__len__5   s    &**r   c                     |\  }}}}|D ]N}t          |t          t          f          s0t          d|d|d|d|d|d|d|d|d|d|d          c S Ot	          ||f||f||f||f||ff          S )z2Construct a Polygon from a bounding box (4-tuple).z	POLYGON(( z, z)))r   floatintr   r   )clsbboxx0y0x1y1zs          r   	from_bboxzPolygon.from_bbox9   s     BB 	 	Aa%.. #|rr222rrr222rrr222rrr222rrr222?    
 R2r(RHr2hRIJJJr   c                     |st          j                    S g }|D ]U}t          |t                    r|                    |           -|                                         |                     V                     |                    d                    }|dz
  }|rt          |z   fd|D              }nd }t          j        |||          S )Nr   r	   c                 :    g | ]}                     |          S r   )_clone).0rr   s     r   
<listcomp>z+Polygon._create_polygon.<locals>.<listcomp>Y   s#    0O0O0OAQ0O0O0Or   )	capicreate_empty_polygonr   r   append_construct_ringr3   popcreate_polygon)r   lengthitemsringsr5   shellr   holes_params   `       r   r   zPolygon._create_polygonF   s    
  	/,... 	6 	6A!X&& 6QT11!445555EIIaLL))1* 	#g-0O0O0O0O0O0O0OPKKK"5+w???r   c                     t          |t                    rt          j        |          S t          j        |j                  S N)r   r   r7   
geom_cloneptr)r   gs     r   r3   zPolygon._clone_   s6    a"" 	*?1%%%?15)))r   YParameter must be a sequence of LinearRings or objects that can initialize to LinearRingsc                     t          |t                    r|S 	 t          |          S # t          $ r t          |          w xY w)z1Try to construct a ring from the given parameter.)r   r   	TypeError)r   parammsgs      r   r:   zPolygon._construct_ringe   sU     eZ(( 	L	!e$$$ 	! 	! 	!C.. 	!s	   ( Ac                     | j         }| j        }|                     ||          | _         |r|| _        t          j        |           d S rC   )rE   sridr   r7   destroy_geom)r   r=   r>   prev_ptrrM   s        r   	_set_listzPolygon._set_listu   sO     8y''66 	DI(#####r   c                 z    |dk    rt          j        | j                  S t          j        | j        |dz
            S )a7  
        Return 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!
        Return 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.
        r   r	   )r7   get_extringrE   get_intringr   indexs     r   _get_single_internalzPolygon._get_single_internal   s;     A::#DH--- #DHeai888r   c                 x    t          t          j        |                     |                    | j                  S )N)rM   )r   r7   rD   rV   rM   rT   s     r   _get_single_externalzPolygon._get_single_external   s8    OD55e<<==DI
 
 
 	
r   c                 4    t          j        | j                  S )z$Return the number of interior rings.)r7   
get_nringsrE   r#   s    r   r"   zPolygon.num_interior_rings   s     tx(((r   c                     | d         S )z%Get the exterior ring of the Polygon.r   r   r#   s    r   _get_ext_ringzPolygon._get_ext_ring   s    Awr   c                     || d<   dS )z%Set the exterior ring of the Polygon.r   Nr   )r   rings     r   _set_ext_ringzPolygon._set_ext_ring   s    Qr   c                 n     t           fdt          t                               D                       S )z,Get the tuple for each ring in this Polygon.c              3   2   K   | ]}|         j         V  d S rC   )r   r4   r   r   s     r   	<genexpr>z Polygon.tuple.<locals>.<genexpr>   s)      ==qT!W]======r   )r   r   r   r#   s   `r   r   zPolygon.tuple   s6     ====E#d)),<,<======r   c                      d                      fdt           j                  D                       }d d         j        d|dS )z.Return the KML representation of this Polygon. c              3   >   K   | ]}d |dz            j         z  V  dS )z%<innerBoundaryIs>%s</innerBoundaryIs>r	   N)kmlrb   s     r   rc   zPolygon.kml.<locals>.<genexpr>   sF       
 
 4d1q5koE
 
 
 
 
 
r   z<Polygon><outerBoundaryIs>r   z</outerBoundaryIs>z
</Polygon>)joinr   r"   rg   )r   	inner_kmls   ` r   rg   zPolygon.kml   sk     GG 
 
 
 
4233
 
 
 
 
		
 GKKKII
 	
r   )rG   )__name__
__module____qualname__
_minlengthr   r    r$   classmethodr0   r   r3   r:   rP   rV   rX   r   _set_single_rebuild_set_single_assign_extended_slice_rebuild_assign_extended_slicepropertyr"   r\   r_   exterior_ringr@   r   coordsrg   __classcell__)r   s   @r   r   r      s~       J$, $, $, $, $,L  
+ + + 	K 	K [	K@ @ @2* * *(	! ! ! ! $ $ $9 9 9$
 
 

 2K)H ) ) X)
    
 H]M::ME> > X> F	
 	
 X	
 	
 	
 	
 	
r   r   N)
django.contrib.gis.geosr   r7    django.contrib.gis.geos.geometryr   django.contrib.gis.geos.libgeosr   "django.contrib.gis.geos.linestringr   r   r   r   r   <module>r{      s    6 6 6 6 6 6 9 9 9 9 9 9 4 4 4 4 4 4 9 9 9 9 9 9v
 v
 v
 v
 v
l v
 v
 v
 v
 v
r   