-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathvector.py
More file actions
29 lines (20 loc) · 826 Bytes
/
vector.py
File metadata and controls
29 lines (20 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from pathlib import Path
from osgeo import ogr
ogr.UseExceptions()
def get_features(vector_path: str | Path) -> list[ogr.Feature]:
ds = ogr.Open(str(vector_path))
layer = ds.GetLayer()
return [feature for feature in layer]
def get_property_values_for_intersecting_features(geometry: ogr.Geometry, features: list[ogr.Feature]) -> bool:
for feature in features:
if feature.GetGeometryRef().Intersects(geometry):
return True
return False
def intersecting_feature_properties(
geometry: ogr.Geometry, features: list[ogr.Feature], feature_property: str
) -> list[str]:
property_values = []
for feature in features:
if feature.GetGeometryRef().Intersects(geometry):
property_values.append(feature.GetField(feature_property))
return property_values