Exemples sur Cartofriches¶
In [3]:
Copied!
import plotly.io as pio
import plotly.express as px
pio.renderers.default = "notebook"
from apifoncier import ApiFoncierClient
import plotly.io as pio
import plotly.express as px
pio.renderers.default = "notebook"
from apifoncier import ApiFoncierClient
Communes ayant le plus de friches identifiées sur un département¶
In [ ]:
Copied!
# On récupère les friches du département 59
with ApiFoncierClient({"base_url": "https://apidf.k8-dev.cerema.fr"}) as apidf:
friches = apidf.cartofriches.friches(coddep="59", limit=1000)
# On récupère les friches du département 59
with ApiFoncierClient({"base_url": "https://apidf.k8-dev.cerema.fr"}) as apidf:
friches = apidf.cartofriches.friches(coddep="59", limit=1000)
/cartofriches/friches: 100%|██████████| 1472/1472 [00:00<00:00, 2909.85enreg./s]
In [5]:
Copied!
# Décompte par commune
result = friches.value_counts("comm_nom").to_frame("nb_friches").iloc[:15]
# Génération du graphique
fig = px.bar(
result,
"nb_friches",
labels={"nb_friches": "Nombre de friches", "comm_nom": "Communes"},
title="Communes ayant le + de friches dans le département du Nord",
)
fig.show()
# Décompte par commune
result = friches.value_counts("comm_nom").to_frame("nb_friches").iloc[:15]
# Génération du graphique
fig = px.bar(
result,
"nb_friches",
labels={"nb_friches": "Nombre de friches", "comm_nom": "Communes"},
title="Communes ayant le + de friches dans le département du Nord",
)
fig.show()
Affichage des friches dans une emprise rectangulaire¶
In [8]:
Copied!
import folium
with ApiFoncierClient({"base_url": "https://apidf.k8-dev.cerema.fr"}) as apidf:
gdf = apidf.cartofriches.geofriches(in_bbox=[3, 50, 3.5, 50.5])
geojson = gdf.to_json()
m = folium.Map(location=[50.25, 3.25], zoom_start=12)
# Ajouter les données GeoJSON à la carte Folium
folium.GeoJson(geojson).add_to(m)
# Afficher la carte
m
import folium
with ApiFoncierClient({"base_url": "https://apidf.k8-dev.cerema.fr"}) as apidf:
gdf = apidf.cartofriches.geofriches(in_bbox=[3, 50, 3.5, 50.5])
geojson = gdf.to_json()
m = folium.Map(location=[50.25, 3.25], zoom_start=12)
# Ajouter les données GeoJSON à la carte Folium
folium.GeoJson(geojson).add_to(m)
# Afficher la carte
m
/cartofriches/geofriches: 100%|██████████| 402/402 [00:00<00:00, 10993.24enreg./s]
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook