3
(h'                 @   s   d Z ddlZddl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 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
    N)byrefc_intc_uint)
prototypes)GEOSException)GEOSGeometryLinearGeometryMixin)geos_version_infoget_pointer_arr)
LinearRing
LineString)Point)Polygon)RemovedInDjango20Warning)rangec                   s   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 fddZeZedd Zedd ZeZ  ZS )GeometryCollection   c                sh   t |dkr.t|d ttfr(|d }q2|}n|}| j| | jt |t|}tt| j	|f| dS )zFInitializes a Geometry Collection from a sequence of Geometry objects.   r   N)
len
isinstancetuplelistZ_check_allowed_create_collectionitersuperr   __init__)selfargskwargsZ
init_geomsZ
collection)	__class__ G/tmp/pip-install-q3hcpn_q/Django/django/contrib/gis/geos/collections.pyr      s    

zGeometryCollection.__init__c             c   s$   xt t| D ]}| | V  qW dS )z.Iterates over each Geometry in the Collection.N)r   r   )r   ir    r    r!   __iter__-   s    zGeometryCollection.__iter__c             C   s   | j S )z4Returns the number of geometries in this Collection.)Znum_geom)r   r    r    r!   __len__2   s    zGeometryCollection.__len__c             C   sP   t |}x*t|D ]\}}tjt|d|||< qW tjt| jt|t	|S )Nptr)
r
   	enumeratecapi
geom_clonegetattrZcreate_collectionr   _typeidr   r   )r   lengthitemsZgeomsr"   gr    r    r!   r   7   s    z%GeometryCollection._create_collectionc             C   s   t j| j|S )N)r'   Z	get_geomnr%   )r   indexr    r    r!   _get_single_internalA   s    z'GeometryCollection._get_single_internalc             C   s   t tj| j|| jdS )zGReturns the Geometry from this Collection at the given index (0-based).)srid)r   r'   r(   r/   r0   )r   r.   r    r    r!   _get_single_externalD   s    z'GeometryCollection._get_single_externalc             C   s2   | j }| j}| j||| _ |r$|| _tj| dS )zJCreate a new collection, and destroy the contents of the previous pointer.N)r%   r0   r   r'   Zdestroy_geom)r   r+   r,   Zprev_ptrr0   r    r    r!   	_set_listI   s    zGeometryCollection._set_listc                s6   | j jdkr*tj| j jdd | D dS tt| jS )Nr   c             S   s   g | ]}|j j|jd qS ))typeZcoordinates)r   __name__coords).0Zgeomr    r    r!   
<listcomp>[   s   z+GeometryCollection.json.<locals>.<listcomp>)r3   Z
geometries)r   r4   jsondumpsr   r   )r   )r   r    r!   r8   U   s    zGeometryCollection.jsonc             C   s   ddj dd | D  S )z-Returns the KML for this Geometry Collection.z!<MultiGeometry>%s</MultiGeometry> c             s   s   | ]}|j V  qd S )N)kml)r6   r-   r    r    r!   	<genexpr>e   s    z)GeometryCollection.kml.<locals>.<genexpr>)join)r   r    r    r!   r;   b   s    zGeometryCollection.kmlc             C   s   t dd | D S )zBReturns a tuple of all the coordinates in this Geometry Collectionc             s   s   | ]}|j V  qd S )N)r   )r6   r-   r    r    r!   r<   j   s    z+GeometryCollection.tuple.<locals>.<genexpr>)r   )r   r    r    r!   r   g   s    zGeometryCollection.tuple)r4   
__module____qualname__r*   r   r#   r$   r   r/   r1   r2   r   Z_set_single_rebuildZ_set_singleZ_assign_extended_slice_rebuildZ_assign_extended_slicepropertyr8   Zgeojsonr;   r   r5   __classcell__r    r    )r   r!   r      s   
	r   c               @   s   e Zd ZeZdZdS )
MultiPoint   N)r4   r>   r?   r   _allowedr*   r    r    r    r!   rB   o   s   rB   c                   s,   e Zd ZeefZdZe fddZ  Z	S )MultiLineString   c                s"   t  d dk rtdtt| jS )Nversionz3.5z.MultiLineString.closed requires GEOS >= 3.5.0.)r	   r   r   rE   closed)r   )r   r    r!   rH   x   s    zMultiLineString.closed)
r4   r>   r?   r   r   rD   r*   r@   rH   rA   r    r    )r   r!   rE   t   s   rE   c               @   s    e Zd ZeZdZedd ZdS )MultiPolygon   c             C   s"   t jdtd ttj| j| jS )z.Returns a cascaded union of this MultiPolygon.zG`cascaded_union` is deprecated, use the `unary_union` property instead.   )warningswarnr   r   r'   Zgeos_cascaded_unionr%   r0   )r   r    r    r!   cascaded_union   s    zMultiPolygon.cascaded_unionN)r4   r>   r?   r   rD   r*   r@   rN   r    r    r    r!   rI      s   rI   )"__doc__r8   rL   ctypesr   r   r   Zdjango.contrib.gis.geosr   r'   Zdjango.contrib.gis.geos.errorr   Z django.contrib.gis.geos.geometryr   r   Zdjango.contrib.gis.geos.libgeosr	   r
   Z"django.contrib.gis.geos.linestringr   r   Zdjango.contrib.gis.geos.pointr   Zdjango.contrib.gis.geos.polygonr   Zdjango.utils.deprecationr   Zdjango.utils.six.movesr   r   rB   rE   rI   rD   r    r    r    r!   <module>   s"   [