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lmZmZ ddl	m
Z
 ed dddZd	d
 Zdd Zdd Zdd Zdd ZdS )z1Helper objects needed by multiple CLI commands.

    )partialN)Geometryto_dict)munchifydefaultc                    s:   t   dr$ fdd}n fdd}| S )z9Return a generator of JSON objects loaded from ``lines``.c                  3   sZ     d} D ]6}|dr<| r0tj| dV  | d} q| |7 } qtj| dV  d S )Nr   object_hook)strip
startswithjsonloads)bufferline
first_linelinesr	    M/var/www/html/django/DPS/env/lib/python3.9/site-packages/fiona/fio/helpers.pygen   s    


zobj_gen.<locals>.genc                  3   s.   t j dV  D ]} t j| dV  qd S )Nr   )r   r   )r   r   r   r   r   $   s    )nextr   )r   r	   r   r   r   r   obj_gen   s
    
r   c                 C   s   | d u rd S || S d S )Nr   )valcastr   r   r   nullable,   s    r   c                 C   s   dt t| i}|ttttttt	t
tt	t
tt	t
tt	t
td
 zddlm} ||d< W n tyr   Y n0 t|dd i|S )Nf)
sumpowminmaxmathboolintstrfloatlenr   )shaper&   __builtins__)r   r   updater   r   r   r   r    r!   r   r   r"   r#   r$   r%   Zshapely.geometryr&   ImportErroreval)feature
expressionZ	safe_dictr&   r   r   r   eval_feature_expression3   s(    r-   c                 C   st   ddddddddd	d
dddddddddddddddddddi}| pJg D ]"}| d\}}| || < qL|S )zTReturns a JSON-LD Context object.

    See https://json-ld.org/spec/latest/json-ld/.z@contextzhttp://ld.geojson.org/vocab#zgeojson:Featurezgeojson:FeatureCollectionzgeojson:GeometryCollectionzgeojson:LineStringzgeojson:MultiLineStringzgeojson:MultiPointzgeojson:MultiPolygonzgeojson:Pointzgeojson:Polygonz@listzgeojson:bbox)z
@container@idzgeojson:coordinatesz)http://www.w3.org/2006/time#inXSDDateTimez$http://purl.org/dc/terms/descriptionz@setzgeojson:featureszgeojson:geometryr.   zgeojson:propertiesz(http://www.w3.org/2006/time#hasBeginningz%http://www.w3.org/2006/time#hasEndingzhttp://purl.org/dc/terms/titlez@typezgeojson:when)ZgeojsonZFeatureZFeatureCollectionZGeometryCollectionZ
LineStringZMultiLineStringZ
MultiPointZMultiPolygonZPointZPolygonZbboxcoordinatesdatetimedescriptionfeaturesZgeometryid
propertiesstartstoptitletypewhen=)splitr
   )Zcontext_itemsctxitemturir   r   r   make_ld_contextL   s<    r@   c                 C   s   d| d  | d< | S )zAConverts a record's id to a blank node id and returns the record.z_:f%sr3   r   )Zrecr   r   r   	id_recordq   s    rA   c                    s    dk r| S t | ddr2t fdd| jD dS t | ddrXt fdd| jD d	S t| ttfrpt|  S  fd
d| D S dS )zRecursively round coordinates.r   
geometriesNc                    s   g | ]}t | qS r   recursive_round.0part	precisionr   r   
<listcomp>}       z#recursive_round.<locals>.<listcomp>)rB   r/   c                    s   g | ]}t | qS r   rC   rE   rH   r   r   rJ      rK   )r/   c                    s   g | ]}t | qS r   rC   rE   rH   r   r   rJ      rK   )getattrr   rB   r/   
isinstancer"   r$   round)objrI   r   rH   r   rD   w   s    
rD   )N)__doc__	functoolsr   r   r    warningsZfiona.modelr   r   Zfiona._vendor.munchr   simplefilterr   r   r-   r@   rA   rD   r   r   r   r   <module>   s   

%