aboutsummaryrefslogtreecommitdiffstats
path: root/export_mvt.py
diff options
context:
space:
mode:
Diffstat (limited to 'export_mvt.py')
-rw-r--r--export_mvt.py17
1 files changed, 6 insertions, 11 deletions
diff --git a/export_mvt.py b/export_mvt.py
index 7b3137b..de4a351 100644
--- a/export_mvt.py
+++ b/export_mvt.py
@@ -186,11 +186,10 @@ def exportSourceLayer(lyr_src : ogr.Layer,
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)
- try:
+ with ds_src.ExecuteSQL(query, spatialFilter=spatialFilter) as lyr_src2:
count1 = -1
- if lyr_src.TestCapability(ogr.OLCFastFeatureCount):
- count1 = lyr_src.GetFeatureCount(force=0)
+ if lyr_src2.TestCapability(ogr.OLCFastFeatureCount):
+ count1 = lyr_src2.GetFeatureCount(force=0)
if count0 >= 0 and count1 >= 0:
logging.debug('Source layer "%s" has %d features, of which %d are to be exported',
layername, count0, count1)
@@ -198,13 +197,13 @@ def exportSourceLayer(lyr_src : ogr.Layer,
fieldMap = fieldMap[1]
logging.debug('Field map: %s', str(fieldMap))
- geom_type = lyr_src.GetGeomType()
+ geom_type = lyr_src2.GetGeomType()
bFlatten = geom_type == ogr.wkbUnknown or ogr.GT_HasM(geom_type) or ogr.GT_HasZ(geom_type)
bTransform = bFlatten or ct is not None
feature_count = 0
defn_dst = lyr_dst.GetLayerDefn()
- feature = lyr_src.GetNextFeature()
+ feature = lyr_src2.GetNextFeature()
while feature is not None:
feature2 = ogr.Feature(defn_dst)
feature2.SetFromWithMap(feature, False, fieldMap)
@@ -219,14 +218,10 @@ def exportSourceLayer(lyr_src : ogr.Layer,
if lyr_dst.CreateFeature(feature2) != ogr.OGRERR_NONE:
raise RuntimeError(f'Could not transfer source feature #{feature.GetFID()}')
feature_count += 1
- feature = lyr_src.GetNextFeature()
+ feature = lyr_src2.GetNextFeature()
logging.info('Exported %d features to MVT layer "%s" from "%s"',
feature_count, lyr_dst.GetName(), layername)
-
- finally:
- ds_src.ReleaseResultSet(lyr_src)
- lyr_src = None
return feature_count
def list_files(top : str,