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 [1]:
Copied!
import tempfile
from pathlib import Path
import open_geodata as geo
import tempfile
from pathlib import Path
import open_geodata as geo
In [2]:
Copied!
# Instancia classe IBGE
ibge = geo.br.ibge.geoftp.IBGE()
# Obtem Malhas de 2018
gdf = ibge.get_malhas_municipais(estado='SP')
# Resultados
gdf.info()
gdf.head()
# Instancia classe IBGE
ibge = geo.br.ibge.geoftp.IBGE()
# Obtem Malhas de 2018
gdf = ibge.get_malhas_municipais(estado='SP')
# Resultados
gdf.info()
gdf.head()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 645 entries, 0 to 644 Data columns (total 3 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 id_municipio 645 non-null int64 1 nome_municipio 645 non-null object 2 geometry 645 non-null geometry dtypes: geometry(1), int64(1), object(1) memory usage: 15.2+ KB
Out[2]:
| id_municipio | nome_municipio | geometry | |
|---|---|---|---|
| 0 | 3517208 | GUAIÇARA | POLYGON ((-49.82514 -21.58632, -49.82509 -21.5... |
| 1 | 3504206 | AURIFLAMA | POLYGON ((-50.61899 -20.66481, -50.61869 -20.6... |
| 2 | 3520905 | IPAUSSU | POLYGON ((-49.67444 -23.05396, -49.67364 -23.0... |
| 3 | 3519071 | HORTOLÂNDIA | POLYGON ((-47.24001 -22.84656, -47.24036 -22.8... |
| 4 | 3505401 | BARRA DO TURVO | POLYGON ((-48.50267 -24.74675, -48.50245 -24.7... |
In [3]:
Copied!
gdf = gdf.loc[gdf['nome_municipio'] == 'SANTOS']
gdf
gdf = gdf.loc[gdf['nome_municipio'] == 'SANTOS']
gdf
Out[3]:
| id_municipio | nome_municipio | geometry | |
|---|---|---|---|
| 559 | 3548500 | SANTOS | MULTIPOLYGON (((-46.16306 -24.32988, -46.16265... |
In [4]:
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)
EPSG:4674 EPSG:4326
In [5]:
Copied!
gdf.explore()
gdf.explore()
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
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:
# Cria o caminho temporário em formato Path
temp_path = Path(temp_dir)
# Faz o download para o caminho desejado
ibge.download_malhas_municipais(output_path=temp_path)
# Aponta o arquivo
print(list(temp_path.glob('*')))
with tempfile.TemporaryDirectory() as temp_dir:
# Cria o caminho temporário em formato Path
temp_path = Path(temp_dir)
# Faz o download para o caminho desejado
ibge.download_malhas_municipais(output_path=temp_path)
# Aponta o arquivo
print(list(temp_path.glob('*')))