ó
*Pc           @   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 d d l m Z d d	 l m Z d d
 l m Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ e e e e e e e f e _ d S(   sy   
 This module houses the Geometry Collection objects:
 GeometryCollection, MultiPoint, MultiLineString, and MultiPolygon
iĸĸĸĸ(   t   c_intt   c_uintt   byref(   t   GEOSException(   t   GEOSGeometry(   t   get_pointer_arrt   GEOS_PREPARE(   t
   LineStringt
   LinearRing(   t   Point(   t   Polygon(   t
   prototypes(   t   xranget   GeometryCollectionc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 e
 j Z e
 j Z e d    Z e d	    Z e Z RS(
   i   c         O   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(   sF   Initializes a Geometry Collection from a sequence of Geometry objects.s4   Must provide at least one Geometry to initialize %s.i   i    N(   t	   TypeErrort	   __class__t   __name__t   lent
   isinstancet   tuplet   listt   _check_allowedt   _create_collectiont   itert   superR   t   __init__(   t   selft   argst   kwargst
   init_geomst
   collection(    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyR      s    	c         c   s*   x# t  t |    D] } |  | Vq Wd S(   s.   Iterates over each Geometry in the Collection.N(   R   R   (   R   t   i(    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyt   __iter__+   s    c         C   s   |  j  S(   s4   Returns the number of geometries in this Collection.(   t   num_geom(   R   (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyt   __len__0   s    c         C   sp   t  |  } x9 t |  D]+ \ } } t j t | d |   | | <q Wt j t |  j  t |  t	 |   S(   Nt   ptr(
   R   t	   enumeratet   capit
   geom_clonet   getattrt   create_collectionR    t   _typeidR   R   (   R   t   lengtht   itemst   geomsR   t   g(    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyR   5   s    #c         C   s   t  j |  j |  S(   N(   R%   t	   get_geomnR#   (   R   t   index(    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyt   _get_single_internal?   s    c         C   s%   t  t j |  j |   d |  j S(   sG   Returns the Geometry from this Collection at the given index (0-based).t   srid(   R   R%   R&   R0   R1   (   R   R/   (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyt   _get_single_externalB   s    c         C   sJ   |  j  } |  j } |  j | |  |  _  | r9 | |  _ n  t j |  d S(   sJ   Create a new collection, and destroy the contents of the previous pointer.N(   R#   R1   R   R%   t   destroy_geom(   R   R*   R+   t   prev_ptrR1   (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyt	   _set_listG   s    		 c         C   s'   d d j  g  |  D] } | j ^ q  S(   s-   Returns the KML for this Geometry Collection.s!   <MultiGeometry>%s</MultiGeometry>t    (   t   joint   kml(   R   R-   (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyR8   R   s    c         C   s    t  g  |  D] } | j  ^ q
  S(   sB   Returns a tuple of all the coordinates in this Geometry Collection(   R   (   R   R-   (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyR   W   s    (   R   t
   __module__R)   R   R    R"   R   R0   R2   R5   R   t   _set_single_rebuildt   _set_singlet   _assign_extended_slice_rebuildt   _assign_extended_slicet   propertyR8   R   t   coords(    (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyR      s   				
					t
   MultiPointc           B   s   e  Z e Z d  Z RS(   i   (   R   R9   R	   t   _allowedR)   (    (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyR@   ^   s   t   MultiLineStringc           B   s)   e  Z e e f Z d  Z e d    Z RS(   i   c         C   s   |  j  t j |  j   S(   sc   
        Returns a LineString representing the line merge of this
        MultiLineString.
        (   t	   _topologyR%   t   geos_linemergeR#   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyt   mergedf   s    (   R   R9   R   R   RA   R)   R>   RE   (    (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyRB   b   s   t   MultiPolygonc           B   s#   e  Z e Z d  Z e d    Z RS(   i   c         C   s2   t  r" t t j |  j  |  j  St d   d S(   s.   Returns a cascaded union of this MultiPolygon.s0   The cascaded union operation requires GEOS 3.1+.N(   R   R   R%   t   geos_cascaded_unionR#   R1   R   (   R   (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyt   cascaded_unionr   s    (   R   R9   R
   RA   R)   R>   RH   (    (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyRF   n   s   N(   t   __doc__t   ctypesR    R   R   t   django.contrib.gis.geos.errorR   t    django.contrib.gis.geos.geometryR   t   django.contrib.gis.geos.libgeosR   R   t"   django.contrib.gis.geos.linestringR   R   t   django.contrib.gis.geos.pointR	   t   django.contrib.gis.geos.polygonR
   t   django.contrib.gis.geosR   R%   t   django.utils.six.movesR   R   R@   RB   RF   RA   (    (    (    s<   ../Django//lib/python/django/contrib/gis/geos/collections.pyt   <module>   s   O