Skip to content

Instantly share code, notes, and snippets.

@EamonKeane
Created July 31, 2017 20:07
Show Gist options
  • Save EamonKeane/16ce83ad702125224a723e677a363b09 to your computer and use it in GitHub Desktop.
Save EamonKeane/16ce83ad702125224a723e677a363b09 to your computer and use it in GitHub Desktop.
import os, zipfile
import geopandas as gpd
import pandas as pd
import shutil
project_folder = 'Spain_CartoCity/'
extension = '.zip'
root_folder = '/Users/Eamon/Google Drive/Python Scripts/merge_CartoCiudad'
df_list = []
for item in os.listdir(project_folder):
if item.endswith(extension):
extracted_folder_name = item[:-4]
print(item[:-4])
path_to_extract = os.path.join(root_folder, project_folder)
extracted_folder_path = os.path.join(root_folder, extracted_folder_name)
zip_path = os.path.join(root_folder, project_folder, item)
address_file = 'PORTAL_PK.shp'
extracted_address_file = os.path.join(extracted_folder_path, address_file)
print(zip_path)
zip_ref = zipfile.ZipFile(zip_path, 'r')
zip_ref.extractall()
df = gpd.read_file(extracted_address_file)
df_list.append(df)
print(df.head())
shutil.rmtree(extracted_folder_path)
rdf = gpd.GeoDataFrame( pd.concat( df_list, ignore_index=True) )
print(rdf.to_csv('merged_output_full.csv', encoding='utf-8-sig'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment