3
®?d]½  ã               @   sœ   d 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
mZ ddlmZ dd	gZG d
d„ de
ƒZG dd„ deeƒZdd	„ Zddd„Zdd„ ZdS )zPoints and related utilities
é    )Úc_double)ÚcastÚPOINTER)ÚDimensionError)Úlgeos)ÚBaseGeometryÚgeos_geom_from_py)ÚCachingGeometryProxyÚPointÚasPointc               @   sš   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	ddd„Z
edd„ ƒZdd„ ZeeƒZedd„ ƒZdd„ ZeejeƒZedd„ ƒZdS )r
   aN  
    A zero dimensional feature

    A point has zero length and zero area.

    Attributes
    ----------
    x, y, z : float
        Coordinate values

    Example
    -------
      >>> p = Point(1.0, -1.0)
      >>> print(p)
      POINT (1.0000000000000000 -1.0000000000000000)
      >>> p.y
      -1.0
      >>> p.x
      1.0
    c             G   s$   t j| ƒ t|ƒdkr | j|Ž  dS )zî
        Parameters
        ----------
        There are 2 cases:

        1) 1 parameter: this must satisfy the numpy array protocol.
        2) 2 or more parameters: x, y, z : float
            Easting, northing, and elevation.
        r   N)r   Ú__init__ÚlenÚ_set_coords)ÚselfÚargs© r   ú9/tmp/pip-build-op5p2y5_/shapely/shapely/geometry/point.pyr   %   s    

zPoint.__init__c             C   s   | j d d S )zReturn x coordinate.r   )Úcoords)r   r   r   r   Úx5   s    zPoint.xc             C   s   | j d d S )zReturn y coordinate.r   é   )r   )r   r   r   r   Úy:   s    zPoint.yc             C   s    | j dkrtdƒ‚| jd d S )zReturn z coordinate.é   zThis point has no z coordinate.r   é   )Ú_ndimr   r   )r   r   r   r   Úz?   s    
zPoint.zc             C   s   d| j d dœS )Nr
   r   )ÚtypeZcoordinates)r   )r   r   r   r   Ú__geo_interface__F   s    zPoint.__geo_interface__ç      ð?Nc             C   s8   | j r
dS |dkr | jrdnd}dj| d| d| |ƒS )ao  Returns SVG circle element for the Point geometry.

        Parameters
        ==========
        scale_factor : float
            Multiplication factor for the SVG circle diameter.  Default is 1.
        fill_color : str, optional
            Hex string for fill color. Default is to use "#66cc99" if
            geometry is valid, and "#ff3333" if invalid.
        z<g />Nz#66cc99z#ff3333ze<circle cx="{0.x}" cy="{0.y}" r="{1}" stroke="#555555" stroke-width="{2}" fill="{3}" opacity="0.6" />g      @g      ð?)Úis_emptyZis_validÚformat)r   Zscale_factorZ
fill_colorr   r   r   ÚsvgM   s    z	Point.svgc             C   sZ   | j sTt| j }|ƒ }| jd }|d |d< |d |d< | jdkrN|d |d< || _ | j S )Nr   r   r   r   )Z_ctypes_datar   r   r   )r   Z
array_typeÚarrayÚxyr   r   r   Úctypesa   s    


zPoint.ctypesc             C   s8   | j rdddtd ƒ dœ}n| j}|jd| jfiƒ |S )z!Provide the Numpy array protocol.r   z<f8r   )ÚversionZtypestrÚshapeÚdatar%   )r   )r   r   Zarray_interface_baseÚupdater   )r   Zair   r   r   Úarray_interfacen   s
    zPoint.array_interfacec             C   s&   | j d }|d |d |d |d fS )Nr   r   )r   )r   r"   r   r   r   Úboundsx   s    
zPoint.boundsc             G   sB   | j ƒ  t|ƒdkr*t|d ƒ\| _| _ntt|ƒƒ\| _| _d S )Nr   r   )Úemptyr   Úgeos_point_from_pyÚ_geomr   Útuple)r   r   r   r   r   r      s    zPoint._set_coordsc             C   s   | j jS )z·Separate arrays of X and Y coordinate values

        Example:
          >>> x, y = Point(0, 0).xy
          >>> list(x)
          [0.0]
          >>> list(y)
          [0.0]
        )r   r"   )r   r   r   r   r"   ˆ   s    zPoint.xy)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r    r#   r(   Ú__array_interface__r)   r   r   Ú_get_coordsr   r"   r   r   r   r   r
      s   
c               @   sF   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZej	Z	dd	„ Z
ee	ƒZd
S )ÚPointAdapterFc             C   s   || _ t| _d S )N)Úcontextr+   Úfactory)r   r6   r   r   r   r   š   s    zPointAdapter.__init__c             C   sL   y,| j j}|d d }|dks*|dks*t‚|S  tk
rF   t| j ƒS X d S )Nr%   r   r   r   )r6   r3   ÚAssertionErrorÚAttributeErrorr   )r   r!   Únr   r   r   r   ž   s    zPointAdapter._ndimc             C   s&   y| j jS  tk
r    | jƒ S X dS )z!Provide the Numpy array protocol.N)r6   r3   r9   r(   )r   r   r   r   r3   ª   s    z PointAdapter.__array_interface__c             C   s   t dƒ‚d S )Nz%Adapters can not modify their sources)ÚNotImplementedError)r   Úobr   r   r   r   ´   s    zPointAdapter._set_coordsN)r.   r/   r0   Z_other_ownedr   r2   r   r3   r   r4   r   r   r   r   r   r   r5   –   s   r5   c             C   s   t | ƒS )z&Adapt an object to the Point interface)r5   )r6   r   r   r   r   º   s    Nc       	      C   sô   t | tƒrt| ƒS t| dƒs$t| ƒ} t | d tƒr<| d }n| }t|ƒ}t|d ƒ}t|d ƒ}d}|dkrxt|d ƒ}|rœtj	|ƒ}||kr¨t
d| ƒ‚ntjd|ƒ}tj|d|ƒ tj|d|ƒ |dkrÚtj|d|ƒ |râdS tj|ƒ|fS dS )z¸Create a GEOS geom from an object that is a Point, a coordinate sequence
    or that provides the array interface.

    Returns the GEOS geometry and the number of its dimensions.
    Ú__getitem__r   r   Nr   r   z=Wrong coordinate dimensions; this geometry has dimensions: %d)Ú
isinstancer
   r   ÚhasattrÚlistr-   r   r   r   ZGEOSGeom_getCoordSeqÚ
ValueErrorZGEOSCoordSeq_createZGEOSCoordSeq_setXZGEOSCoordSeq_setYZGEOSCoordSeq_setZZGEOSGeom_createPoint)	r<   Zupdate_geomZupdate_ndimr   r:   ZdxZdyZdzÚcsr   r   r   r+   ¿   s6    




r+   c             C   s   t || j| jƒ d S )N)r+   r,   r   )Zgeomr<   r   r   r   Úupdate_point_from_pyì   s    rC   )Nr   )r1   r#   r   r   r   Zshapely.errorsr   Zshapely.geosr   Zshapely.geometry.baser   r   Zshapely.geometry.proxyr	   Ú__all__r
   r5   r   r+   rC   r   r   r   r   Ú<module>   s    $
-