Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
need to export individual features to shapefiles using geopandas

I'm using geopandas to read a geojson file and output shapefiles. The issue is I cannot figure out how to export single features within that shapefile - only the entire shapefile. Just for ref, I'm using google colab.

here's what I have so far

os.makedirs('/content/drive/MyDrive/shapes')
gdf = gpd.read_file('/content/sample_data/countries.geojson')
for num, row in gdf.iterrows():
    key = row.city
    fileName = key+".shp"
    path = '/content/drive/MyDrive/shapes/'+fileName
    os.makedirs('/content/drive/MyDrive/shapes/'+fileName)
    os.chdir('/content/drive/MyDrive/shapes/'+fileName)
    gdf.to_file(fileName) # need to do something like row to file here

this code will export a bunch of shapefiles of the original geojson file & name them by a certain key. I can't figure out how to loop through the individual features and make a shapefile for each.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since I didn't have your shapefile, I am going to answer your question based on what you have told in your question. First of all, you should not save the gdf dataframe every time because you want to save the row into a file(I think each row represents a city and you want to have this city in a different shapefile that is named after the city name). So, what I suggest is:

os.makedirs('/content/drive/MyDrive/shapes')
gdf = gpd.read_file('/content/sample_data/countries.geojson')
for num, row in gdf.iterrows():
    key = row.city
    fileName = key+".shp"
    path = '/content/drive/MyDrive/shapes/'+fileName
    os.makedirs(path)
    os.chdir('/content/drive/MyDrive/shapes/'+fileName)
    gdf.iloc[num:num+1,:].to_file(path)

Note that, instead of saving in filename I saved the file into path because if it wasn't the case, the last few lines in your code would be for nothing!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda