Prototype Solar Mini Grid Layout (1st Implementation)




Pay Notebook Creator: Roy Hyunjin Han250
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0

Vision

Inspire a community of professionals skilled in spatiotemporal analysis for community health and safety.

Mission

Write a tool that converts the example KMZ datasets into a normalized format.

Owner

Roy Hyunjin Han

Context

We have some example datasets and we would like to normalize them so that downstream modules know how to load them.

Timeframe

20170912-1715 - 20170920-1700: 1 week actual

Objectives

_ Load example kmz datasets
_ Save kmz datasets
_ Build a tool that extracts specific information from a kml file

Log

20170912-1715 - 20170912-1815: 60 minutes

fastkml
_ kmltogeojson    
_ pykml
_ simplekml
_ pygis

+ Find packages for handling kmz files

20170912-2130 - 20170912-2200: 30 minutes

After evaluating a bunch of packages, I think we should use fastkml.

+ Decide which package we might use

20170920-1630 - 20170920-1700: 30 minutes

Maybe we can stick to GDAL for both loading and saving the KML. I don't feel like going into the specifics of KML format.

I think the reason fastkml exists is if you do not want any dependencies other than Python.

_ Use fastkml to load the example datasets

I probably could use fiona, but I would rather upgrade geometryIO as it has been on my list of things to do for a long time. But I would like to call it something different.

In [ ]:
from os.path import expanduser
dataset_path = expanduser('~/Experiments/Datasets/evi-20170819.kmz')
In [ ]:
# Try fiona
import pip
pip.main(['install', 'fiona'])
In [ ]:
import fiona
# fiona.open(dataset_path)  # Raises FionaValueError

It looks like fiona will not support kml: https://github.com/Toblerity/Fiona/issues/23

In [ ]:
# Try geometryIO
import geometryIO
geometryIO.load(dataset_path)

The geometryIO package makes more progress, but it looks like it is not loading any geometries. We might have to put KML to CSV/SHP.ZIP as a separate tool.

In [ ]:
import pip
pip.main(['install', 'fastkml'])
In [ ]:
%%bash
cd ~/Downloads
cp ~/Experiments/Datasets/evi-20170819.kmz .
unzip evi-20170819.kmz
ls -l
In [ ]:
from fastkml.kml import KML
from os.path import expanduser
kml = KML()
kml_text = open(expanduser('~/Downloads/doc.kml'), 'rb').read()
kml.from_string(kml_text)
len(list(kml.features()))
In [ ]:
features = list(kml.features())
f = list(features[0].features())[0]
f.__dict__
In [ ]:
x = list(list(list(f.features())[0].features())[0].features())[0]
x
In [ ]:
x.__dict__
In [ ]:
x._geometry.__dict__

It looks like kml is one of those strange nested file formats.

In [ ]:
x = list(list(list(f.features())[0].features())[0].features())[1]
x.__dict__
In [ ]:
list(list(list(f.features())[0].features())[2].features())[1].__dict__
_ Examine KML of each example dataset
_ Try gdal
_ Load the different datasets
_ Save the different datasets

We decided not to accept kml files for now.