
    !\i                     T    S r SSKJr  SSKrSSKrSSKrS rS
S jrS rS r	S r
S	 rg)z!Feature parsing and normalization    )chainNc              #   0  #    U=(       d    S HA  n [         R                  " USS9 n[        [        U5      5       H  nUv   M	     SSS5        MC     g! , (       d  f       MU  = f! [         a#    [        [        U5      5      nS0 SUS.S.v    M  f = f7f)	ah  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FeaturePoint)typecoordinatesr	   
propertiesgeometry)click	open_fileiter_featuresiterIOErrorlistcoords_from_query)ctxparamvaluefeature_likesrcfeaturecoordss          Q/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/cligj/features.pynormalize_feature_inputsr   
   s     2 	,@C,T#Y7G!M  8 A@ (@@  	,+L9:F! ##)+, ,	,sK   BA& AA&B
A#	A&!B#A&&)BBBBc              #   4  #    U=(       d    S n[        U 5      nUR                  S5      (       a  UR                  S5      nU  Hq  nUR                  S5      (       aT  U(       a:  [        R                  " U5      nSU;   a  [        U5      nU" U5      nU(       a  Uv   UR                  S5      nMm  X4-  nMs     [        R                  " U5      nSU;   a  [        U5      nU" U5      nU(       a  Uv   g	g	 [        R                  " U5      nUS   S:X  aF  U" U5      nU(       a  Uv   U  H,  nU" [        R                  " U5      5      nU(       d  M(  Uv   M.     g	US   S:X  a"  US    H  nU" U5      nU(       d  M  Uv   M     g	SU;   aX  U" [        U5      5      nU(       a  Uv   U  H5  nU" [        [        R                  " U5      5      5      nU(       d  M1  Uv   M7     g	g	! [         a    SR                  [        U/U 5      5      n[        R                  " U5      nUS   S:X  a  U" U5      nU(       a  Uv    g	 g	US   S:X  a#  US    H  nU" U5      nU(       d  M  Uv   M      g	SU;   a   U" [        U5      5      nU(       a  Uv    g	 g	 g	f = f7f)
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                     U $ N )xs    r   <lambda>iter_features.<locals>.<lambda>I   s    a    r
   r	   r   FeatureCollectionfeatures N)	next
startswithstripjsonloads
to_feature
ValueErrorjoinr   )	geojsonfilefunc
first_linetext_bufferlineobjnewfeatfeattexts	            r   r   r   2   s^    .  KDk"J W%% &&w/Dw''**[1C$+(o"3iG%"jj1#   **[)C# o3iG ,	"**Z(C6{i's)!M'D"4::d#34Gw% ( V 33
OD"4jGw% , #%z#/!M'D":djj.>#?@Gw% (	 &  	"775*{;<D**T"C6{i's)!M V 33
OD"4jGw% , #%z#/!M  &	"su   C2J5AG$ G$ JG$ <G$ JAG$ G$ "J$AJ<J J"J*J,"JJJJc                 F    U S   S:X  a  U $ SU ;   a  S0 U S.$ [        S5      e)zConverts 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 geometry)r0   )r7   s    r   r/   r/      s>      6{i
	#	 	
 >??r%   c                 x     [         R                  " U 5      R                  5       nU$ ! [         a    U /n U$ f = f)zRAccept a filename, stream, or string.
Returns an iterator over lines of the query.)r   r   	readlinesr   )queryitrs     r   
iter_queryr@      sB    ooe$..0 J  gJs   $( 99c                      [         R                  " U 5      n[        USS 5      $ ! [         aF    U R                  SS5      n U R	                  5       nU Vs/ s H  n[        U5      PM     Os  snf nn N]f = f)z=Transform a query line into a (lng, lat) pair of coordinates., N   )r-   r.   r0   replacesplitfloattuple)r>   r   valsvs       r   r   r      sq    *E"
 	  *c3'{{}$()Dq%(D))*s   & 0A6A,+A65A6c              #   (  #    U  H  n[        US5      (       aA  SUR                  R                  5       ;   a#  UR                  S   S:X  a  UR                  v   MU  [        U[        5      (       a  SU;   a  US   S:X  a  Uv   M  [        S5      e   g7f)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)hasattrrL   keys
isinstancedictr0   )feature_objsr7   s     r   normalize_feature_objectsrR      s      C,--#//4466%%f-:'''T""v}V	9QIJKK s   BBr    )__doc__	itertoolsr   r-   rer   r   r   r/   r@   r   rR   r!   r%   r   <module>rV      s7    '   	 %,Pc"L@6Lr%   