a
    1$e                     @   s^   d Z ddlmZ ddlZddlZddlZdd ZdddZdd	 Zd
d Z	dd Z
dd ZdS )z!Feature parsing and normalization    )chainNc              	   c   s   |pdD ]}zJt j|dd(}tt|D ]
}|V  q*W d   n1 sJ0    Y  W q ty   tt|}di d|ddV  Y q0 qdS )	a  Click callback that normalizes feature input values.

    Returns a generator over features from the input value.

    Parameters
    ----------
    ctx: a Click context
    param: the name of the argument or option
    value: object
        The value argument may be one of the following:

        1. A list of paths to files containing GeoJSON feature
           collections or feature sequences.
        2. A list of string-encoded coordinate pairs of the form
           "[lng, lat]", or "lng, lat", or "lng lat".

        If no value is provided, features will be read from stdin.

    Yields
    ------
    Mapping
        A GeoJSON Feature represented by a Python mapping

    )-zutf-8)encodingNFeatureZPoint)typecoordinatesr   
propertiesZgeometry)click	open_fileiter_featuresiterIOErrorlistcoords_from_query)ctxparamvalueZfeature_likesrcfeaturecoords r   J/var/www/html/django/DPS/env/lib/python3.9/site-packages/cligj/features.pynormalize_feature_inputs
   s    *r   c           	      c   s0  |p
dd }t | }|dr|d}| D ]R}|drv|rjt|}d|v rXt|}||}|rj|V  |d}q,||7 }q,t|}d|v rt|}||}|r|V  n|zt|}|d dkr||}|r|V  | D ]}|t|}|r|V  qn|d dkr2|d D ]}||}|r|V  qnLd|v r~|t|}|rT|V  | D ]$}|tt|}|rX|V  qXW n ty*   d	t|g| }t|}|d dkr||}|r&|V  nV|d dkr|d D ]}||}|r|V  qn"d|v r&|t|}|r&|V  Y n0 d
S )a  Extract GeoJSON features from a text file object.

    Given a file-like object containing a single GeoJSON feature
    collection text or a sequence of GeoJSON features, iter_features()
    iterates over lines of the file and yields GeoJSON features.

    Parameters
    ----------
    geojsonfile: a file-like object
        The geojsonfile implements the iterator protocol and yields
        lines of JSON text.
    func: function, optional
        A function that will be applied to each extracted feature. It
        takes a feature object and may return a replacement feature or
        None -- in which case iter_features does not yield.

    Yields
    ------
    Mapping
        A GeoJSON Feature represented by a Python mapping

    c                 S   s   | S )Nr   )xr   r   r   <lambda>I       ziter_features.<locals>.<lambda>r   r   r   ZFeatureCollectionfeatures N)	next
startswithstripjsonloads
to_feature
ValueErrorjoinr   )	Zgeojsonfilefunc
first_lineZtext_bufferlineobjZnewfeatZfeattextr   r   r   r   2   sx    











r   c                 C   s0   | d dkr| S d| v r$di | dS t ddS )a  Converts an object to a GeoJSON Feature

    Returns feature verbatim or wraps geom in a feature with empty
    properties.

    Raises
    ------
    ValueError

    Returns
    -------
    Mapping
        A GeoJSON Feature represented by a Python mapping

    r   r   r   r   z#Object is not a feature or geometryN)r&   )r+   r   r   r   r%      s    r%   c                 C   s0   zt |  }W n ty*   | g}Y n0 |S )zVAccept a filename, stream, or string.
    Returns an iterator over lines of the query.)r
   r   	readlinesr   )queryitrr   r   r   
iter_query   s
    r0   c                 C   sT   zt | }W n4 tyB   | dd} |  }dd |D }Y n0 t|dd S )z=Transform a query line into a (lng, lat) pair of coordinates., c                 S   s   g | ]}t |qS r   )float).0vr   r   r   
<listcomp>   r   z%coords_from_query.<locals>.<listcomp>N   )r#   r$   r&   replacesplittuple)r.   r   valsr   r   r   r      s    r   c                 c   sl   | D ]b}t |dr8d|j v r8|jd dkr8|jV  qt|tr^d|v r^|d dkr^|V  qtdqdS )zTakes an iterable of GeoJSON-like Feature mappings or
    an iterable of objects with a geo interface and
    normalizes it to the former.__geo_interface__r   r   z+Did not recognize object as GeoJSON FeatureN)hasattrr<   keys
isinstancedictr&   )Zfeature_objsr+   r   r   r   normalize_feature_objects   s    
rA   )N)__doc__	itertoolsr   r#   rer
   r   r   r%   r0   r   rA   r   r   r   r   <module>   s   (
f
