aboutsummaryrefslogtreecommitdiffstats
path: root/gis-observation-map
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2023-10-02 17:50:37 +0200
committerGuilhem Moulin <guilhem@fripost.org>2023-10-03 01:47:33 +0200
commit746eb3900573972afe8598b0606cc223b8928b79 (patch)
treeb137192aec9c2032f6bc90c118565c3a4b5f27dd /gis-observation-map
parent6f47f3fe2a2f07955fb9f9a3e38213bdf8e049eb (diff)
Use .UnionCascaded() to compute union.
Diffstat (limited to 'gis-observation-map')
-rwxr-xr-xgis-observation-map18
1 files changed, 8 insertions, 10 deletions
diff --git a/gis-observation-map b/gis-observation-map
index e9cda7f..9c58b8e 100755
--- a/gis-observation-map
+++ b/gis-observation-map
@@ -244,7 +244,7 @@ def idx_intersects(idx_path, source_geometry):
locFieldIdx = layer.FindFieldIndex('location', True)
locations = []
- union = None
+ union = ogr.Geometry(ogr.wkbMultiPolygon)
feature = layer.GetNextFeature()
while feature is not None:
geometry = feature.GetGeometryRef()
@@ -252,13 +252,10 @@ def idx_intersects(idx_path, source_geometry):
if geometry.Intersects(source_geometry):
loc = feature.GetField(locFieldIdx)
locations.append(loc)
- if union is None:
- union = geometry.Clone()
- else:
- union = union.Union(geometry)
+ union.AddGeometry(geometry)
feature = layer.GetNextFeature()
- contains = union.Contains(source_geometry)
+ contains = union.UnionCascaded().Contains(source_geometry)
ds = None
return locations, contains
@@ -293,7 +290,7 @@ for pt in args.point:
bbox = ogr.Geometry(ogr.wkbPolygon)
bbox.AddGeometry(ring)
- clipGeometry = clipGeometry.Union(bbox)
+ clipGeometry.AddGeometry(bbox)
for geom in args.geometry:
ds = ogr.Open(geom['path'].as_posix(), update=0)
@@ -331,22 +328,23 @@ for geom in args.geometry:
bbox = ogr.Geometry(ogr.wkbPolygon)
bbox.AddGeometry(ring)
- clipGeometry = clipGeometry.Union(bbox)
+ clipGeometry.AddGeometry(bbox)
elif geometryType == ogr.wkbPoint or geometryType == ogr.wkbMultiPoint:
parser.error('Point geometry requires positive --margin')
elif geometryType == ogr.wkbLineString or geometryType == ogr.wkbMultiLineString:
parser.error('Line geometry requires positive --margin')
elif geometryType == ogr.wkbPolygon:
- clipGeometry = clipGeometry.Union(geometry)
+ clipGeometry.AddGeometry(geometry)
elif geometryType == ogr.wkbMultiPolygon:
for i in range(geometry.GetGeometryCount()):
geom2 = geometry.GetGeometryRef(i)
- clipGeometry = clipGeometry.Union(geom2)
+ clipGeometry.AddGeometry(geom2)
else:
raise Exception('Unsuported geometry (try --margin=0)')
feature = layer.GetNextFeature()
+clipGeometry = clipGeometry.UnionCascaded()
if not clipGeometry.IsValid():
raise Exception('Invalid geometry')