diff options
Diffstat (limited to 'export_mvt.py')
-rw-r--r-- | export_mvt.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/export_mvt.py b/export_mvt.py index c3690a9..7b3137b 100644 --- a/export_mvt.py +++ b/export_mvt.py @@ -117,8 +117,7 @@ def createMVT(drv : gdal.Driver, path : str, return drv.Create(path, 0, 0, 0, **kwargs) # pylint: disable-next=too-many-branches -def exportSourceLayer(ds_src : gdal.Dataset, - lyr_src : ogr.Layer, +def exportSourceLayer(lyr_src : ogr.Layer, lyr_dst : ogr.Layer, layerdef : dict[str,Any], fieldMap : tuple[list[str],list[int]], @@ -184,6 +183,7 @@ def exportSourceLayer(ds_src : gdal.Dataset, if cond is not None: query += ' WHERE ' + cond.strip() + ds_src = lyr_src.GetDataset() logging.debug('ExecuteSQL(%s%s)', query, '' if spatialFilter is None else ', spatialFilter=' + spatialFilter.ExportToWkt()) lyr_src = ds_src.ExecuteSQL(query, spatialFilter=spatialFilter) @@ -363,7 +363,6 @@ def exportMetadata(basedir : Path, data : dict[str,Any], os.close(fd) def getFieldMap(lyr_dst : ogr.Layer, lyr_src : ogr.Layer, - drv_src : gdal.Driver, fieldMap : dict[str,str]|None) -> tuple[list[str],list[int]]: """Create fields on the destination MVT layer, and return a list of column statements along with a field map for the MVT export.""" @@ -376,6 +375,7 @@ def getFieldMap(lyr_dst : ogr.Layer, lyr_src : ogr.Layer, columns = {} defn_src = lyr_src.GetLayerDefn() + drv_src = lyr_src.GetDataset().GetDriver() for fld_dst, fld_src in fieldMap.items(): idx_src = defn_src.GetFieldIndex(fld_src) if idx_src < 0: @@ -394,7 +394,6 @@ def getFieldMap(lyr_dst : ogr.Layer, lyr_src : ogr.Layer, # advantage of the reduced storage though) defn_dst.SetSubType(ogr.OFSTInt16) - # TODO[GDAL >=3.9] use lyr_src.GetDataset().GetDriver() if drv_src.ShortName == 'PostgreSQL': column = 'CAST(m.' + escape_identifier(fld_src) column += ' - date \'1970-01-01\' AS smallint)' @@ -528,13 +527,12 @@ def exportMVT(ds : gdal.Dataset, if lyr_dst is None: raise RuntimeError(f'Could not create destination layer "{layername}"') - fieldMap = getFieldMap(lyr_dst, lyr_src, drv_src=ds.GetDriver(), - fieldMap=layerdef.get('fields', None)) + fieldMap = getFieldMap(lyr_dst, lyr_src, fieldMap=layerdef.get('fields', None)) # TODO: GDAL exports features to a temporary SQLite database even though the source # is PostGIS hence is able to generate MVT with ST_AsMVT(). Letting PostGIS generate # tiles is likely to speed up things. - feature_count += exportSourceLayer(ds, lyr_src, lyr_dst, layerdef, + feature_count += exportSourceLayer(lyr_src, lyr_dst, layerdef, fieldMap=fieldMap, extent=extent) layer_count += 1 |