An warware: Geodata gani

Hannun Geodata kayan aiki ne mai ฦ™arfi wanda ke ba mu damar fahimtar hadaddun tsari da alaฦ™a tsakanin yanki da sauran bayanai. Yana taimakawa wajen yanke shawara mai fa'ida da gabatar da bayanai ta hanya mafi sauฦ™i kuma mai jan hankali. A cikin wannan labarin, za mu bincika yadda za a iya samun hangen nesa ta geodata ta amfani da Python, ษ—aya daga cikin yarukan shirye-shirye da suka fi dacewa a yau. Za mu bincika ษ—akunan karatu daban-daban, ayyuka, da dabarun da ake amfani da su don magance matsalolin gama-gari a wannan yanki, tabbatar da samun ingantaccen tushe don ginawa.

Gabatar da Geodata Visualization a Python

Python yana ba da ษ—akunan karatu da yawa waษ—anda aka tsara musamman don ganin geodata. Wasu daga cikin shahararrun wadanda suka hada da GeoPandas, Folium, Da kuma Makirci. Kowane ษ—akin karatu yana aiki da manufarsa ta musamman, yana samar da ayyuka waษ—anda za a iya amfani da su don ฦ™irฦ™irar taswirori masu ฦ™arfi da mu'amala, sigogi, da filaye masu alaฦ™a da geodata. A matsayin mai haษ“akawa kuma ฦ™wararre a Python, yana da mahimmanci don fahimtar waษ—annan ษ—akunan karatu, fasalulluka, da iyakokin su don ฦ™irฦ™irar ingantattun abubuwan gani na geodata masu amfani.

  • GeoPandas ษ—akin karatu ne da aka gina a saman Pandas, wanda aka ฦ™era a sarari don sarrafa bayanan ฦ™asa. Yana iya karantawa da rubuta nau'ikan bayanai daban-daban, aiwatar da ayyukan geospatial, da sauฦ™in haษ—awa da sauran ษ—akunan karatu na Python kamar Matplotlib don ganin bayanan.
  • Folium ษ—akin karatu ne wanda ke samar da taswirori masu mu'amala ta amfani da ษ—akin karatu na Leaflet JavaScript, wanda ya dace da taswirori na choropleth masu mu'amala da taswirorin zafi. Yana ba da sauฦ™i mai sauฦ™i don ฦ™irฦ™irar taswira tare da yadudduka daban-daban (alamomi, popups, da sauransu), yana mai da shi kyakkyawan zaษ“i ga waษ—anda ba ฦ™wararru ba waษ—anda ke son ฦ™irฦ™irar taswira masu rikitarwa.
  • Makirci Labura ce mai ฦ™arfi kuma mai juzu'i don ฦ™irฦ™irar hotuna masu ma'amala da bugawa, sigogi, da taswira. Plotly Express babban keษ“antawa ne don ฦ™irฦ™irar waษ—annan abubuwan gani cikin sauri, yayin da API ษ—in 'graph_objects' da ke da hannu yana ba da damar keษ“ance kowane dalla-dalla na gani.

Magani ga Matsala: Kallon Geodata Amfani da Python

Bari mu yi la'akari da yanayin gama-gari wanda a cikinsa muke so mu hango yadda ake rarraba yawan jama'a a cikin ฦ™asashe daban-daban. Za mu yi amfani da bayanan da ke ษ—auke da iyakoki a tsarin GeoJSON da yawan yawan jama'a a tsarin CSV. Da farko, muna buฦ™atar karantawa, sarrafa, da haษ—a wannan bayanan. Sa'an nan, za mu ฦ™irฦ™iri taswirar choropleth don ganin girman yawa tare da ma'aunin launi masu dacewa.

1. Karanta kuma sarrafa bayanai

Za mu fara da karanta bayanan ta amfani da GeoPandas don bayanan yanki da Pandas don yawan yawan jama'a. Sannan, za mu haษ—a waษ—annan firam ษ—in bayanai guda biyu bisa maษ“alli gama gari (misali, lambar ฦ™asa).

import geopandas as gpd
import pandas as pd

# Read the GeoJSON file
world_map = gpd.read_file("world_map.geojson")

# Read the CSV file with population densities
density_data = pd.read_csv("population_density.csv")

# Merge the dataframes based on the common key (country code)
merged_data = world_map.merge(density_data, on="country_code")

2. ฦ˜irฦ™iri Taswirar Choropleth

Amfani da GeoPandas da Matplotlib, za mu iya ฦ™irฦ™irar taswirar choropleth don nuna yawan yawan jama'a tare da ma'aunin launi.

import matplotlib.pyplot as plt

# Create a choropleth map using population density data
fig, ax = plt.subplots(1, figsize=(10, 6))
merged_data.plot(column="population_density", cmap="Blues", linewidth=0.8, ax=ax)
plt.show()

Bayanin mataki-mataki na lambar Python

Yanzu da muka sami mafitarmu, bari mu bi ta hanyar code mataki-mataki don fahimtar kowane bangare. Za mu fara da shigo da dakunan karatu masu mahimmanci:

import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt

Na gaba, muna karanta fayil ษ—in GeoJSON ta amfani da GeoPandas da fayil ษ—in CSV ta amfani da Pandas.

world_map = gpd.read_file("world_map.geojson")
density_data = pd.read_csv("population_density.csv")

Bayan haka, muna haษ—a firam ษ—in bayanai ta maษ“alli gama gari, a wannan yanayin, lambar ฦ™asa.

merged_data = world_map.merge(density_data, on="country_code")

A ฦ™arshe, mun ฦ™irฦ™iri taswirar choropleth ta amfani da GeoPandas da Matplotlib, suna ฦ™ayyadaddun ginshiฦ™i don hangowa (yawan yawan jama'a) da taswirar launi (Blues).

fig, ax = plt.subplots(1, figsize=(10, 6))
merged_data.plot(column="population_density", cmap="Blues", linewidth=0.8, ax=ax)
plt.show()

Wannan ya ฦ™are binciken mu na ganin geodata a cikin Python. Mun tattauna dakunan karatu daban-daban, kamar GeoPandas, Folium, Da kuma Makirci, da ayyukansu wajen ฦ™irฦ™irar abubuwan gani na geodata masu ฦ™arfi da ma'amala. Tare da wannan ilimin, ya kamata ku zama mafi kyawun kayan aiki don magance hadaddun ayyukan gani na geodata da haษ“aka ingantattun mafita.

Shafi posts:

Leave a Comment