In [1]:
import json
import sys
import subprocess
from copy import deepcopy
import pathlib
import xml.dom.minidom as md
import re
from pathlib import Path

DATA_DIR = Path('../tests/data')
OUT_DIR = Path('../outputs')

sys.path.append('../')
import kml2geojson as kg

%load_ext autoreload
%autoreload 2

In [9]:
kml_path = DATA_DIR/'google_sample.kml'
with kml_path.open() as src:
    root = md.parseString(src.read())
    
layers = kg.build_layers(root)
print('')
for layer in layers:
    print(layer['name'])


RIDGE2 SVR Warnings
RIDGE2 SVR Warnings1
RIDGE2 TOR Warnings
RIDGE2 FFW Warnings
RIDGE2 SMW Warnings

In [ ]:
k_path = DATA_DIR/'two_layers'/'two_layers.kml'
out_path = DATA_DIR/'tmp'
kg.convert(k_path, out_path, separate_folders=True, style_type='svg')
for p in k_path.parent.iterdir():
    if p.suffix == '.kml':
        continue
    gp = out_path/p.name
    with gp.open() as src:
        get = json.load(src)
    with p.open() as src:
        expect = json.load(src)
    is_equal = get == expect
    print(p.stem, is_equal)
    if not is_equal:
        print(get)
        print(expect)

In [ ]:
kml_path = DATA_DIR/'description.kml'
with kml_path.open() as src:
    root = md.parseString(src.read())
    
desc = kg.get1(root, 'description')

def test(node):
    text = kg.val(node)
    text = re.sub(r'<META .*>', '', text, flags=re.I)
    x = md.parseString(text)
    return kg.del_attrs(x)

def clean_description(node):
    text = kg.val(node)
    text = re.sub(r'<META .*>', '', text, flags=re.I)
    try:
        x = md.parseString(text)
        x = kg.del_attrs(x)
    except Exception:
        x = node
    return x

desc = clean_description(desc)
desc.toxml()
# feature = kg.build_feature_collection(root)
# feature

In [ ]:


In [ ]: