

_Vz                 @   s'  d  Z  d d l Z d d l m Z m Z m Z d d l m Z d d l	 m
 Z
 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 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)GEOSGeometryProjectInterpolateMixin)get_pointer_arr)
LinearRing
LineString)Point)Polygon)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   | s t  d |  j j   n  t |  d k r` t | d t t f  rW | d } qf | } n | } |  j |  |  j t |  t	 |   } t
 t |   j | |  d S)zFInitializes a Geometry Collection from a sequence of Geometry objects.z4Must provide at least one Geometry to initialize %s.   r   N)	TypeError	__class____name__len
isinstancetuplelistZ_check_allowed_create_collectionitersuperr   __init__)selfargskwargsZ
init_geomsZ
collection)r    E/tmp/pip-build-ghmbqnp_/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__4   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   9   s    #z%GeometryCollection._create_collectionc             C   s   t  j |  j |  S)N)r&   Z	get_geomnr$   )r   indexr   r   r    _get_single_internalC   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.   r/   )r   r-   r   r   r    _get_single_externalF   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$   r/   r   r&   Zdestroy_geom)r   r*   r+   Zprev_ptrr/   r   r   r    	_set_listK   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)r2   Zcoordinates)r   r   coords).0Zgeomr   r   r    
<listcomp>]   s   	z+GeometryCollection.json.<locals>.<listcomp>Z
geometries)r   r   jsondumpsr   r   )r   )r   r   r    r6   W   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)r4   r,   r   r   r    	<genexpr>g   s    z)GeometryCollection.kml.<locals>.<genexpr>)join)r   r   r   r    r9   d   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   )r4   r,   r   r   r    r:   l   s    z+GeometryCollection.tuple.<locals>.<genexpr>)r   )r   r   r   r    r   i   s    zGeometryCollection.tuple)r   
__module____qualname__r)   r   r"   r#   r   r.   r0   r1   r   Z_set_single_rebuildZ_set_singleZ_assign_extended_slice_rebuildZ_assign_extended_slicepropertyr6   Zgeojsonr9   r   r3   r   r   )r   r    r      s   
			r   c               @   s   e  Z d  Z e Z d Z d S)
MultiPoint   N)r   r<   r=   r   _allowedr)   r   r   r   r    r?   q   s   r?   c               @   s4   e  Z d  Z e e f Z d Z e d d    Z d S)MultiLineString   c             C   s   |  j  t j |  j   S)zc
        Returns a LineString representing the line merge of this
        MultiLineString.
        )Z	_topologyr&   Zgeos_linemerger$   )r   r   r   r    mergedz   s    zMultiLineString.mergedN)	r   r<   r=   r
   r	   rA   r)   r>   rD   r   r   r   r    rB   v   s   rB   c               @   s.   e  Z d  Z e Z d Z e d d    Z d S)MultiPolygon   c             C   s   t  t j |  j  |  j  S)z.Returns a cascaded union of this MultiPolygon.)r   r&   Zgeos_cascaded_unionr$   r/   )r   r   r   r    cascaded_union   s    zMultiPolygon.cascaded_unionN)r   r<   r=   r   rA   r)   r>   rG   r   r   r   r    rE      s   rE   )__doc__r6   ctypesr   r   r   Zdjango.contrib.gis.geosr   r&   Z django.contrib.gis.geos.geometryr   r   Zdjango.contrib.gis.geos.libgeosr   Z"django.contrib.gis.geos.linestringr	   r
   Zdjango.contrib.gis.geos.pointr   Zdjango.contrib.gis.geos.polygonr   Zdjango.utils.six.movesr   r   r?   rB   rE   rA   r   r   r   r    <module>   s   ^