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ZddlZddlm	Z	m
Z
mZ ddlmZmZ ddlmZ ejddejd	d
dejdde
jddejdddejejejejddddejddddejddddejdd
dde
jejedd ZdS ) zfio-dump    )partialN)helpersoptionswith_context_env)FeatureObjectEncoder)transform_geomzDump a dataset to GeoJSON.)
short_helpinputT)requiredz--layerz
INDEX|NAMEzPrint information about a specific layer.  The first layer is used by default.  Layers use zero-based numbering when accessed by index.)metavarcallbackhelpz
--encodingz#Specify encoding of the input file.)r   z&--record-buffered/--no-record-bufferedFzJEconomical buffering of writes at record, not collection (default), level.)defaultr   z"--ignore-errors/--no-ignore-errorsz)log errors but do not stop serialization.z&--with-ld-context/--without-ld-contextz%add a JSON-LD context to JSON output.z--add-ld-context-itemz?map a term to a URI and add it to the output's JSON LD context.)multipler   c                    s  t t}td}ddi}|r(||d< |r4d|d< |r<dp>d}|rL||d	< |
rX|
|d
<  fddtj|fi |j}tj	d 
 |d< |rt|}ddd|pd   }d|d |d g d}|rt|	|d< tj|fi |d\}}|| |d t}z^dt| }}|}|r@t|}|rP|| |tj|fdti|d| W n ty   Y np ty } zV|r|d|| n4|d|| |d || |r|d  W Y d}~n
d}~0 0 t|dD ]\}}|}zR|r&t|}|r6|| || |tj|fdti|d| W np ty } zV|r|d|| n4|d|| |d || |r|d  W Y d}~n
d}~0 0 q|d || |rv|d ntd|d |d  d }|rFt|	|d< fd!d"D |d#< nfd$d"D |d#< tj||fdti| W d   n1 s0    Y  dS )%zjDump a dataset either as a GeoJSON feature collection (the default)
    or a sequence of GeoJSON features.stdout	sort_keysTindent),:
separatorsr   z, encodinglayerc                    s*   t t| dd d}t|j|j||jdS )Nz	EPSG:4326T)Zantimeridian_cutting	precision)id
propertiesgeometry)r   r   r   r   r   r   )crsZfeattg)r    J/var/www/html/django/DPS/env/lib/python3.9/site-packages/fiona/fio/dump.pytransformerH   s    zdump.<locals>.transformerr   fields
    r   ZFeatureCollectionschemar   )typefiona:schema	fiona:crsfeaturesz@contextz[][clsz3failed to serialize file record %d (%s), continuingz0failed to serialize file record %d (%s), quiting]N   )r'   r(   r)   c                    s   g | ]}t  |qS r   )r   	id_record.0rec)r!   r   r    
<listcomp>   s   zdump.<locals>.<listcomp>r*   c                    s   g | ]} j |qS r   )r   r0   )sourcer!   r   r    r3      s   )logging	getLogger__name__clickget_text_streamfionaopenmetadictr&   itemsboolr   Zmake_ld_contextjsondumpssplitwriteiternextr/   r   replaceStopIteration	Exceptionerrorcritical	enumerate	to_stringdump)ctxr
   r   r   r   compactZrecord_bufferedignore_errorsZwith_ld_contextZadd_ld_context_itemr   Zopen_optionsloggerZsinkZ	dump_kwdsZitem_sepr<   ZindentedZ
rec_indent
collectionheadtailitrifirstexcr2   r   )r   r4   r!   r    rM      s    )



















rM   )__doc__	functoolsr   r@   r5   r8   Zcligjr:   Z	fiona.fior   r   r   Zfiona.modelr   r   Zfiona.transformr   commandargumentoptionZcb_layerZprecision_optZ
indent_optZcompact_optZopen_optpass_contextrM   r   r   r   r    <module>   sD   
