U
    /e                     @  sb   d Z ddlmZ ddlZeeZddlZddlm	  m
Z ddlmZmZ dZdd Ze ZdS )	ay   This modules exposes geometry data for Unites States.

This module contains one dict: ``data``.

The data is indexed by two-tuples of `` (state_id, county_id)`` that
have the following dictionaries as values:

.. code-block:: ipython

    In [25]: data[(1,1)]
    Out[25]:
    {
        'name': 'Autauga',
        'detailed name': 'Autauga County, Alabama',
        'state': 'al',
        'lats': [32.4757, ..., 32.48112],
        'lons': [-86.41182, ..., -86.41187]
    }

Entries for ``'name'`` can have duplicates for certain states (e.g. Virginia).
The combination of ``'detailed name'`` and ``'state'`` will always be unique.

    )annotationsN   )external_pathopen_csv)datac                  C  s  t d} i }ttd}t| tj|ddd}|D ]}|\}}}}}}}}}	}
}}}t|}g }g }t|	dD ]f\}}|dkr|
|  |
|  dd	 |j D }ttd
d |D  \}}|| || qx||	|||d|t|
t|f< q6W 5 Q R X |S )z

    NaNzUS_Counties.csv,")	delimiter	quotecharz).//outerBoundaryIs/LinearRing/coordinatesr   c                 s  s    | ]}| d dd V  qdS )r   Nr   )split).0c r   @/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/sampledata/us_counties.py	<genexpr>Y   s     z_read_data.<locals>.<genexpr>c                 S  s    g | ]\}}t |t |fqS r   )float)r   lonlatr   r   r   
<listcomp>Z   s     z_read_data.<locals>.<listcomp>)namezdetailed namestatelatslons)r   r   r   nextcsvreaderet
fromstring	enumeratefindallappendtextr   listzipextendint)nanr   fr   rowr   dummyr   ZgeometryZdet_nameZstate_idZ	county_idxmlr   r   iZpolyZcoordsr   r   r   r   r   
_read_dataE   s6    




"r-   )__doc__
__future__r   logging	getLogger__name__logr   xml.etree.ElementTreeetreeElementTreer   Zutil.sampledatar   r   __all__r-   r   r   r   r   r   <module>   s   
'