Commit dc807658 authored by Matthias Betz's avatar Matthias Betz
Browse files

Merge branch 'master' of transfer.hft-stuttgart.de:circulargreensimcity/circulargreensimcity

parents eb6b5464 07eab64d
folium==0.15.1
kdtree==0.16
matplotlib==3.7.2
numpy==1.24.3
overpy==0.7
pyproj==3.6.1
Shapely==2.0.2
from dataclasses import dataclass
from collections import UserList
import kdtree
@dataclass
class Tree:
x: float
y: float
diameter: float
height: float
z: float = 0
trunk_diameter: float = None
type: str = None
description: str = '?'
source: str = '?'
color: str = 'green'
def __len__(self):
return 2 # x & y
def __getitem__(self, i):
return [self.x, self.y][i]
@property
def radius(self):
return self.diameter / 2
def __str__(self):
return f"{self.type} ({self.description}), {self.radius} m radius, {self.height} m height, (X={self.x:.1f}, Y={self.y:.1f})"
class Forest(UserList):
def __init__(self, existing_trees=[]):
if existing_trees:
self.kd_tree = kdtree.create(existing_trees, dimensions=2)
else:
self.kd_tree = kdtree.create([(0, 0)], dimensions=2)
self.data = existing_trees
def add_tree_if_possible(self, min_distance_2, x, y, **kparams):
_nearest_tree, distance_2 = self.kd_tree.search_nn((x, y))
if distance_2 > min_distance_2:
self.kd_tree.add((x, y))
self.append(Tree(x, y, **kparams))
@property
def xs_ys_cs(self):
xs, ys, colors = [], [], []
for tree in self:
xs.append(tree.x)
ys.append(tree.y)
colors.append(tree.color)
return xs, ys, colors
def __str__(self):
return f"Forest with {len(self)} trees."
def __repr__(self):
return "\n".join([str(self)] + [str(tree) for tree in self])
...@@ -7,7 +7,7 @@ if the server updates the values. The cache is stored in the file 'bafg_cache.sq ...@@ -7,7 +7,7 @@ if the server updates the values. The cache is stored in the file 'bafg_cache.sq
Usage: Usage:
python .\get_values_from_hag.py --help python get_values_from_hag.py --help
usage: get_values_from_hag.py [-h] [--lat LAT] [--lon LON] [--name NAME] usage: get_values_from_hag.py [-h] [--lat LAT] [--lon LON] [--name NAME]
[--layers LAYERS [LAYERS ...]] [--tree] [--layers LAYERS [LAYERS ...]] [--tree]
...@@ -24,7 +24,7 @@ Usage: ...@@ -24,7 +24,7 @@ Usage:
Show the layers tree: Show the layers tree:
python .\get_values_from_hag.py --tree python get_values_from_hag.py --tree
BfG Hydrologischer Atlas Deutschland BfG Hydrologischer Atlas Deutschland
├── Teil 1: Grundlagen (id = 0) ├── Teil 1: Grundlagen (id = 0)
│ ├── 1.1 Orohydrographie (id = 1) │ ├── 1.1 Orohydrographie (id = 1)
...@@ -59,11 +59,11 @@ Specify desired layers by id or by name: ...@@ -59,11 +59,11 @@ Specify desired layers by id or by name:
Value: 92 mm Value: 92 mm
""" """
import json import json
import requests
import requests_cache
from pyproj import Transformer
import re import re
import argparse import argparse
from pyproj import Transformer
import requests
import requests_cache
# Those constants can also be overwritten by command line arguments. # Those constants can also be overwritten by command line arguments.
...@@ -139,6 +139,7 @@ def download_tree(url): ...@@ -139,6 +139,7 @@ def download_tree(url):
def get_json(url): def get_json(url):
# TODO: Server somehows requires some time to startup. Ping bafg.de first, and try 3 times at most, with a sleep inbetween?
response = requests.get(url, timeout=TIMEOUT) response = requests.get(url, timeout=TIMEOUT)
text = response.content text = response.content
data = json.loads(text) data = json.loads(text)
...@@ -193,7 +194,8 @@ if __name__ == "__main__": ...@@ -193,7 +194,8 @@ if __name__ == "__main__":
parser.add_argument('--lat', type=float, default=EXAMPLE_LAT, help='Latitude') parser.add_argument('--lat', type=float, default=EXAMPLE_LAT, help='Latitude')
parser.add_argument('--lon', type=float, default=EXAMPLE_LON, help='Longitude') parser.add_argument('--lon', type=float, default=EXAMPLE_LON, help='Longitude')
parser.add_argument('--name', type=str, default=EXAMPLE_LOCATION, help='Location name') parser.add_argument('--name', type=str, default=EXAMPLE_LOCATION, help='Location name')
parser.add_argument('--layers', type=str, nargs='+', default=EXAMPLES_LAYERS, help='Layers to download') parser.add_argument('--layers', type=str, nargs='+',
default=EXAMPLES_LAYERS, help='Layers to download')
parser.add_argument('--tree', action='store_true', help='Display the tree of layers?') parser.add_argument('--tree', action='store_true', help='Display the tree of layers?')
args = parser.parse_args() args = parser.parse_args()
main(args.lat, args.lon, args.name, args.layers, args.tree) main(args.lat, args.lon, args.name, args.layers, args.tree)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment