aboutsummaryrefslogtreecommitdiffstats
path: root/webmap-import
diff options
context:
space:
mode:
Diffstat (limited to 'webmap-import')
-rwxr-xr-xwebmap-import64
1 files changed, 52 insertions, 12 deletions
diff --git a/webmap-import b/webmap-import
index dafff78..1b9cde8 100755
--- a/webmap-import
+++ b/webmap-import
@@ -31,6 +31,7 @@ import re
from datetime import datetime, timedelta, timezone, UTC
from math import modf
from pathlib import Path
+from time import monotonic as time_monotonic
from typing import Any, Optional, NoReturn
import traceback
@@ -67,6 +68,7 @@ from import_source import (
importSources,
ImportStatus
)
+from export_mvt import exportMVT
def setFieldIf(cond : bool,
attrName : str,
@@ -580,6 +582,13 @@ def main() -> NoReturn:
help='obtain an exclusive lock before processing')
parser.add_argument('--lockdir-sources', default=None,
help='optional directory for lock files to source paths')
+ parser.add_argument('--mvtdir', default=None,
+ help='optional directory for Mapbox Vector Tiles (MVT)')
+ parser.add_argument('--mvtdir-tmp', default=None,
+ help='temporary directory for Mapbox Vector Tiles (MVT); it must exists and be '
+ 'on the same file system as the --mvtdir value')
+ parser.add_argument('--compress-tiles', default=False, action='store_true',
+ help='whether to compress Mapbox Vector Tiles (MVT) files')
parser.add_argument('--force', default=False, action='store_true',
help='import even if no new changes were detected')
parser.add_argument('groupname', nargs='*', help='group layer name(s) to process')
@@ -634,7 +643,16 @@ def main() -> NoReturn:
'support layer creation')
createOutputLayer(dso, layername, srs=srs, options=layerdef.get('create', None))
- cachedir = Path(args.cachedir) if args.cachedir is not None else None
+ if args.mvtdir is not None:
+ args.mvtdir = Path(args.mvtdir)
+ if args.mvtdir == Path():
+ raise RuntimeError('Invalid value for --mvtdir')
+ args.mvtdir.parent.mkdir(parents=True, exist_ok=True)
+ if args.mvtdir_tmp is not None:
+ args.mvtdir_tmp = Path(args.mvtdir_tmp)
+
+ if args.cachedir is not None:
+ args.cachedir = Path(args.cachedir)
if args.lockdir_sources is None:
sourcePathLocks = None
else:
@@ -665,15 +683,19 @@ def main() -> NoReturn:
rv = 0
try:
- r = ImportStatus.IMPORT_NOCHANGE
+ r = {}
+ n = 0
+ start = time_monotonic()
for layername, layerdef in layers.items():
- r0 = processOutputLayer(dso, layername, layerdef,
- srs=srs,
- cachedir=cachedir,
- extent=extent,
- dsTransaction=dsoTransaction,
- lyrcache=lyr_cache,
- force=args.force)
+ r[layername] = r0 = processOutputLayer(dso, layername, layerdef,
+ srs=srs,
+ cachedir=args.cachedir,
+ extent=extent,
+ dsTransaction=dsoTransaction,
+ lyrcache=lyr_cache,
+ force=args.force)
+ n += 1
+ logging.info('Import result status for layer "%s": %s', layername, str(r0))
if r0 == ImportStatus.IMPORT_ERROR:
rv = 1
if dsoTransaction:
@@ -682,13 +704,31 @@ def main() -> NoReturn:
# no need to catch the exception here
if dso.CommitTransaction() != ogr.OGRERR_NONE:
logging.error('Could not rollback transaction')
- if r == ImportStatus.IMPORT_NOCHANGE and r0 == ImportStatus.IMPORT_SUCCESS:
- r = ImportStatus.IMPORT_SUCCESS
- logging.info('result = %s', str(r))
+ break
+ elapsed = time_monotonic() - start
+ logging.info('Processed %d destination layers in %s', n, common.format_time(elapsed))
if sourcePathLocks is not None:
releaseSourcePathLocks(sourcePathLocks)
+ export_layers = { l:d for l,d in layers.items() if d.get('publish', None) is not None }
+ if args.mvtdir is None or any(r0 == ImportStatus.IMPORT_ERROR for r0 in r.values()):
+ pass
+ elif len(export_layers) == 0:
+ logging.warning('--mvtdir option used but no layer has a publication definition')
+ elif (all(r0 == ImportStatus.IMPORT_NOCHANGE for l,r0 in r.items() if l in export_layers)
+ and args.mvtdir.is_dir()):
+ logging.info('Skipping MVT export for group %s (no changes)',
+ ', '.join(args.groupname) if args.groupname is not None else '*')
+ else:
+ exportMVT(dso, layers=export_layers,
+ tmpdir=args.mvtdir_tmp,
+ dst=args.mvtdir,
+ default_options=config.get('vector-tiles', None),
+ mvtname=(args.groupname[0] if args.groupname is not None and
+ len(args.groupname) == 1 else 'mvt'),
+ compress=args.compress_tiles)
+
if dsoTransaction:
dsoTransaction = False
logging.debug('Committing transaction')