Skip to content

Instantly share code, notes, and snippets.

@BavYeti
Created February 3, 2018 19:22
Show Gist options
  • Save BavYeti/54f50d9d2b8a113e3d9eab65864156b5 to your computer and use it in GitHub Desktop.
Save BavYeti/54f50d9d2b8a113e3d9eab65864156b5 to your computer and use it in GitHub Desktop.
Wulca aware factors to GIS
#this script will convert the wulca aware factors kmz file from http://www.wulca-waterlca.org/aware.html to more GIS-ish vector (shp, geojson)files
#MIT License
#Copyright 2018 Matthias Czechowski https://github.com/bavyeti
file = 'AWARE_v1_2April_7th.kmz'
import geopandas as gpd
import pandas as pd
import fiona
fiona.drvsupport.supported_drivers['kml'] = 'rw'
fiona.drvsupport.supported_drivers['KML'] = 'rw'
aware = gpd.read_file('zip://'+file)
attributes_df = pd.DataFrame()
for i,feature in aware.iterrows():
#access weird nested html table:
ntable= feature['Description'].split('td><table',1)
htmltable = pd.read_html('<table'+ntable[1])
attr = htmltable[0].set_index(0).T
attributes_df = attributes_df.append(attr,ignore_index=True)
attributes_df['FID']= attributes_df.FID.astype(int)
aware['Name'] = aware.Name.astype(int)
output = pd.merge(aware, attributes_df,left_on='Name',right_on='FID')
#for other filetypes check with fiona.supported_drivers
output.to_file('./aware.shp')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment