IBGE¶
O GeoFTP do IBGE é o servidor do Instituto Brasileiro de Geografia e Estatistica (IBGE) que disponibiliza diversas informações relevantes, majoritariamente em formato shapefile, ou seja, em formato editável, sendo que os dados armazenados nesse repositório são derivados destes.
In [ ]:
Copied!
import tempfile
from pathlib import Path
import geopandas as gpd
import open_geodata as geo
import tempfile
from pathlib import Path
import geopandas as gpd
import open_geodata as geo
In [ ]:
Copied!
db = geo.data.DB(db='br_ibge')
db.list_data
db = geo.data.DB(db='br_ibge')
db.list_data
In [ ]:
Copied!
filename = db.get_data(name='geo.br-municipios-2024')
filename
filename = db.get_data(name='geo.br-municipios-2024')
filename
In [ ]:
Copied!
gpd.read_file(filename=filename)
gpd.read_file(filename=filename)
In [ ]:
Copied!
gdf = geo.load_dataset(db='br_ibge', name='geo.br-malha_municipal-2024')
gdf.head()
gdf = geo.load_dataset(db='br_ibge', name='geo.br-malha_municipal-2024')
gdf.head()
In [ ]:
Copied!
gdf = gdf.loc[gdf['SIGLA_UF'] == 'SP']
gdf
gdf = gdf.loc[gdf['SIGLA_UF'] == 'SP']
gdf
In [ ]:
Copied!
# Reprojeta
print(gdf.crs)
gdf = gdf.to_crs(epsg=4326)
print(gdf.crs)
# Reprojeta
print(gdf.crs)
gdf = gdf.to_crs(epsg=4326)
print(gdf.crs)
In [ ]:
Copied!
gdf.explore()
gdf.explore()
In [ ]:
Copied!
# Salva
with tempfile.TemporaryDirectory() as temp_dir:
# Cria o caminho temporário em formato Path
temp_path = Path(temp_dir)
# Salva em GeoJSON e GPKG
gdf.to_file(
temp_path / 'limite_municipal_sp.geojson',
driver='GeoJSON',
encoding='utf-8',
)
gdf.to_file(
temp_path / 'limite_municipal_sp.gpkg',
layer='Limite',
driver='GPKG',
)
# Salva
with tempfile.TemporaryDirectory() as temp_dir:
# Cria o caminho temporário em formato Path
temp_path = Path(temp_dir)
# Salva em GeoJSON e GPKG
gdf.to_file(
temp_path / 'limite_municipal_sp.geojson',
driver='GeoJSON',
encoding='utf-8',
)
gdf.to_file(
temp_path / 'limite_municipal_sp.gpkg',
layer='Limite',
driver='GPKG',
)
In [ ]:
Copied!
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)
ibge.download_malhas_municipais(output_path=temp_path)
print(list(temp_path.glob('*')))
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)
ibge.download_malhas_municipais(output_path=temp_path)
print(list(temp_path.glob('*')))
In [ ]:
Copied!