diff --git a/rantanenurageocommands/geojson.py b/rantanenurageocommands/geojson.py index bd6d2c5..bff4fdc 100644 --- a/rantanenurageocommands/geojson.py +++ b/rantanenurageocommands/geojson.py @@ -15,15 +15,28 @@ def register(parser): # Allow filtering by language-only, dialect-only, list of glottocodes parser.add_argument('-o', '--output', type=PathType(must_exist=False), default=None) + parser.add_argument('--callback', default=None) + parser.add_argument('--branches', default=None, type=lambda s: s.split(',')) def run(args): res = dict(type='FeatureCollection', features=[]) cldf = Dataset().cldf_reader() features = {r['Language_ID']: r['SpeakerArea'] for r in cldf['areas.csv']} - #for l in cldf.objects('LanguageTable'): - res['features'] = list(features.values()) + + def filter(l): + res = True + if args.branches: + res = res and l['Branch'] in args.branches + return res + + lids = [l['ID'] for l in cldf['LanguageTable'] if filter(l)] + res['features'] = [f for lid, f in features.items() if lid in lids] if args.output: - dump(res, args.output, indent=4) + if args.callback: + args.output.write_text('{}({});'.format( + args.callback, json.dumps(res)), encoding='utf8') + else: + dump(res, args.output, indent=4) else: print(json.dumps(res, indent=4)) diff --git a/rantanenurageocommands/htmlmap.py b/rantanenurageocommands/htmlmap.py new file mode 100644 index 0000000..804c3cb --- /dev/null +++ b/rantanenurageocommands/htmlmap.py @@ -0,0 +1,29 @@ +""" + +""" +import shutil +import pathlib +import argparse +import webbrowser + +from clldutils.clilib import PathType + +from . import geojson + + +def register(parser): + # Allow filtering by language-only, dialect-only, list of glottocodes + parser.add_argument( + '-o', '--output', type=PathType(must_exist=False, type='dir'), default=pathlib.Path('.')) + parser.add_argument('--callback', default='parseGeojson', help=argparse.SUPPRESS) + parser.add_argument('--branches', default=None, type=lambda s: s.split(',')) + + +def run(args): + outdir = args.output + if not outdir.exists(): + outdir.mkdir() + args.output = outdir / 'languages.js' + geojson.run(args) + shutil.copy(pathlib.Path(__file__).parent / 'index.html', outdir) + webbrowser.open(str(outdir / 'index.html')) diff --git a/rantanenurageocommands/index.html b/rantanenurageocommands/index.html new file mode 100644 index 0000000..54d30a5 --- /dev/null +++ b/rantanenurageocommands/index.html @@ -0,0 +1,86 @@ + + +
+