Merge pull request 'master' (#283) from master into Docker
Reviewed-on: SGD-Nord/konova#283pull/380/head
commit
74a70e159c
@ -0,0 +1,11 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 14.12.22
|
||||
|
||||
"""
|
||||
|
||||
base_url = "http://127.0.0.1:8002"
|
||||
auth_header = "auth"
|
||||
auth_header_token = "CHANGE_ME"
|
@ -0,0 +1,59 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 14.12.22
|
||||
|
||||
"""
|
||||
import json
|
||||
from json import JSONDecodeError
|
||||
|
||||
import requests
|
||||
|
||||
from konova.sub_settings import schneider_settings
|
||||
|
||||
|
||||
class ParcelFetcher:
|
||||
base_url = schneider_settings.base_url
|
||||
auth_header = schneider_settings.auth_header
|
||||
auth_header_token = schneider_settings.auth_header_token
|
||||
|
||||
geometry = None
|
||||
geojson = None
|
||||
results = None
|
||||
|
||||
def __init__(self, geometry):
|
||||
if geometry is None:
|
||||
raise AssertionError("Geometry must not be none")
|
||||
self.geometry = geometry
|
||||
|
||||
# Reduce size of geometry to avoid "intersections" because of exact border matching
|
||||
geom = geometry.geom.buffer(-0.001)
|
||||
self.geojson = geom.ewkt
|
||||
self.results = []
|
||||
|
||||
def get_parcels(self, url: str = None):
|
||||
post_url = url
|
||||
if post_url is None:
|
||||
post_url = f"{self.base_url}/parcel/intersect/"
|
||||
|
||||
response = requests.post(
|
||||
url=post_url,
|
||||
data=self.geojson,
|
||||
headers={
|
||||
self.auth_header: self.auth_header_token
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
content = json.loads(response.content.decode("utf-8"))
|
||||
except JSONDecodeError:
|
||||
content = {}
|
||||
next = content.get("next", None)
|
||||
fetched_parcels = content.get("results", [])
|
||||
self.results += fetched_parcels
|
||||
|
||||
if next:
|
||||
self.get_parcels(next)
|
||||
|
||||
return self.results
|
Loading…
Reference in New Issue