aboutsummaryrefslogtreecommitdiffstats
path: root/webmap-import
diff options
context:
space:
mode:
Diffstat (limited to 'webmap-import')
-rwxr-xr-xwebmap-import30
1 files changed, 15 insertions, 15 deletions
diff --git a/webmap-import b/webmap-import
index 9f9fdca..13bdcdc 100755
--- a/webmap-import
+++ b/webmap-import
@@ -46,13 +46,13 @@ import osgeo.gdalconst as gdalconst
gdal.UseExceptions()
import common
-from common import gdalSetOpenExArgs, gdalGetMetadataItem, gdalVersionMin, escapeIdentifier
+from common import gdalSetOpenExArgs, gdalGetMetadataItem, gdalVersionMin, escape_identifier
# Open and return the output DS. It is created if create=False or
# create-options is a non-empty dictionary.
def openOutputDS(def_dict):
path = def_dict['path']
- kwargs, drv = gdalSetOpenExArgs(def_dict, flags=GDAL_OF_UPDATE|GDAL_OF_VERBOSE_ERROR)
+ kwargs, drv = gdalSetOpenExArgs(gdal, def_dict, flags=GDAL_OF_UPDATE|GDAL_OF_VERBOSE_ERROR)
try:
logging.debug('OpenEx(%s, %s)', path, str(kwargs))
return gdal.OpenEx(path, **kwargs)
@@ -321,13 +321,13 @@ def setFieldIf(cond, attrName, val, data, fldName, drvName, log=logging.warning)
# constraints.)
def validateSchema(layers, drvo=None, lco_defaults=None):
# Cf. https://github.com/OSGeo/gdal/blob/master/NEWS.md
- if gdalVersionMin(maj=3, min=7):
+ if gdalVersionMin(gdal, maj=3, min=7):
# list of capability flags supported by the CreateField() API
drvoFieldDefnFlags = drvo.GetMetadataItem(gdalconst.DMD_CREATION_FIELD_DEFN_FLAGS)
drvoFieldDefnFlags = drvoFieldDefnFlags.split(' ') if drvoFieldDefnFlags is not None else []
drvoSupportsFieldComment = 'Comment' in drvoFieldDefnFlags
# GetTZFlag()/SetTZFlag() and OGR_TZFLAG_* constants added in 3.8.0
- hasTZFlagSupport = gdalVersionMin(maj=3, min=8)
+ hasTZFlagSupport = gdalVersionMin(gdal, maj=3, min=8)
else:
# list of flags supported by the OGRLayer::AlterFieldDefn() API
drvoFieldDefnFlags = drvo.GetMetadataItem(gdalconst.DMD_ALTER_FIELD_DEFN_FLAGS)
@@ -726,7 +726,7 @@ def clearLayer(ds, lyr):
if n == 0:
# nothing to clear, we're good
return
- layername_esc = escapeIdentifier(lyr.GetName())
+ layername_esc = escape_identifier(lyr.GetName())
# XXX GDAL <3.9 doesn't have lyr.GetDataset() so we pass the DS along with the layer
drv = ds.GetDriver()
@@ -849,7 +849,7 @@ def setFieldMapValue(fld, idx, val):
# while we want a single transaction for the entire desination layer,
# including truncation, source imports, and metadata changes.
def importSource2(lyr_dst, path, args={}, basedir=None, extent=None):
- kwargs, _ = gdalSetOpenExArgs(args, flags=GDAL_OF_READONLY|GDAL_OF_VERBOSE_ERROR)
+ kwargs, _ = gdalSetOpenExArgs(gdal, args, flags=GDAL_OF_READONLY|GDAL_OF_VERBOSE_ERROR)
path2 = path if basedir is None else str(basedir.joinpath(path))
logging.debug('OpenEx(%s, %s)', path2, str(kwargs))
@@ -1121,13 +1121,13 @@ if __name__ == '__main__':
if args.debug > 1:
gdal.ConfigurePythonLogging(enable_debug=True)
- common.load_config(groupnames=None if args.groupname == [] else args.groupname)
+ config = common.get_config(groupnames=None if args.groupname == [] else args.groupname)
# validate configuration
- if 'dataset' not in common.config:
+ if 'dataset' not in config:
raise Exception('Configuration does not specify output dataset')
- layers = common.config.get('layers', {})
+ layers = config.get('layers', {})
for layername, layerdefs in layers.items():
for idx, layerdef in enumerate(layerdefs['sources']):
importdef = layerdef.get('import', None)
@@ -1140,7 +1140,7 @@ if __name__ == '__main__':
ds_srcpath = importdef.get('path', None)
if src is None and unar is None and ds_srcpath is not None:
- # fallback to importe:path if there is no unarchiving receipe
+ # fallback to importe:path if there is no unarchiving recipe
src = Path(ds_srcpath)
if unar is not None and ds_srcpath is None:
raise Exception(f'Output layer "{layername}" source #{idx} has no import source path')
@@ -1149,20 +1149,20 @@ if __name__ == '__main__':
layerdef['source'] = { 'path': src, 'unar': unar }
# set global GDAL/OGR configuration options
- for pszKey, pszValue in common.config.get('GDALconfig', {}).items():
+ for pszKey, pszValue in config.get('GDALconfig', {}).items():
logging.debug('gdal.SetConfigOption(%s, %s)', pszKey, pszValue)
gdal.SetConfigOption(pszKey, pszValue)
# open output dataset (possibly create it first)
- dso = openOutputDS(common.config['dataset'])
+ dso = openOutputDS(config['dataset'])
validateSchema(layers,
drvo=dso.GetDriver(),
- lco_defaults=common.config['dataset'].get('create-layer-options', None))
+ lco_defaults=config['dataset'].get('create-layer-options', None))
# get configured Spatial Reference System and extent
- srs = common.getSRS(common.config.get('SRS', None))
- extent = common.getExtent(common.config.get('extent', None), srs=srs)[0]
+ srs = common.getSRS(osr, config.get('SRS', None))
+ extent = common.getExtent(config.get('extent', None), srs=srs)[0]
if args.lockfile is not None:
# obtain an exclusive lock and don't release it until exiting the program