Skip to content

Instantly share code, notes, and snippets.

@andreasnuesslein
Created June 25, 2024 18:21
Show Gist options
  • Save andreasnuesslein/d928cb575507e78d04f6b41866ac886e to your computer and use it in GitHub Desktop.
Save andreasnuesslein/d928cb575507e78d04f6b41866ac886e to your computer and use it in GitHub Desktop.
Breitbandatlas Query
import json
import math
import requests
from pyproj import Transformer
def __create_rough_circle_polygon(center, diameter=10, num_vertices=60):
"""
Create a rough circular polygon with a given diameter centered at the given coordinate.
:param center: A dictionary with 'x' and 'y' keys representing the center coordinate.
:param diameter: Diameter of the circle (default is 10 meters).
:param num_vertices: Number of vertices for the polygon (default is 60).
:return: A list of coordinates representing the vertices of the polygon.
"""
radius = diameter / 2.0
angle_step = 2 * math.pi / num_vertices
polygon = []
for i in range(num_vertices):
angle = i * angle_step
x = center[0] + radius * math.cos(angle)
y = center[1] + radius * math.sin(angle)
polygon.append([x, y])
return polygon
def __netzda_mig_state(poly):
params = {
"f": "json",
"resultOffset": "0",
"resultRecordCount": "200",
"where": "1=1",
"geometry": json.dumps({"rings": [poly]}),
"outFields": "*",
"outSR": "4326",
"spatialRel": "esriSpatialRelIntersects",
}
headers = {"referer": "https://webclient.eks.production.netzda-mig.org/"}
url = "https://buergerplattform-prod1.production.netzda-mig.org/server/rest/services/Hosted/mobilfunk_008/FeatureServer/0/query"
ret = requests.get(
url,
params=params,
headers=headers,
)
ret_json = ret.json()
return ret_json["features"]
# ic(ret.json())
def get_netzabdeckung(coords: [float, float]):
transformer = Transformer.from_crs(4326, 25832)
coords_25832 = transformer.transform(*coords)
poly = __create_rough_circle_polygon(coords_25832)
return __netzda_mig_state(poly)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment