
v^7                 @   s  d  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 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
    )byrefc_intc_uint)
prototypes)GEOSGeometryLinearGeometryMixin)GEOM_PTR)
LinearRing
LineString)Point)Polygonc                   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 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   j | |  d S)zEInitialize a Geometry Collection from a sequence of Geometry objects.   r   N)len
isinstancetuplelistZ_check_allowed_create_collectionsuper__init__)selfargskwargsZ
init_geomsZ
collection)	__class__ E/tmp/pip-build-8lau8j11/django/django/contrib/gis/geos/collections.pyr      s    	zGeometryCollection.__init__c             c   s*   x# t  t |    D] } |  | Vq Wd 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.)Znum_geom)r   r   r   r   __len__,   s    zGeometryCollection.__len__c             C   sE   t  | d d   | D   } t j t |  j  t |  t |   S)Nc             S   s+   g  |  ]! } t  j t | d  |    q S)ptr)capi
geom_clonegetattr).0gr   r   r   
<listcomp>6   s   	 z9GeometryCollection._create_collection.<locals>.<listcomp>)r   r"   Zcreate_collectionr   _typeidr   r   )r   lengthitemsZgeomsr   r   r   r   1   s    z%GeometryCollection._create_collectionc             C   s   t  j |  j |  S)N)r"   Z	get_geomnr!   )r   indexr   r   r   _get_single_internal:   s    z'GeometryCollection._get_single_internalc             C   s%   t  t j |  j |   d |  j S)zFReturn the Geometry from this Collection at the given index (0-based).srid)r   r"   r#   r,   r-   )r   r+   r   r   r   _get_single_external=   s    z'GeometryCollection._get_single_externalc             C   sG   |  j  } |  j } |  j | |  |  _  | r6 | |  _ 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_listB   s    			zGeometryCollection._set_listc             C   s   d d j  d d   |  D  S)z,Return the KML for this Geometry Collection.z!<MultiGeometry>%s</MultiGeometry> c             s   s   |  ] } | j  Vq d  S)N)kml)r%   r&   r   r   r   	<genexpr>Q   s    z)GeometryCollection.kml.<locals>.<genexpr>)join)r   r   r   r   r1   N   s    zGeometryCollection.kmlc             C   s   t  d d   |  D  S)zAReturn a tuple of all the coordinates in this Geometry Collectionc             s   s   |  ] } | j  Vq d  S)N)r   )r%   r&   r   r   r   r2   V   s    z+GeometryCollection.tuple.<locals>.<genexpr>)r   )r   r   r   r   r   S   s    zGeometryCollection.tuple)__name__
__module____qualname__r(   r   r   r    r   r,   r.   r/   r   Z_set_single_rebuildZ_set_singleZ_assign_extended_slice_rebuildZ_assign_extended_slicepropertyr1   r   Zcoordsr   r   )r   r   r      s   				r   c               @   s   e  Z d  Z e Z d Z d S)
MultiPoint   N)r4   r5   r6   r   _allowedr(   r   r   r   r   r8   [   s   r8   c               @   s"   e  Z d  Z e e f Z d Z d S)MultiLineString   N)r4   r5   r6   r
   r	   r:   r(   r   r   r   r   r;   `   s   r;   c               @   s   e  Z d  Z e Z d Z d S)MultiPolygon   N)r4   r5   r6   r   r:   r(   r   r   r   r   r=   e   s   r=   N)__doc__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   r   r8   r;   r=   r:   r   r   r   r   <module>   s   L