3
®?d]R  ã               @   sH   d Z ddlmZ ddlmZmZ ddlmZ G dd„ deƒZ	dd„ Z
d	S )
z0
Support for GEOS prepared geometry operations.
é    )Úlgeos)ÚDefaultImplementationÚ	delegated)ÚPicklingErrorc               @   s¤   e Zd ZdZeZdd„ Zdd„ Zedd„ ƒZ	e
dd	„ ƒZe
d
d„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZdd„ ZdS )ÚPreparedGeometrya7  
    A geometry prepared for efficient comparison to a set of other geometries.
    
    Example:
      
      >>> from shapely.geometry import Point, Polygon
      >>> triangle = Polygon(((0.0, 0.0), (1.0, 1.0), (1.0, -1.0)))
      >>> p = prep(triangle)
      >>> p.intersects(Point(0.5, 0.5))
      True
    c             C   s   || _ tj| j jƒ| _d S )N)Úcontextr   ZGEOSPrepareÚ_geomÚ__geom__)Úselfr   © r   ú3/tmp/pip-build-op5p2y5_/shapely/shapely/prepared.pyÚ__init__   s    zPreparedGeometry.__init__c             C   s@   | j d k	r0ytj| j ƒ W n tk
r.   Y nX d | _ d | _d S )N)r	   r   ZGEOSPreparedGeom_destroyÚAttributeErrorr   )r
   r   r   r   Ú__del__   s    
zPreparedGeometry.__del__c             C   s   | j S )N)r	   )r
   r   r   r   r   &   s    zPreparedGeometry._geomc             C   s   t | jd | |ƒƒS )z;Returns True if the geometry contains the other, else FalseZprepared_contains)ÚboolÚimpl)r
   Úotherr   r   r   Úcontains*   s    zPreparedGeometry.containsc             C   s   t | jd | |ƒƒS )zDReturns True if the geometry properly contains the other, else FalseZprepared_contains_properly)r   r   )r
   r   r   r   r   Úcontains_properly/   s    z"PreparedGeometry.contains_properlyc             C   s   t | jd | |ƒƒS )z9Returns True if the geometry covers the other, else FalseZprepared_covers)r   r   )r
   r   r   r   r   Úcovers4   s    zPreparedGeometry.coversc             C   s   t | jd | |ƒƒS )z0Returns True if the geometries cross, else FalseZprepared_crosses)r   r   )r
   r   r   r   r   Úcrosses9   s    zPreparedGeometry.crossesc             C   s   t | jd | |ƒƒS )z3Returns True if geometries are disjoint, else FalseZprepared_disjoint)r   r   )r
   r   r   r   r   Údisjoint>   s    zPreparedGeometry.disjointc             C   s   t | jd | |ƒƒS )z0Returns True if geometries intersect, else FalseZprepared_intersects)r   r   )r
   r   r   r   r   Ú
intersectsC   s    zPreparedGeometry.intersectsc             C   s   t | jd | |ƒƒS )z.Returns True if geometries overlap, else FalseZprepared_overlaps)r   r   )r
   r   r   r   r   ÚoverlapsH   s    zPreparedGeometry.overlapsc             C   s   t | jd | |ƒƒS )z,Returns True if geometries touch, else FalseZprepared_touches)r   r   )r
   r   r   r   r   ÚtouchesM   s    zPreparedGeometry.touchesc             C   s   t | jd | |ƒƒS )z8Returns True if geometry is within the other, else FalseZprepared_within)r   r   )r
   r   r   r   r   ÚwithinR   s    zPreparedGeometry.withinc             C   s   t dƒ‚d S )Nz&Prepared geometries cannot be pickled.)r   )r
   r   r   r   Ú
__reduce__W   s    zPreparedGeometry.__reduce__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Úpropertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
   s   	r   c             C   s   t | ƒS )z0Creates and returns a prepared geometric object.)r   )Úobr   r   r   ÚprepZ   s    r#   N)r    Zshapely.geosr   Zshapely.implr   r   Úpickler   Úobjectr   r#   r   r   r   r   Ú<module>   s
   P