• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mthh / routingpy / 19018276231

02 Nov 2025 09:17PM UTC coverage: 88.943%. First build
19018276231

Pull #150

github

web-flow
Merge e90838d9f into eb20b436a
Pull Request #150: feat: add geotiff support valhalla isochrones

9 of 9 new or added lines in 1 file covered. (100.0%)

1649 of 1854 relevant lines covered (88.94%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.77
/routingpy/expansion.py
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2021 GIS OPS UG
3
#
4
#
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
# use this file except in compliance with the License. You may obtain a copy of
7
# the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations under
15
# the License.
16
#
17
"""
18
:class:`Expansion` returns expansion results.
19
"""
20
from typing import List, Optional, Tuple, Union
1✔
21

22

23
class Edge:
1✔
24
    """
25
    Contains a parsed single line string of an edge and its attributes, if specified in the request.
26
    Access via properties ``geometry``, ``distance`` ``duration``, ``cost``, ``edge_id``,
27
    ``pred_edge_id``, ``edge_status``.
28
    """
29

30
    def __init__(
1✔
31
        self,
32
        geometry=None,
33
        distance=None,
34
        duration=None,
35
        cost=None,
36
        edge_id=None,
37
        pred_edge_id=None,
38
        edge_status=None,
39
    ):
40
        self._geometry = geometry
1✔
41
        self._distance = distance
1✔
42
        self._duration = duration
1✔
43
        self._cost = cost
1✔
44
        self._edge_id = edge_id
1✔
45
        self._pred_edge_id = pred_edge_id
1✔
46
        self._status = edge_status
1✔
47

48
    @property
1✔
49
    def geometry(self) -> Optional[List[List[float]]]:
1✔
50
        """
51
        The geometry of the edge as [[lon1, lat1], [lon2, lat2]] list.
52

53
        :rtype: list or None
54
        """
55
        return self._geometry
×
56

57
    @property
1✔
58
    def distance(self) -> Optional[int]:
1✔
59
        """
60
        The accumulated distance in meters for the edge in order of graph traversal.
61

62
        :rtype: int or None
63
        """
64
        return self._distance
×
65

66
    @property
1✔
67
    def duration(self) -> Optional[int]:
1✔
68
        """
69
        The accumulated duration in seconds for the edge in order of graph traversal.
70

71
        :rtype: int or None
72
        """
73
        return self._duration
×
74

75
    @property
1✔
76
    def cost(self) -> Optional[int]:
1✔
77
        """
78
        The accumulated cost for the edge in order of graph traversal.
79

80
        :rtype: int or None
81
        """
82
        return self._cost
×
83

84
    @property
1✔
85
    def edge_id(self) -> Optional[int]:
1✔
86
        """
87
        The internal edge IDs for each edge in order of graph traversal.
88

89
        :rtype: int or None
90
        """
91
        return self._edge_id
×
92

93
    @property
1✔
94
    def pred_edge_id(self) -> Optional[int]:
1✔
95
        """
96
        The predecessor edge IDs for each edge in order of graph traversal.
97

98
        :rtype: int or None
99
        """
100
        return self._pred_edge_id
×
101

102
    @property
1✔
103
    def status(self) -> Optional[str]:
1✔
104
        """
105
        The edge states for each edge in order of graph traversal.
106
        Can be one of "r" (reached), "s" (settled), "c" (connected).
107

108
        :rtype: str or None
109
        """
110
        return self._status
×
111

112
    def __repr__(self):  # pragma: no cover
113
        return "Edge({})".format(", ".join([f"{k[1:]}: {v}" for k, v in vars(self).items() if v]))
114

115

116
class Expansions:
1✔
117
    """
118
    Contains a list of :class:`Edge`, which can be iterated over or accessed by index. The property ΒΈ`raw`` contains
119
    the complete raw response of the expansion request.
120
    """
121

122
    def __init__(
1✔
123
        self,
124
        edges: Optional[List[Edge]] = None,
125
        center: Optional[Union[List[float], Tuple[float]]] = None,
126
        interval_type: Optional[str] = None,
127
        raw: Optional[dict] = None,
128
    ):
129
        self._edges = edges
1✔
130
        self._center = center
1✔
131
        self._interval_type = interval_type
1✔
132
        self._raw = raw
1✔
133

134
    @property
1✔
135
    def raw(self) -> Optional[dict]:
1✔
136
        """
137
        Returns the expansion's raw, unparsed response. For details, consult the documentation
138
         at https://valhalla.readthedocs.io/en/latest/api/expansion/api-reference/.
139

140
        :rtype: dict or None
141
        """
142
        return self._raw
1✔
143

144
    @property
1✔
145
    def center(self) -> Optional[Union[List[float], Tuple[float]]]:
1✔
146
        """
147
        The center coordinate in [lon, lat] of the expansion, which is the location from the user input.
148

149
        :rtype: list of float or None
150
        """
151
        return self._center
1✔
152

153
    @property
1✔
154
    def interval_type(self) -> Optional[str]:
1✔
155
        """
156
        Was it based on 'distance' or 'time'?
157

158
        :return: str or None
159
        """
160
        return self._interval_type
1✔
161

162
    def __repr__(self):  # pragma: no cover
163
        if len(self._edges) < 10:
164
            return "Expansions({}, {})".format(self._edges, self.raw)
165
        else:
166
            return "Expansions({}, ..., {})".format(
167
                ", ".join([str(e) for e in self._edges[:3]]),
168
                ", ".join(str(e) for e in self._edges[-3:]),
169
            )
170

171
    def __getitem__(self, item):
1✔
172
        return self._edges[item]
×
173

174
    def __iter__(self):
1✔
175
        return iter(self._edges)
×
176

177
    def __len__(self):
1✔
178
        return len(self._edges)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc