a
    1$ey                     @   s   d Z ddlZddlmZ ddlmZmZ ddlmZ eedddZ	eedd	d
Z
G dd dejZG dd deZeeeef dddZdeeeeef dddZeeedddZdS )z&
Utility functions used within pyproj
    N)array)Enumauto)Any)valuereturnc                 C   s   | | kp| du S )z'
    Check if value is NaN or None
    N r   r   r   H/var/www/html/django/DPS/env/lib/python3.9/site-packages/pyproj/utils.pyis_null
   s    r   c                 C   s8   t |  } | dv rdS | dv r$dS td|  ddS )z
    https://docs.python.org/3.9/distutils/apiref.html#distutils.util.strtobool

    Here since distutils is deprecated.

    Convert a string representation of truth to True or False.
    )yyesttrueon1T)nnoffalseoff0Fzinvalid truth value: ''N)strlower
ValueErrorr	   r   r   r
   	strtobool   s    r   c                   @   s   e Zd ZdZdd ZdS )NumpyEncoderz1
    Handle numpy types when dumping to JSON
    c                 C   sp   z
|  W S  ty   Y n0 z0|jjdkr6t|W S |jjdkrLt|W S W n ty`   Y n0 tj| |S )Nr   i)	tolistAttributeErrorZdtypekindfloatintjsonJSONEncoderdefault)selfobjr   r   r
   r&   '   s    

zNumpyEncoder.defaultN)__name__
__module____qualname____doc__r&   r   r   r   r
   r   "   s   r   c                   @   s(   e Zd ZdZe Ze Ze Ze ZdS )DataTypezA
    Data type for copy to buffer and convertback operations
    N)	r)   r*   r+   r,   r   FLOATLISTTUPLEARRAYr   r   r   r
   r-   7   s
   r-   )xxxr   c                 C   s:   zt dt| ftjfW S  ty4   tddY n0 dS )a  
    Prepares scalar for PROJ C-API:
    - Makes a copy because PROJ modifies buffer in place
    - Make sure dtype is double as that is what PROJ expects
    - Makes sure object supports Python Buffer API

    Parameters
    -----------
    xxx: float or 0-d numpy array

    Returns
    -------
    tuple[Any, DataType]
        The copy of the data prepared for the PROJ API & Python Buffer API.
    dzinput must be a scalarN)r   r"   r-   r.   	Exception	TypeError)r2   r   r   r
   _copytobuffer_return_scalarB   s    r6   F)r2   inplacer   c                 C   s   t | ds&t | dr&t| jr&|  } t | drZ| jdkrBt| S | jdd| dtjfS tj}t| t	r|rx| j
dkrt	d| } n@t| trt	d| } tj}n$t| trt	d| } tj}nt| S | |fS )a  
    Prepares data for PROJ C-API:
    - Makes a copy because PROJ modifies buffer in place
    - Make sure dtype is double as that is what PROJ expects
    - Makes sure object supports Python Buffer API

    If the data is a numpy array, it ensures the data is in C order.

    Parameters
    ----------
    xxx: Any
        A scalar, list, tuple, numpy.array,
        pandas.Series, xaray.DataArray, or dask.array.Array.
    inplace: bool, default=False
        If True, will return the array without a copy if it
        meets the requirements of the Python Buffer API & PROJ C-API.

    Returns
    -------
    tuple[Any, DataType]
        The copy of the data prepared for the PROJ API & Python Buffer API.
    Zhardmask	__array__shaper   r3   C)ordercopy)hasattrcallabler8   r9   r6   Zastyper-   r1   
isinstancer   typecodelistr/   tupler0   )r2   r7   	data_typer   r   r
   _copytobufferX   s.    






rD   )rC   inxr   c                 C   s:   | t jkr|d S | t jkr$| S | t jkr6t|S |S )Nr   )r-   r.   r/   r   r0   rB   )rC   rE   r   r   r
   _convertback   s    


rF   )F)r,   r$   r   enumr   r   typingr   boolr   r   r%   r   r-   rB   r6   rD   rF   r   r   r   r
   <module>   s   9