aboutsummaryrefslogtreecommitdiffstats
path: root/list-observations
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2023-10-23 22:24:31 +0200
committerGuilhem Moulin <guilhem@fripost.org>2023-10-23 22:24:31 +0200
commitdb1d23c1a4286fc3b78acac436a82b4eecb32b5b (patch)
tree96cf830962af7853da07bfccb6d15f99477a9f34 /list-observations
parent0070da1fc157bf8bf9f2703bea5505843c39bde6 (diff)
list-observations: Fix usage without --geometry.
Diffstat (limited to 'list-observations')
-rwxr-xr-xlist-observations88
1 files changed, 44 insertions, 44 deletions
diff --git a/list-observations b/list-observations
index be8961f..0a9764c 100755
--- a/list-observations
+++ b/list-observations
@@ -114,53 +114,53 @@ for k in ['since', 'until']:
setattr(args, k, d)
geometry = None
-for path in args.geometry:
- path = path.as_posix()
- ds = ogr.Open(path, update=0)
-
- layer = None
- for i in range(ds.GetLayerCount()):
- lyr = ds.GetLayerByIndex(i)
- if lyr.GetGeomType() in [ogr.wkbPolygon,
- ogr.wkbMultiPolygon,
- ogr.wkbPolygonM,
- ogr.wkbMultiPolygonM,
- ogr.wkbPolygonZM,
- ogr.wkbMultiPolygonZM,
- ogr.wkbPolygon25D,
- ogr.wkbMultiPolygon25D]:
- layer = lyr
- break
- if layer is None:
- raise Exception(f'{path}: does not have any layer of geometry type Polygon')
-
- source_srs = layer.GetSpatialRef()
- transform_srs = osr.CoordinateTransformation(source_srs, target_srs)
+if args.geometry is not None:
+ for path in args.geometry:
+ path = path.as_posix()
+ ds = ogr.Open(path, update=0)
+
+ layer = None
+ for i in range(ds.GetLayerCount()):
+ lyr = ds.GetLayerByIndex(i)
+ if lyr.GetGeomType() in [ogr.wkbPolygon,
+ ogr.wkbMultiPolygon,
+ ogr.wkbPolygonM,
+ ogr.wkbMultiPolygonM,
+ ogr.wkbPolygonZM,
+ ogr.wkbMultiPolygonZM,
+ ogr.wkbPolygon25D,
+ ogr.wkbMultiPolygon25D]:
+ layer = lyr
+ break
+ if layer is None:
+ raise Exception(f'{path}: does not have any layer of geometry type Polygon')
+
+ source_srs = layer.GetSpatialRef()
+ transform_srs = osr.CoordinateTransformation(source_srs, target_srs)
- feature = layer.GetNextFeature()
- while feature is not None:
- geom = feature.GetGeometryRef()
- geom = geom.Clone()
- geom.FlattenTo2D()
- geom.Transform(transform_srs)
-
- if geometry is None:
- geometry = ogr.Geometry(ogr.wkbMultiPolygon)
-
- geometryType = geom.GetGeometryType()
- if geometryType == ogr.wkbPolygon:
- geometry.AddGeometry(geom)
- elif geometryType == ogr.wkbMultiPolygon:
- for i in range(geom.GetGeometryCount()):
- geom2 = geom.GetGeometryRef(i)
- geometry.AddGeometry(geom2)
- else:
- raise Exception(f'Unsuported geometry {geometryType}')
feature = layer.GetNextFeature()
- layer = None
- ds = None
+ while feature is not None:
+ geom = feature.GetGeometryRef()
+ geom = geom.Clone()
+ geom.FlattenTo2D()
+ geom.Transform(transform_srs)
+
+ if geometry is None:
+ geometry = ogr.Geometry(ogr.wkbMultiPolygon)
+
+ geometryType = geom.GetGeometryType()
+ if geometryType == ogr.wkbPolygon:
+ geometry.AddGeometry(geom)
+ elif geometryType == ogr.wkbMultiPolygon:
+ for i in range(geom.GetGeometryCount()):
+ geom2 = geom.GetGeometryRef(i)
+ geometry.AddGeometry(geom2)
+ else:
+ raise Exception(f'Unsuported geometry {geometryType}')
+ feature = layer.GetNextFeature()
+ layer = None
+ ds = None
-if geometry is not None:
geometry = geometry.UnionCascaded()