|
| 1 | +from shapely.geometry import Polygon |
| 2 | +import requests |
| 3 | +import pandas as pd |
| 4 | + |
| 5 | +NADAG_URL = "https://ogcapitest.ngu.no/rest/services/grunnundersokelser_utvidet" |
| 6 | + |
| 7 | + |
| 8 | +def get_nadag_geotekniskborehull(): |
| 9 | + url = f"{NADAG_URL}/collections/geotekniskborehull/items" |
| 10 | + return url |
| 11 | + |
| 12 | + |
| 13 | +def _calculate_bbox_from_polygon(polygon: Polygon) -> str: |
| 14 | + """ |
| 15 | + Calculate the bounding box from a Polygon object. |
| 16 | + """ |
| 17 | + x_min, y_min, x_max, y_max = polygon.bounds |
| 18 | + return f"{x_min},{y_min},{x_max},{y_max}" |
| 19 | + |
| 20 | + |
| 21 | +def fetch_geotechnical_borehole_data( |
| 22 | + polygon_lon_lat: Polygon, |
| 23 | + bbox_crs="http://www.opengis.net/def/crs/OGC/1.3/CRS84", |
| 24 | + crs="http://www.opengis.net/def/crs/OGC/1.3/CRS84", |
| 25 | + filter_crs="http://www.opengis.net/def/crs/OGC/1.3/CRS84", |
| 26 | + filter_lang="cql2-text", |
| 27 | + limit=100, |
| 28 | + max_allowable_offset=0.05, |
| 29 | + offset=0, |
| 30 | + skip_geometry=False, |
| 31 | +): |
| 32 | + url = f"{NADAG_URL}/collections/geotekniskborehullunders/items" |
| 33 | + params = { |
| 34 | + "bbox": _calculate_bbox_from_polygon(polygon_lon_lat), |
| 35 | + "bbox-crs": bbox_crs, |
| 36 | + "crs": crs, |
| 37 | + "filter-crs": filter_crs, |
| 38 | + "filter-lang": filter_lang, |
| 39 | + "limit": limit, |
| 40 | + "maxAllowableOffset": max_allowable_offset, |
| 41 | + "offset": offset, |
| 42 | + "skipGeometry": str(skip_geometry).lower(), |
| 43 | + } |
| 44 | + |
| 45 | + response = requests.get(url, params=params) |
| 46 | + response.raise_for_status() |
| 47 | + return response.json() |
| 48 | + |
| 49 | + |
| 50 | +url = f"{NADAG_URL}/collections/geotekniskborehullunders/items" |
| 51 | +bbox_crs = ("http://www.opengis.net/def/crs/OGC/1.3/CRS84",) |
| 52 | +crs = ("http://www.opengis.net/def/crs/OGC/1.3/CRS84",) |
| 53 | +filter_crs = ("http://www.opengis.net/def/crs/OGC/1.3/CRS84",) |
| 54 | +filter_lang = ("cql2-text",) |
| 55 | +limit = (100,) |
| 56 | +max_allowable_offset = (0.05,) |
| 57 | +offset = (0,) |
| 58 | +skip_geometry = False |
| 59 | + |
| 60 | + |
| 61 | +params = { |
| 62 | + "bbox": "10,59,10.02,59.2", |
| 63 | + "bbox-crs": bbox_crs, |
| 64 | + "crs": crs, |
| 65 | + "filter-crs": filter_crs, |
| 66 | + "filter-lang": filter_lang, |
| 67 | + "limit": limit, |
| 68 | + "maxAllowableOffset": max_allowable_offset, |
| 69 | + "offset": offset, |
| 70 | + "skipGeometry": str(skip_geometry).lower(), |
| 71 | +} |
| 72 | + |
| 73 | +url_tolketlag = f"{NADAG_URL}/collections/geoteknisktolketlag/items" |
| 74 | +url_grunnvann = f"{NADAG_URL}/collections/grunnvanndata/items" |
| 75 | +# denne inneholder d meste av dataen |
| 76 | +url_geotekniskborehull = f"{NADAG_URL}/collections/geotekniskborehullunders/items" |
| 77 | +# url_geotekniskborehull= f"{NADAG_URL}/collections/geotekniskborehull/items" |
| 78 | +# mulig nederste er bedre her faktiks inneholder kvikkleirePåvisning, boretlengde etc |
| 79 | +# må sjekke om det er noe som mangler |
| 80 | +response = requests.get(url_geotekniskborehull, params=params) |
| 81 | +response.raise_for_status() |
| 82 | +data = response.json() |
| 83 | +features = data.get("features", []) |
| 84 | +data_geometry = features[0].get("geometry", {}) |
| 85 | +data_prop = features[0].get("properties", {}) |
| 86 | +method = data_prop.get("geotekniskMetode", None) |
| 87 | +methods = {"15": "metode-KombinasjonSondering"} |
| 88 | +method_data = data_prop[methods.get(method, "")] |
| 89 | +id = method_data[0]["title"] |
| 90 | +href = method_data[0]["href"] |
| 91 | +method_url = ( |
| 92 | + f"{NADAG_URL}/collections/kombinasjonsonderingdata/items?kombinasjonSondering={id}" |
| 93 | +) |
| 94 | +r = requests.get(method_url) |
| 95 | +r.raise_for_status() |
| 96 | + |
| 97 | +data_method = r.json() |
| 98 | +features_method = data_method.get("features", []) |
| 99 | +get_properties = [properties.get("properties", {}) for properties in features_method] |
| 100 | +dataframe = pd.DataFrame(get_properties) |
0 commit comments