Skip to content

Instantly share code, notes, and snippets.

@marcellobenigno
Created May 8, 2024 12:30
Show Gist options
  • Save marcellobenigno/34bec1f9961483c6b4d6af63521ff50d to your computer and use it in GitHub Desktop.
Save marcellobenigno/34bec1f9961483c6b4d6af63521ff50d to your computer and use it in GitHub Desktop.
Realizar a junção de um Excel com a camada de sedes
import geopandas as gpd
import pandas as pd
path = '/Users/marcellodebarrosfilho/Desktop/PAC/Reg_Tratada_08_05_2024.xlsx'
gpkg = '/Users/marcellodebarrosfilho/code/curso_geopandas/dados/bc250_2021_11_18.gpkg'
sedes = gpd.read_file(gpkg, layer='sedes')
for idx, row in df.iterrows():
sede = sedes[(sedes['nome'].str.upper() == row['Município beneficiado']) & (sedes['sigla'] == row['UF'])]
if not sede.empty:
geododico_value = sede['geocodigo'].values[0]
geometry_value = sede['geometry'].values[0]
df.at[idx, 'geocodigo'] = geododico_value
df.at[idx, 'geometry'] = geometry_value
else:
df.at[idx, 'geocodigo'] = None
df.at[idx, 'geometry'] = None
gdf = gpd.GeoDataFrame(df, crs='EPSG:4326', geometry='geometry')
gdf.to_file('/Users/marcellodebarrosfilho/Desktop/PAC/Reg_Tratada_08_05_2024.geojson')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment