diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2025-06-06 01:46:06 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2025-06-07 18:31:59 +0200 |
commit | 5f9d4e4cc914f10c6cfd3ee06405f18b880ba82d (patch) | |
tree | f2c57c771006a37a433e32acc4cbcffdcd082e3b /import_source.py | |
parent | 50c4e7c2a3b61acc980afb1b7c041ac43d5d1bf0 (diff) |
Add various nature value layers.
Including k-skog, but we leave that one alone for now as the script
lacks some logic to process raster files.
Diffstat (limited to 'import_source.py')
-rw-r--r-- | import_source.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/import_source.py b/import_source.py index 13a8e6c..16284b9 100644 --- a/import_source.py +++ b/import_source.py @@ -758,6 +758,15 @@ def _importSource2(lyr_dst : ogr.Layer, path : str, args : dict[str,Any], if nullReplacement is not None or len(mapping) > 0: valueMap.append( (i, nullReplacement, mapping) ) + if args.get('rstrip-strings', False): + stringFieldsIdx = [ i for i in range(fieldCount) + if defn.GetFieldDefn(i).GetType() == ogr.OFTString and + fieldMap[i] >= 0 ] + logging.debug('Source field indices to rstrip: %s', str(stringFieldsIdx)) + bStringFields = len(stringFieldsIdx) > 0 + else: + bStringFields = False + bValueMap = len(valueMap) > 0 defn = None @@ -774,6 +783,12 @@ def _importSource2(lyr_dst : ogr.Layer, path : str, args : dict[str,Any], mismatch = {} feature = lyr.GetNextFeature() while feature is not None: + if bStringFields: + for i in stringFieldsIdx: + if feature.IsFieldSetAndNotNull(i): + v = feature.GetField(i) + feature.SetField(i, v.rstrip()) + if bValueMap: for i, nullReplacement, mapping in valueMap: if not feature.IsFieldSet(i): |