o
    ›¨Êhô  ã                   @   sD   d dl mZ d dlmZ dd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )é    )ÚWGS_84_SRID)ÚSpatialErrorc                 C   s   t | dƒstd|  ƒ‚| S )zP
    Makes sure the parameter passed in looks like a GEOS ``GEOSGeometry``.
    Ú	geom_typez0Point '%s' doesn't appear to be a GEOS geometry.)Úhasattrr   ©Úgeom© r   úD/var/www/html/env/lib/python3.10/site-packages/haystack/utils/geo.pyÚensure_geometry   s   
r
   c                 C   s"   t | ƒ | jdkrtd|  ƒ‚| S )zI
    Makes sure the parameter passed in looks like a GEOS ``Point``.
    ÚPointz(Provided geometry '%s' is not a 'Point'.)r
   r   r   r   r   r   r	   Úensure_point   s   
r   c                 C   s8   t | ƒ |  ¡ }|jst|_|S |jtkr| t¡ |S )z}
    Ensures the point passed in is a GEOS ``Point`` & returns that point's
    data is in the WGS-84 spatial reference.
    )r   ÚcloneÚsridr   Ú	transform)ÚpointÚ	new_pointr   r   r	   Úensure_wgs84   s   
ü
r   c                 C   s(   z| j  W | S  ty   td|  ƒ‚w )zD
    Makes sure the parameter passed in is a 'Distance' object.
    z/'%s' does not appear to be a 'Distance' object.)ÚkmÚAttributeErrorr   )Údistr   r   r	   Úensure_distance/   s   ýÿr   c                 C   s:   | j \}}|j \}}t||ƒt||ƒ}}||f||ffS )zä
    Takes two opposite corners of a bounding box (order matters!) & generates
    a two-tuple of the correct coordinates for the bounding box.

    The two-tuple is in the form ``((min_lat, min_lng), (max_lat, max_lng))``.
    )ÚcoordsÚminÚmax)Úbottom_leftÚ	top_rightÚwestÚlat_1ÚeastÚlat_2Úmin_latÚmax_latr   r   r	   Úgenerate_bounding_box=   s   

r"   N)	Úhaystack.constantsr   Úhaystack.exceptionsr   r
   r   r   r   r"   r   r   r   r	   Ú<module>   s    
