pyvalhalla-git 3.5.1.post132__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- _valhalla.cp39-win_amd64.pyd +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/.load-order-pyvalhalla_git-3.5.1.post132 +20 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/Lerc-d4ff05a506ddcfc551c350aa718ab4da.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/abseil_dll-bdd8a5a1f5a4da3f67279509940f7994.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/gdal-e68c9d36ee94002182307d221cc91ce3.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/geos-b8640de6faf146d9855a807e72427e47.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/geos_c-7d79920a3a18ad2c1ff594fcef060f0a.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/geotiff-020296779aedd28fd03f34200e6e3c61.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/jpeg62-52d863f4f0f8139faf1608976c1d91f6.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/json-c-0d6db73c6075abe84a7bdd2a2d393471.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/libcurl-bfd466d47923540033e77b192031a728.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/libexpat-6da76b3644b9424613b6d75323fcdc82.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/liblzma-9b97b163f3fff34e786ef56c4f919383.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/libpng16-45e0d625267ecee5996170051645e533.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/libprotobuf-lite-2bea258fef20ab8f71dcb2fec86675a8.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/lz4-cb6b9d0ac653fc68b286ff6ba7ef9bf5.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/msvcp140-73e7ea186a7d9ab676a764ffa64cf7e6.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/proj_9-3a2a70c01b92ddd4e14ab2bc22e06ab7.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/qhull_r-46ecfc2e889bb30a2c3af738edb6eeb9.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/sqlite3-219685aef036100e03dd97e60c61281d.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/tiff-f8c8a1908722e0556fad08f0b5c1bb6f.dll +0 -0
- pyvalhalla_git-3.5.1.post132.data/platlib/zlib1-8425906e295d322425fe840dc45228db.dll +0 -0
- pyvalhalla_git-3.5.1.post132.dist-info/DELVEWHEEL +2 -0
- pyvalhalla_git-3.5.1.post132.dist-info/METADATA +137 -0
- pyvalhalla_git-3.5.1.post132.dist-info/RECORD +39 -0
- pyvalhalla_git-3.5.1.post132.dist-info/WHEEL +5 -0
- pyvalhalla_git-3.5.1.post132.dist-info/licenses/AUTHORS +5 -0
- pyvalhalla_git-3.5.1.post132.dist-info/licenses/COPYING +22 -0
- pyvalhalla_git-3.5.1.post132.dist-info/licenses/LICENSE.md +1 -0
- pyvalhalla_git-3.5.1.post132.dist-info/top_level.txt +2 -0
- valhalla/__init__.py +41 -0
- valhalla/__main__.py +72 -0
- valhalla/__version__.py +21 -0
- valhalla/_scripts.py +46 -0
- valhalla/_valhalla.cc +81 -0
- valhalla/actor.py +118 -0
- valhalla/config.py +45 -0
- valhalla/utils.py +62 -0
- valhalla/valhalla_build_config.py +760 -0
valhalla/actor.py
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
import json
|
2
|
+
import tempfile
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Union
|
5
|
+
|
6
|
+
try:
|
7
|
+
from ._valhalla import _Actor
|
8
|
+
except ModuleNotFoundError:
|
9
|
+
from _valhalla import _Actor
|
10
|
+
|
11
|
+
|
12
|
+
# TODO: wasteful for dict input/output; more reasonable would be to extend
|
13
|
+
# the Actor's action C++ interfaces with a JSON arg
|
14
|
+
def dict_or_str(func):
|
15
|
+
def wrapped(*args):
|
16
|
+
# /status doesn't take any parameters
|
17
|
+
if not len(args) > 1:
|
18
|
+
return func(*args)
|
19
|
+
|
20
|
+
if isinstance(args[1], dict):
|
21
|
+
return json.loads(func(args[0], json.dumps(args[1])))
|
22
|
+
elif not isinstance(args[1], str):
|
23
|
+
raise ValueError("Request must be either of type str or dict")
|
24
|
+
return func(*args)
|
25
|
+
|
26
|
+
return wrapped
|
27
|
+
|
28
|
+
|
29
|
+
class Actor(_Actor):
|
30
|
+
def __init__(self, config: Union[Path, str, dict]):
|
31
|
+
"""
|
32
|
+
Valhalla's Actor class is used to call its actions, like route, isochrone, matrix etc.
|
33
|
+
|
34
|
+
Configuration passed in either by an existing configuration JSON file path or in `dict` form,
|
35
|
+
e.g. by calling valhalla.config.get_config(). In the latter case a temp file will be
|
36
|
+
created.
|
37
|
+
|
38
|
+
For details on parameters for each function consult Valhalla's documentation:
|
39
|
+
https://github.com/valhalla/valhalla/blob/master/docs/api
|
40
|
+
"""
|
41
|
+
# make sure there's a valhalla.json file
|
42
|
+
if isinstance(config, dict):
|
43
|
+
with tempfile.NamedTemporaryFile(
|
44
|
+
"w", suffix=".json", prefix="valhalla_config_", delete=False
|
45
|
+
) as f:
|
46
|
+
json.dump(config, f)
|
47
|
+
self._config_path = f.name
|
48
|
+
elif isinstance(config, str):
|
49
|
+
if not Path(config).is_file():
|
50
|
+
raise FileNotFoundError(f"Valhalla JSON config file doesn't exist: {config}")
|
51
|
+
self._config_path = config
|
52
|
+
elif isinstance(config, Path):
|
53
|
+
self._config_path = str(config.resolve())
|
54
|
+
else:
|
55
|
+
raise AttributeError(f"Valhalla JSON config can't be of type {type(config)}")
|
56
|
+
|
57
|
+
# test if there's an extract or tile_dir
|
58
|
+
with open(self._config_path) as f:
|
59
|
+
config = json.load(f)
|
60
|
+
tile_extract_fp = config.get("mjolnir", {}).get("tile_extract")
|
61
|
+
tile_dir = config.get("mjolnir", {}).get("tile_dir")
|
62
|
+
|
63
|
+
# raise if neither exists
|
64
|
+
if not tile_extract_fp and not tile_dir:
|
65
|
+
raise AttributeError(
|
66
|
+
"Valhalla config JSON is not valid: mjolnir.tile_extract and mjolnir.tile_dir are missing."
|
67
|
+
)
|
68
|
+
if not Path(config["mjolnir"]["tile_extract"]).is_file():
|
69
|
+
if not Path(config["mjolnir"]["tile_dir"]).is_dir():
|
70
|
+
raise FileNotFoundError(
|
71
|
+
f"Neither mjolnir.tile_extract ({Path(tile_extract_fp).resolve()}) nor mjolnir.tile_dir ({Path(tile_dir).resolve()}) exists. Can't load graph."
|
72
|
+
)
|
73
|
+
|
74
|
+
super(Actor, self).__init__(self._config_path)
|
75
|
+
|
76
|
+
@dict_or_str
|
77
|
+
def route(self, req: Union[str, dict]):
|
78
|
+
return super().route(req)
|
79
|
+
|
80
|
+
@dict_or_str
|
81
|
+
def locate(self, req: Union[str, dict]):
|
82
|
+
return super().locate(req)
|
83
|
+
|
84
|
+
@dict_or_str
|
85
|
+
def isochrone(self, req: Union[str, dict]):
|
86
|
+
return super().isochrone(req)
|
87
|
+
|
88
|
+
@dict_or_str
|
89
|
+
def matrix(self, req: Union[str, dict]):
|
90
|
+
return super().matrix(req)
|
91
|
+
|
92
|
+
@dict_or_str
|
93
|
+
def trace_route(self, req: Union[str, dict]):
|
94
|
+
return super().trace_route(req)
|
95
|
+
|
96
|
+
@dict_or_str
|
97
|
+
def trace_attributes(self, req: Union[str, dict]):
|
98
|
+
return super().trace_attributes(req)
|
99
|
+
|
100
|
+
@dict_or_str
|
101
|
+
def height(self, req: Union[str, dict]):
|
102
|
+
return super().height(req)
|
103
|
+
|
104
|
+
@dict_or_str
|
105
|
+
def transit_available(self, req: Union[str, dict]):
|
106
|
+
return super().transit_available(req)
|
107
|
+
|
108
|
+
@dict_or_str
|
109
|
+
def expansion(self, req: Union[str, dict]):
|
110
|
+
return super().expansion(req)
|
111
|
+
|
112
|
+
@dict_or_str
|
113
|
+
def centroid(self, req: Union[str, dict]):
|
114
|
+
return super().centroid(req)
|
115
|
+
|
116
|
+
@dict_or_str
|
117
|
+
def status(self, req: Union[str, dict] = ""):
|
118
|
+
return super().status(req)
|
valhalla/config.py
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
from typing import Union, Dict
|
3
|
+
|
4
|
+
from .valhalla_build_config import config as default_config, Optional, help_text
|
5
|
+
|
6
|
+
|
7
|
+
def _sanitize_config(dict_: dict = None) -> dict:
|
8
|
+
"""remove the "Optional" values from the config."""
|
9
|
+
int_dict_ = dict_.copy()
|
10
|
+
for k, v in int_dict_.items():
|
11
|
+
if isinstance(v, Optional):
|
12
|
+
del dict_[k]
|
13
|
+
elif isinstance(v, dict):
|
14
|
+
_sanitize_config(v)
|
15
|
+
|
16
|
+
return dict_
|
17
|
+
|
18
|
+
|
19
|
+
def get_help() -> Dict[str, Union[Dict[str, str], str]]:
|
20
|
+
"""
|
21
|
+
Returns the help dictionary with the same keys as the config JSON.
|
22
|
+
"""
|
23
|
+
return help_text
|
24
|
+
|
25
|
+
|
26
|
+
def get_config(
|
27
|
+
tile_extract: Union[str, Path] = "valhalla_tiles.tar",
|
28
|
+
tile_dir: Union[str, Path] = "valhalla_tiles",
|
29
|
+
verbose: bool = False,
|
30
|
+
) -> dict:
|
31
|
+
"""
|
32
|
+
Returns a default Valhalla configuration.
|
33
|
+
|
34
|
+
:param tile_extract: The file path (with .tar extension) of the tile extract (mjolnir.tile_extract), if present. Preferred over tile_dir.
|
35
|
+
:param tile_dir: The directory path where the graph tiles are stored (mjolnir.tile_dir), if present.
|
36
|
+
:param verbose: Whether you want to see Valhalla's logs on stdout (mjolnir.logging). Default False.
|
37
|
+
"""
|
38
|
+
|
39
|
+
config = _sanitize_config(default_config.copy())
|
40
|
+
|
41
|
+
config["mjolnir"]["tile_dir"] = str(Path(tile_dir).resolve())
|
42
|
+
config["mjolnir"]["tile_extract"] = str(Path(tile_extract).resolve())
|
43
|
+
config["mjolnir"]["logging"]["type"] = "std_out" if verbose else ""
|
44
|
+
|
45
|
+
return config
|
valhalla/utils.py
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
from typing import List, Tuple
|
2
|
+
|
3
|
+
|
4
|
+
def decode_polyline(
|
5
|
+
polyline: str, precision: int = 6, order: str = "lnglat"
|
6
|
+
) -> List[Tuple[float, float]]:
|
7
|
+
"""Decodes an encoded ``polyline`` string with ``precision`` to a list of coordinate tuples.
|
8
|
+
The coordinate ``order`` of the output can be ``lnglat`` or ``latlng``."""
|
9
|
+
|
10
|
+
return _decode(polyline, precision=precision, order=order, is3d=False)
|
11
|
+
|
12
|
+
|
13
|
+
def _trans(value, index):
|
14
|
+
"""
|
15
|
+
Copyright (c) 2014 Bruno M. Custódio
|
16
|
+
Copyright (c) 2016 Frederick Jansen
|
17
|
+
https://github.com/hicsail/polyline/commit/ddd12e85c53d394404952754e39c91f63a808656
|
18
|
+
"""
|
19
|
+
byte, result, shift = None, 0, 0
|
20
|
+
|
21
|
+
while byte is None or byte >= 0x20:
|
22
|
+
byte = ord(value[index]) - 63
|
23
|
+
index += 1
|
24
|
+
result |= (byte & 0x1F) << shift
|
25
|
+
shift += 5
|
26
|
+
comp = result & 1
|
27
|
+
|
28
|
+
return ~(result >> 1) if comp else (result >> 1), index
|
29
|
+
|
30
|
+
|
31
|
+
def _decode(expression, precision=5, order="lnglat", is3d=False):
|
32
|
+
"""
|
33
|
+
Copyright (c) 2014 Bruno M. Custódio
|
34
|
+
Copyright (c) 2016 Frederick Jansen
|
35
|
+
https://github.com/hicsail/polyline/commit/ddd12e85c53d394404952754e39c91f63a808656
|
36
|
+
|
37
|
+
Modified to be able to work with 3D polylines and a specified coordinate order.
|
38
|
+
"""
|
39
|
+
coordinates, index, lat, lng, z, length, factor = (
|
40
|
+
[],
|
41
|
+
0,
|
42
|
+
0,
|
43
|
+
0,
|
44
|
+
0,
|
45
|
+
len(expression),
|
46
|
+
float(10**precision),
|
47
|
+
)
|
48
|
+
|
49
|
+
while index < length:
|
50
|
+
lat_change, index = _trans(expression, index)
|
51
|
+
lng_change, index = _trans(expression, index)
|
52
|
+
lat += lat_change
|
53
|
+
lng += lng_change
|
54
|
+
coord = (lat / factor, lng / factor) if order == "latlng" else (lng / factor, lat / factor)
|
55
|
+
if not is3d:
|
56
|
+
coordinates.append(coord)
|
57
|
+
else:
|
58
|
+
z_change, index = _trans(expression, index)
|
59
|
+
z += z_change
|
60
|
+
coordinates.append((*coord, z / 100))
|
61
|
+
|
62
|
+
return coordinates
|