
    Eh)              	           S r SSKrSSKrSSKJr  SSKJr  SSKJ	r	J
r
JrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SrSrSr\S\S\SS\R0                  S4	S jrS rS r\4S jrg)zTools to plot basemaps    N   )	providers)TileProvider)
bounds2img_sm2ll
warp_tiles_warper)
Resamplingtransform_bounds)patheffects)drawbilinearauto   Tc
                    U R                  5       u  pp[        U[        5      (       a   [        R                  " U5      nUb9  [        U[        [        45      (       d  [        U[        5      (       ak  USS S:X  ab  XX4u  nnnnUb  [        UUUUUS5      u  nnnn[        UUUUUUSU	S9u  nnUb  [        UUXxS9u  nn[        U5      (       a  SU
;  a  S	U
S'   GO|S
SKnUR                  U5       nU(       al  S
SKJn  U(       a.  UR                   R#                  UUR$                  XX5      u  nnnnO	XX4u  nnnnSUU4UU4UU4UU4UU444S./nU" UUSS9u  nnUUUU4nO{[&        R(                  " UR+                  5        Vs/ s H  nUPM     sn5      nUR,                  nUR.                  nUR0                  UR2                  UR4                  UR6                  4nUbZ  UR$                  U:w  aJ  [9        UUUR$                  Xx5      u  nnnUR0                  UR2                  UR4                  UR6                  4nUR;                  SSS
5      nSSS5        WR<                  S   S:X  a  USS2SS2S
4   nU R>                  " U4WUU RA                  5       S.U
D6nU(       a  U R                  XX45        OK[C        UUS
   5      [E        UUS   5      [C        UUS   5      [E        UUS   5      4nU R                  U5        Uc  [        RF                  RH                  n[        U[        [        45      (       a  Uc  URK                  S5      nU(       a
  [M        XUS9  g! [
         a     GN/f = fs  snf ! , (       d  f       GN-= f)a  
Add a (web/local) basemap to `ax`.

Parameters
----------
ax : AxesSubplot
    Matplotlib axes object on which to add the basemap. The extent of the
    axes is assumed to be in Spherical Mercator (EPSG:3857), unless the `crs`
    keyword is specified.
zoom : int or 'auto'
    [Optional. Default='auto'] Level of detail for the basemap. If 'auto',
    it is calculated automatically. Ignored if `source` is a local file.
source : xyzservices.TileProvider object or str
    [Optional. Default: OpenStreetMap Humanitarian web tiles]
    The tile source: web tile provider, a valid input for a query of a
    :class:`xyzservices.TileProvider` by a name from ``xyzservices.providers`` or
    path to local file. The web tile provider can be in the form of a
    :class:`xyzservices.TileProvider` object or a URL. The placeholders for the XYZ
    in the URL need to be `{x}`, `{y}`, `{z}`, respectively. For local file paths,
    the file is read with `rasterio` and all bands are loaded into the basemap.
    IMPORTANT: tiles are assumed to be in the Spherical Mercator projection
    (EPSG:3857), unless the `crs` keyword is specified.
interpolation : str
    [Optional. Default='bilinear'] Interpolation algorithm to be passed
    to `imshow`. See `matplotlib.pyplot.imshow` for further details.
attribution : str
    [Optional. Defaults to attribution specified by the source]
    Text to be added at the bottom of the axis. This
    defaults to the attribution of the provider specified
    in `source` if available. Specify False to not
    automatically add an attribution, or a string to pass
    a custom attribution.
attribution_size : int
    [Optional. Defaults to `ATTRIBUTION_SIZE`].
    Font size to render attribution text with.
reset_extent : bool
    [Optional. Default=True] If True, the extent of the
    basemap added is reset to the original extent (xlim,
    ylim) of `ax`
crs : None or str or CRS
    [Optional. Default=None] coordinate reference system (CRS),
    expressed in any format permitted by rasterio, to use for the
    resulting basemap. If None (default), no warping is performed
    and the original Spherical Mercator (EPSG:3857) is used.
resampling : <enum 'Resampling'>
    [Optional. Default=Resampling.bilinear] Resampling
    method for executing warping, expressed as a
    `rasterio.enums.Resampling` method
zoom_adjust : int or None
    [Optional. Default: None]
    The amount to adjust a chosen zoom level if it is chosen automatically.
    Values outside of -1 to 1 are not recommended as they can lead to slow execution.
**extra_imshow_args :
    Other parameters to be passed to `imshow`.

Examples
--------

>>> import geopandas
>>> import contextily as cx
>>> db = geopandas.read_file(ps.examples.get_path('virginia.shp'))

Ensure the data is in Spherical Mercator:

>>> db = db.to_crs(epsg=3857)

Add a web basemap:

>>> ax = db.plot(alpha=0.5, color='k', figsize=(6, 6))
>>> cx.add_basemap(ax, source=url)
>>> plt.show()

Or download a basemap to a local file and then plot it:

>>> source = 'virginia.tiff'
>>> _ = cx.bounds2raster(*db.total_bounds, zoom=6, source=source)
>>> ax = db.plot(alpha=0.5, color='k', figsize=(6, 6))
>>> cx.add_basemap(ax, source=source)
>>> plt.show()

N   httpz	epsg:3857F)zoomsourcellzoom_adjust)t_crs
resamplingzorder	   r   )maskPolygon)typecoordinatesT)cropr      )extentinterpolationaspect   attribution)	font_size)'axis
isinstancestrr   
query_name
ValueErrordictr   
_reproj_bbr   r   _is_overlayrasterioopenrasterio.maskr   warpr   crsnparrayread	transformboundsleftrightbottomtopr	   	transposeshapeimshow
get_aspectminmaxOpenStreetMapHOTgetadd_attribution)axr   r   r$   r'   attribution_sizereset_extentr5   r   r   extra_imshow_argsxminxmaxyminymaxr;   r<   r=   r>   imager#   riorasterriomaskwindowimg_transformbandbbr:   _
max_boundss                                  fC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\contextily/plotting.pyadd_basemapr\      s   |  WWYD&#	))&1F 	ft\233vs##r
f(< $(t#9 eVS?'1eVS#{($D% ##	
v ?&ufCWME6v83D#D*+h' 	 XXf9 /2xx/H/HVZZT0,D&% 044/E,D&% !* "&v!&!&!%s!%v( (/vvD'I$}ufc1 6;;=!A=4$=!AB & 0 0]]"((BIIrvv=fjjC&7#*=&**c$ vq  fllFMM6::MOOAq!,EO T {{1~aAg
			#}}		
 	A 
T() fQi fQi fQi fQi 	

 	
 ~((,,&4.//K4Gjj/3CD
]  		H "B; s1   M" 3BM8	M3
B=M8"
M0/M03M88
Nc                 *    [        XEXX5      u  pgpXhXy4$ Nr   )
r;   r<   r=   r>   s_crsr   n_ln_bn_rn_ts
             r[   r/   r/      s     )%eQCcS    c           	          [        U [        5      (       d  gU R                  SS5      S:  a  g/ SQnSSKn[	        UR                  SS	R                  U5      -   S
-   U R                  SS5      5      5      $ )a  
Check if the identified source is an overlay (partially transparent) layer.

Parameters
----------
source : dict
    The tile source: web tile provider.  Must be preprocessed as
    into a dictionary, not just a string.

Returns
-------
bool

Notes
-----
This function is based on a very similar javascript version found in leaflet:
https://github.com/leaflet-extras/leaflet-providers/blob/9eb968f8442ea492626c9c8f0dac8ede484e6905/preview/preview.js#L56-L70
Fopacityg      ?T)
z^(OpenWeatherMap|OpenSeaMap)zHOpenMapSurfer.(Hybrid|AdminBounds|ContourLines|Hillshade|ElementsAtRisk)z!Stamen.Toner(Hybrid|Lines|Labels)z/CartoDB.(Positron|DarkMatter|Voyager)OnlyLabelszHydda.RoadsAndLabelsz^JusticeMap	OpenPtMapOpenRailwayMapOpenFireMapSafeCastr   N(|)name )r*   r.   rG   reboolmatchjoin)r   overlayPatternsrp   s      r[   r0   r0      sk    & fd##zz)S!C'O sxx883>

6SU@VWXXrd   c           
         ^ [        5         U R                  " SSU4U R                  U[        R                  " SSS9/SS.UD6nU R                  5       R                  S-  mU4S jUl        U$ )	a  
Utility to add attribution text.

Parameters
----------
ax : AxesSubplot
    Matplotlib axes object on which to add the attribution text.
text : str
    Text to be added at the bottom of the axis.
font_size : int
    [Optional. Defaults to 8] Font size in which to render
    the attribution text.
**kwargs : Additional keywords to pass to the matplotlib `text` method.

Returns
-------
matplotlib.text.Text
                      Matplotlib Text object added to the plot.
g{Gzt?r"   w)	linewidth
foregroundT)r9   sizepath_effectswrapgGz?c                     > T $ r^    )
wrap_widths   r[   <lambda>!add_attribution.<locals>.<lambda>9  s    zrd   )r   text	transAxesr   
withStrokeget_window_extentwidth_get_wrap_line_width)rI   r   r(   kwargstext_artistr~   s        @r[   rH   rH     s{    . 	F''	 ,,!,,qSIJ	 	K %%'--4J'9K$rd   )__doc__warningsnumpyr6   ro   r   xyzservicesr   tiler   r   r   r	   rasterio.enumsr
   rasterio.warpr   
matplotlibr   matplotlib.pyplotr   INTERPOLATIONZOOMATTRIBUTION_SIZEr   r\   r/   r0   rH   r}   rd   r[   <module>r      sv        $ 9 9 % * " " 
 
%""Qh
%YP )9 'rd   