import matplotlib.pyplot as plt
import geopandas as gpd
from pyLandUseMX.descargas import *
from pyLandUseMX.usodesuelo import *
Agregación de vialidades
En este tutorial vamos a usar el módulo
coberturas
para agregar la red vial de la CDMX en una retícula.
Importamos los que vamos a necesitar
= gpd.read_file("datos/descargas/red_zmvm.gpkg")
red # zmvm = gpd.read_file("datos/descargas/silhuetas.shp.zip")
# zmvm = zmvm.loc[zmvm.CVE_SUN == '13']
# red = red.sjoin(zmvm.to_crs(red.crs))
= [100, 101, 102, 103, 104, 105]
id_acceso_c = [106, 107]
id_primarias = 108
id_secundarias = 109
id_terciarias = 110 id_residencial
= red.loc[red.tag_id.isin(id_acceso_c)]
acceso_controlado = red.loc[red.tag_id.isin(id_primarias)]
primarias = red.loc[red.tag_id == id_secundarias]
secundarias = red.loc[red.tag_id == id_terciarias]
terciarias = red.loc[red.tag_id == id_residencial] residenciales
= {
mapas "Vialidades de acceso controlado": {
"datos":acceso_controlado,
"color": "darkred",
"peso": 1},
"Vialidades primarias": {
"datos":primarias,
"color": "tomato",
"peso": 0.8},
"Vialidades secundaris": {
"datos":secundarias,
"color": "chocolate",
"peso": 0.6},
"Vialidades terciarias": {
"datos":terciarias,
"color": "tan",
"peso": 0.5},
"Calles residenciales": {
"datos":residenciales,
"color": "black",
"peso": 0.02},
}
= plt.subplots(3,2,figsize=(15, 15))
fig, axs = axs.ravel()
axs for i, (k,v) in enumerate(mapas.items()):
= v['datos'].plot(ax=axs[i], linewidth=v['peso'], color=v['color'])
ax
ax.set_title(k)'off')
ax.axis(
-1])
fig.delaxes(axs[=0, hspace=0)
plt.subplots_adjust(wspace# plt.tight_layout(pad=0.05)
= (Malla
malla 1000)
.desde_capa(red, ='Acceso controlado')
.agrega_lineas(acceso_controlado, campo='Vialidades primarias')
.agrega_lineas(primarias, campo='Vialidades secundarias')
.agrega_lineas(secundarias, campo='Vialidades terciarias')
.agrega_lineas(terciarias, campo='Calles residenciales')) .agrega_lineas(residenciales, campo
malla.datos
grid_id | geometry | Acceso controlado | Vialidades primarias | Vialidades secundarias | Vialidades terciarias | Calles residenciales | |
---|---|---|---|---|---|---|---|
0 | 0 | POLYGON ((455987.604 2101522.619, 456987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
1 | 1 | POLYGON ((455987.604 2102522.619, 456987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
2 | 2 | POLYGON ((455987.604 2103522.619, 456987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
3 | 3 | POLYGON ((455987.604 2104522.619, 456987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
4 | 4 | POLYGON ((455987.604 2105522.619, 456987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
... | ... | ... | ... | ... | ... | ... | ... |
7609 | 7609 | POLYGON ((535987.604 2190522.619, 536987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
7610 | 7610 | POLYGON ((535987.604 2191522.619, 536987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
7611 | 7611 | POLYGON ((535987.604 2192522.619, 536987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
7612 | 7612 | POLYGON ((535987.604 2193522.619, 536987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
7613 | 7613 | POLYGON ((535987.604 2194522.619, 536987.604 2... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
7614 rows × 7 columns
= malla.to_xarray() rasters
rasters
<xarray.Dataset> Dimensions: (y: 95, x: 82) Coordinates: * y (y) float64 2.102e+06 2.102e+06 ... 2.196e+06 * x (x) float64 5.365e+05 5.355e+05 ... 4.555e+05 spatial_ref int64 0 Data variables: Acceso controlado (y, x) float64 nan nan nan nan ... 0.0 0.0 0.0 nan Vialidades primarias (y, x) float64 nan nan nan nan ... 0.0 0.0 0.0 nan Vialidades secundarias (y, x) float64 nan nan nan nan ... 0.0 0.0 0.0 nan Vialidades terciarias (y, x) float64 nan nan nan nan ... 0.0 0.0 0.0 nan Calles residenciales (y, x) float64 nan nan nan nan ... 0.0 0.0 0.0 nan
'Acceso controlado'].plot() rasters[
<matplotlib.collections.QuadMesh>
(rasters
.to_array()= 'variable', col_wrap=3, figsize=(15, 10))) .plot(col
<xarray.plot.facetgrid.FacetGrid>