Browse Source

neo cover ui mode, cf #9

master
Olivier Courtin 4 months ago
parent
commit
d28a40e876
1 changed files with 13 additions and 2 deletions
  1. +13
    -2
      neat_eo/tools/cover.py

+ 13
- 2
neat_eo/tools/cover.py View File

@@ -12,6 +12,7 @@ from mercantile import tiles, xy_bounds
from rasterio import open as rasterio_open
from rasterio.warp import transform_bounds

from neat_eo.core import web_ui
from neat_eo.tiles import tiles_from_dir, tiles_from_csv, tiles_to_geojson
from neat_eo.geojson import geojson_srid, geojson_parse_feature

@@ -38,10 +39,12 @@ def add_parser(subparser, formatter_class):
out = parser.add_argument_group("Outputs")
out.add_argument("--zoom", type=int, help="zoom level of tiles [required, except with --dir or --cover inputs]")
help = "Output type (default: cover)"
out.add_argument("--type", type=str, choices=["cover", "extent", "geojson"], default="cover", help=help)
out.add_argument("--type", type=str, choices=["cover", "extent", "ui", "geojson"], default="cover", help=help)
out.add_argument("--union", action="store_true", help="if set, union adjacent tiles, imply --type geojson")
out.add_argument("--splits", type=str, help="if set, shuffle and split in several cover subpieces (e.g 50/15/35)")
out.add_argument("--out", type=str, nargs="*", help="cover output paths [required except with --type extent]")
out.add_argument("--web_ui_base_url", type=str, help="alternate Web UI base URL, if ui mode")
out.add_argument("--web_ui_template", type=str, help="alternate Web UI template path, if ui mode")

parser.set_defaults(func=main)

@@ -50,6 +53,7 @@ def main(args):

assert not (args.type == "extent" and args.splits), "--splits and --type extent are mutually exclusive options"
assert not (args.type == "extent" and args.out and len(args.out) > 1), "--type extent option imply a single --out path"
assert not (args.type == "ui" and len(args.out) != 1), "--type ui option imply a single --out path"
assert not (args.type != "extent" and not args.out), "--out mandatory [except with --type extent]"
assert not (args.union and args.type != "geojson"), "--union imply --type geojson"
assert not (args.sql and not args.pg), "--sql option imply --pg"
@@ -200,7 +204,14 @@ def main(args):
fp.write(extent)
else:
print(extent)
else:

if args.type == "ui":
template = "leaflet.html" if not args.web_ui_template else args.web_ui_template
base_url = args.web_ui_base_url if args.web_ui_base_url else "."
os.makedirs(args.out[0], exist_ok=True)
web_ui(args.out[0], base_url, covers[0], covers[0], "png", template)

if args.type in ["cover", "geojson"]:
for i, cover in enumerate(covers):

if os.path.dirname(args.out[i]) and not os.path.isdir(os.path.dirname(args.out[i])):


Loading…
Cancel
Save