o
    uvXjB  ã                   @   sÒ   d 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 ddlmZmZ ddlmZmZ ddlmZ dd	lmZ G d
d„ deƒZG dd„ deƒZG dd„ deeƒZG dd„ deƒZeeeeeeefe_dS )zy
 This module houses the Geometry Collection objects:
 GeometryCollection, MultiPoint, MultiLineString, and MultiPolygon
é    )ÚbyrefÚc_intÚc_uint)Ú
prototypes)ÚGEOSException)ÚGEOSGeometryÚLinearGeometryMixin)ÚGEOM_PTRÚgeos_version_tuple)Ú
LinearRingÚ
LineString)ÚPoint)ÚPolygonc                       sx   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
ejZejZedd„ ƒZedd„ ƒZeZ‡  ZS )ÚGeometryCollectioné   c                    sd   t |ƒdkrt|d ttfƒr|d }n|}n|}|  |¡ |  t |ƒ|¡}tƒ j|fi |¤Ž dS )zEInitialize a Geometry Collection from a sequence of Geometry objects.é   r   N)ÚlenÚ
isinstanceÚtupleÚlistÚ_check_allowedÚ_create_collectionÚsuperÚ__init__)ÚselfÚargsÚkwargsÚ
init_geomsÚ
collection©Ú	__class__© ú`/var/www/html/myproject/venv/lib/python3.10/site-packages/django/contrib/gis/geos/collections.pyr      s   

zGeometryCollection.__init__c                 c   s"   � t t| ƒƒD ]}| | V  qdS )z-Iterate over each Geometry in the Collection.N)Úranger   )r   Úir!   r!   r"   Ú__iter__(   s   €ÿzGeometryCollection.__iter__c                 C   s   | j S )z3Return the number of geometries in this Collection.)Únum_geom©r   r!   r!   r"   Ú__len__-   s   zGeometryCollection.__len__c                 C   s2   t | dd„ |D ƒŽ }t t| jƒt|ƒt|ƒ¡S )Nc                 S   s   g | ]}t  t|d |ƒ¡‘qS )Úptr)ÚcapiÚ
geom_cloneÚgetattr©Ú.0Úgr!   r!   r"   Ú
<listcomp>4   s    ýz9GeometryCollection._create_collection.<locals>.<listcomp>)r	   r*   Úcreate_collectionr   Ú_typeidr   r   )r   ÚlengthÚitemsÚgeomsr!   r!   r"   r   2   s   ýz%GeometryCollection._create_collectionc                 C   s   t  | j|¡S ©N)r*   Ú	get_geomnr)   ©r   Úindexr!   r!   r"   Ú_get_single_internal;   s   z'GeometryCollection._get_single_internalc                 C   s   t t |  |¡¡| jd�S )zFReturn the Geometry from this Collection at the given index (0-based).)Úsrid)r   r*   r+   r:   r;   r8   r!   r!   r"   Ú_get_single_external>   s   z'GeometryCollection._get_single_externalc                 C   s2   | j }| j}|  ||¡| _ |r|| _t |¡ dS )zJCreate a new collection, and destroy the contents of the previous pointer.N)r)   r;   r   r*   Údestroy_geom)r   r3   r4   Úprev_ptrr;   r!   r!   r"   Ú	_set_listC   s   zGeometryCollection._set_listc                 C   s   dd  dd„ | D ƒ¡ S )z,Return the KML for this Geometry Collection.z!<MultiGeometry>%s</MultiGeometry>Ú c                 s   ó   � | ]}|j V  qd S r6   )Úkmlr-   r!   r!   r"   Ú	<genexpr>R   ó   € z)GeometryCollection.kml.<locals>.<genexpr>)Újoinr'   r!   r!   r"   rB   O   s   zGeometryCollection.kmlc                 C   s   t dd„ | D ƒƒS )zAReturn a tuple of all the coordinates in this Geometry Collectionc                 s   rA   r6   ©r   r-   r!   r!   r"   rC   W   rD   z+GeometryCollection.tuple.<locals>.<genexpr>rF   r'   r!   r!   r"   r   T   s   zGeometryCollection.tuple)Ú__name__Ú
__module__Ú__qualname__r2   r   r%   r(   r   r:   r<   r?   r   Ú_set_single_rebuildÚ_set_singleÚ_assign_extended_slice_rebuildÚ_assign_extended_sliceÚpropertyrB   r   ÚcoordsÚ__classcell__r!   r!   r   r"   r      s     		

r   c                   @   ó   e Zd ZeZdZdS )Ú
MultiPointé   N)rG   rH   rI   r   Ú_allowedr2   r!   r!   r!   r"   rR   \   ó    rR   c                       s,   e Zd ZeefZdZe‡ fdd„ƒZ‡  Z	S )ÚMultiLineStringé   c                    s   t ƒ dk r	tdƒ‚tƒ jS )N)é   rW   z.MultiLineString.closed requires GEOS >= 3.5.0.)r
   r   r   Úclosedr'   r   r!   r"   rY   e   s   
zMultiLineString.closed)
rG   rH   rI   r   r   rT   r2   rN   rY   rP   r!   r!   r   r"   rV   a   s
    rV   c                   @   rQ   )ÚMultiPolygoné   N)rG   rH   rI   r   rT   r2   r!   r!   r!   r"   rZ   l   rU   rZ   N)Ú__doc__Úctypesr   r   r   Údjango.contrib.gis.geosr   r*   Údjango.contrib.gis.geos.errorr   Ú django.contrib.gis.geos.geometryr   r   Údjango.contrib.gis.geos.libgeosr	   r
   Ú"django.contrib.gis.geos.linestringr   r   Údjango.contrib.gis.geos.pointr   Údjango.contrib.gis.geos.polygonr   r   rR   rV   rZ   rT   r!   r!   r!   r"   Ú<module>   s    L