
 X'                 @   sY  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 Gd d   d e  Z Gd d   d e  Z Gd d   d e e  Z Gd 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   S)GeometryCollection   c                s   t  |  d k rA t | d t t f  r8 | d } qG | } n | } |  j |  |  j t  |  t |   } t t |   j	 | |  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__ Q/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/geos/collections.pyr      s    	zGeometryCollection.__init__c             c   s*   x# t  t |    D] } |  | Vq Wd 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  |  } x9 t |  D]+ \ } } t j t | d |   | | <q Wt 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 |   d |  j 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   sJ   |  j  } |  j } |  j | |  |  _  | r9 | |  _ n  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                sP   |  j  j d k r@ t j i |  j  j d 6d d   |  D d 6 St t |   j S)Nr   typec             S   s-   g  |  ]# } i | j  j d  6| j d 6 q S)r3   Zcoordinates)r   __name__coords).0Zgeomr    r    r!   
<listcomp>[   s   	z+GeometryCollection.json.<locals>.<listcomp>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   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!   rA   o   s   rA   c                   s:   e  Z d  Z e e f Z d Z e   f d d    Z   S)MultiLineString   c                s2   t    d d k  r" t d   n  t t |   j S)Nversionz3.5z.MultiLineString.closed requires GEOS >= 3.5.0.)r	   r   r   rD   closed)r   )r   r    r!   rG   x   s    zMultiLineString.closed)	r4   r>   r?   r   r   rC   r*   r@   rG   r    r    )r   r!   rD   t   s   rD   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   rC   r*   r@   rM   r    r    r    r!   rH      s   rH   )"__doc__r8   rK   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   rA   rD   rH   rC   r    r    r    r!   <module>   s"   [