o
    pfa                     @   sH   d dl Z d dlZd dlmZ d dlmZ G dd dZG dd dZdS )    N)
Definition)Tilec                   @   s0   e Zd Zdd ZdefddZdefddZd	S )
Configc                 C   s   t |}|d d | _|d d| _|d d| _|d d| _|d d| _|d d| _|d d| _	g | _
|d	i  D ]\}}| j
t||| qGd
| _d
| _| j
rwtdd | j
D | _tdd | j
D | _d
S d
S )zCreate a config from a yaml string
           Creates a config from the yaml string. Any SQL files referenced must be in the
           filesystem.
        metadataidnamedescriptionattributionversionboundscentervector_layersNc                 S      g | ]}|j qS  minzoom.0layerr   r   H/home/ertert/spirit/venv/lib/python3.10/site-packages/tilekiln/config.py
<listcomp>       z#Config.__init__.<locals>.<listcomp>c                 S   r   r   maxzoomr   r   r   r   r       r   )yaml	safe_loadr   getr   r   r	   r
   r   r   layersitemsappendLayerConfigr   r   minmax)selfyaml_string
filesystemconfigr   lr   r   r   __init__	   s"   
zConfig.__init__returnc                 C   sz   d| d| j  d g| j| j| j| j| j| j| jdd
}dd | jD }dd |D |d	< t	j
d
d | D dddS )zReturns a TileJSONz3.0.0/z/{z}/{x}/{y}.mvtxyz)
tilejsontilesr	   r   r   r   r   r   r   schemec                 S   s&   g | ]}|j |j|j|j|jd qS )r   fieldsr   r   r   r/   r   r   r   r   r   0   s    
z#Config.tilejson.<locals>.<listcomp>c                 S   s   g | ]}d d |  D qS )c                 S      i | ]\}}|d ur||qS Nr   r   kvr   r   r   
<dictcomp>5       z.Config.tilejson.<locals>.<listcomp>.<dictcomp>)r   r   r   r   r   r   5   s    r   c                 S   r1   r2   r   r3   r   r   r   r6   8   r7   z#Config.tilejson.<locals>.<dictcomp>T   )	sort_keysindent)r   r	   r   r   r   r   r   r   r   jsondumpsr   )r#   urlresultr   r   r   r   r,   "   s(   
zConfig.tilejsontilec                    s    fdd| j D S )Nc                    s$   h | ]}|  d ur|  qS r2   )
render_sqlr   r?   r   r   	<setcomp><   s    z'Config.layer_queries.<locals>.<setcomp>)r   )r#   r?   r   rA   r   layer_queries;   s   zConfig.layer_queriesN)__name__
__module____qualname__r(   strr,   r   rC   r   r   r   r   r      s    r   c                   @   s   e Zd Zdd Zdd ZdS )r    c                 C   s   || _ |d| _|di | _g | _t|dg | _t | _|dg D ]}| jt	||| q&t
dd | jD | _tdd | jD | _dS )	zCreate a layer config
           Creates a layer config from the config yaml for a layer. Any SQL files referenced must
           be in the filesystem.
        r   r0   geometry_typesqlc                 S      h | ]}|j qS r   r   r   dr   r   r   rB   P   r   z'LayerConfig.__init__.<locals>.<setcomp>c                 S   rJ   r   r   rK   r   r   r   rB   Q   r   N)r   r   r   r0   definitionssetrH   _LayerConfig__definitionsaddr   r!   r   r"   r   )r#   r   
layer_yamlr%   
definitionr   r   r   r(   A   s   zLayerConfig.__init__c                 C   sR   |j | jks|j | jk rdS | jD ]}|j |jkr&|j |jkr&||  S qdS )zyReturns the SQL for a layer, given a tile, or None if it is outside the zoom range
           of the definitions
        N)zoomr   r   rO   r@   )r#   r?   rL   r   r   r   r@   S   s   
zLayerConfig.render_sqlN)rD   rE   rF   r(   r@   r   r   r   r   r    @   s    r    )r;   r   tilekiln.definitionr   tilekiln.tiler   r   r    r   r   r   r   <module>   s    8