-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphways.pyi
More file actions
513 lines (395 loc) · 13 KB
/
Copy pathgraphways.pyi
File metadata and controls
513 lines (395 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
"""
Type stubs for graphways -- the compiled Rust extension.
Geometry results are structured Python objects. Use ``to_geojson()`` when you
need serialized GeoJSON for Folium, GeoPandas, or web maps.
"""
from __future__ import annotations
# ---------------------------------------------------------------------------
# Result objects
# ---------------------------------------------------------------------------
class SnapResult:
"""Nearest-network-node snap diagnostics for coordinate-based operations."""
@property
def input_lat(self) -> float: ...
@property
def input_lon(self) -> float: ...
@property
def node_id(self) -> int: ...
@property
def node_lat(self) -> float: ...
@property
def node_lon(self) -> float: ...
@property
def distance_m(self) -> float: ...
def as_dict(self) -> dict[str, float | int]: ...
def __repr__(self) -> str: ...
class RouteResult:
"""Fastest route result with metrics, snap diagnostics, and GeoJSON export."""
@property
def coordinates(self) -> list[tuple[float, float]]: ...
@property
def cumulative_times_s(self) -> list[float]: ...
@property
def distance_m(self) -> float: ...
@property
def duration_s(self) -> float: ...
@property
def origin_snap(self) -> SnapResult: ...
@property
def destination_snap(self) -> SnapResult: ...
def as_dict(self) -> dict[str, object]: ...
def to_geojson(self) -> str:
"""Return this route as a GeoJSON ``Feature`` string."""
...
def __repr__(self) -> str: ...
class IsochroneResult:
"""One isochrone polygon for one travel-time threshold."""
@property
def minutes(self) -> float: ...
def as_dict(self) -> dict[str, object]: ...
def to_geojson(self) -> str:
"""Return this isochrone polygon as a GeoJSON geometry string."""
...
def __repr__(self) -> str: ...
class Poi:
"""OpenStreetMap point of interest returned by ``SpatialGraph.fetch_pois``."""
@property
def id(self) -> int: ...
@property
def lat(self) -> float: ...
@property
def lon(self) -> float: ...
@property
def tags(self) -> dict[str, str]: ...
def as_dict(self) -> dict[str, object]: ...
def __repr__(self) -> str: ...
class PoiCollection:
"""Collection of POIs with structured access and GeoJSON export."""
@property
def count(self) -> int: ...
@property
def pois(self) -> list[Poi]: ...
def as_dict(self) -> dict[str, object]: ...
def to_geojson(self) -> str:
"""Return POIs as a GeoJSON ``FeatureCollection`` string."""
...
def __len__(self) -> int: ...
def __repr__(self) -> str: ...
# ---------------------------------------------------------------------------
# Graph views
# ---------------------------------------------------------------------------
class ReachableGraph:
"""
Travel-time-labeled graph view produced by ``SpatialGraph.reachable``.
Cheap inspection methods operate on the parent graph plus reachable labels.
Constrained routing and isochrones materialize a bounded subgraph internally.
"""
@property
def max_time_s(self) -> float: ...
def node_count(self) -> int: ...
def edge_count(self) -> int: ...
def contains_node(self, node_id: int) -> bool: ...
def nearest_node(
self, lat: float, lon: float
) -> tuple[int, float, float] | None: ...
def travel_time_to_node_id(self, node_id: int) -> float | None: ...
def nodes(self) -> list[dict[str, float | int]]:
"""
Return reachable nodes with ``node_id``, ``lat``, ``lon``, and
``travel_time_s``.
"""
...
def nodes_geojson(self) -> str:
"""
Return reachable nodes as a GeoJSON ``FeatureCollection`` of points.
"""
...
def edges_geojson(self) -> str:
"""
Return edges whose source and target nodes are both reachable.
"""
...
def to_geojson(self) -> str:
"""
Return reachable nodes and edges in one GeoJSON ``FeatureCollection``.
"""
...
def isochrone(
self,
origin: tuple[float, float],
minutes: list[float],
max_snap_m: float | None = 100.0,
) -> list[IsochroneResult]:
"""
Compute isochrones within this reachable subgraph.
"""
...
def route(
self,
origin: tuple[float, float],
destination: tuple[float, float],
max_snap_m: float | None = 100.0,
) -> RouteResult:
"""
Find the fastest route constrained to this reachable subgraph.
"""
...
def __repr__(self) -> str: ...
class PrismGraph:
"""
Network-time prism produced by ``SpatialGraph.prism``.
Cheap inspection methods operate on the parent graph plus prism labels.
Constrained routing and isochrones materialize a bounded subgraph internally.
"""
@property
def max_time_s(self) -> float: ...
@property
def traversal_budget_s(self) -> float: ...
@property
def stop_time_s(self) -> float: ...
@property
def buffer_s(self) -> float: ...
@property
def direct_time_s(self) -> float: ...
def node_count(self) -> int: ...
def edge_count(self) -> int: ...
def contains_node(self, node_id: int) -> bool: ...
def nearest_node(
self, lat: float, lon: float
) -> tuple[int, float, float] | None: ...
def slack_at_node_id(self, node_id: int) -> float | None: ...
def nodes(self) -> list[dict[str, float | int]]:
"""
Return nodes with ``node_id``, ``lat``, ``lon``, ``inbound_time_s``,
``outbound_time_s``, and ``slack_s``.
"""
...
def nodes_geojson(self) -> str:
"""
Return prism nodes as a GeoJSON ``FeatureCollection`` of points.
"""
...
def edges_geojson(self) -> str:
"""
Return edges whose source and target nodes are both inside the prism.
"""
...
def to_geojson(self) -> str:
"""
Return prism nodes and edges in one GeoJSON ``FeatureCollection``.
"""
...
def slack_polygon(self, min_slack_s: float = 0.0) -> str | None:
"""
Build a GeoJSON polygon enclosing nodes with at least ``min_slack_s``.
"""
...
def slack_polygons(self, min_slack_values: list[float]) -> list[str | None]:
"""
Build one slack polygon per minimum-slack threshold.
"""
...
def isochrone(
self,
origin: tuple[float, float],
minutes: list[float],
max_snap_m: float | None = 100.0,
) -> list[IsochroneResult]:
"""
Compute isochrones constrained to this prism subgraph.
"""
...
def route(
self,
origin: tuple[float, float],
destination: tuple[float, float],
max_snap_m: float | None = 100.0,
) -> RouteResult:
"""
Find the fastest route constrained to this prism subgraph.
"""
...
def __repr__(self) -> str: ...
class SpatialGraph:
"""
A road-network graph loaded from OpenStreetMap.
Construct once with :meth:`from_place`, :meth:`from_pbf`, or :meth:`from_osm`.
Reuse the same object across multiple queries to avoid rebuilding the graph.
Attributes are read-only; all mutations happen inside Rust.
"""
@staticmethod
def from_pbf(
path: str,
network: str,
retain_all: bool = False,
) -> SpatialGraph:
"""
Load a local OSM PBF file into a reusable ``SpatialGraph``.
``network`` accepts ``"drive"``, ``"drive_service"``, ``"walk"``,
``"bike"``, ``"all"``, or ``"all_private"``.
"""
...
@staticmethod
def from_osm(
xml: str,
network: str,
retain_all: bool = False,
) -> SpatialGraph:
"""
Parse an OSM XML string into a reusable ``SpatialGraph``.
``network`` accepts ``"drive"``, ``"drive_service"``, ``"walk"``,
``"bike"``, ``"all"``, or ``"all_private"``.
"""
...
@staticmethod
def from_place(
place: str,
network: str,
max_dist: float | None = None,
retain_all: bool = False,
) -> SpatialGraph:
"""
Geocode a place name and build a reusable ``SpatialGraph`` around it.
``network`` accepts ``"drive"``, ``"drive_service"``, ``"walk"``,
``"bike"``, ``"all"``, or ``"all_private"``.
"""
...
def node_count(self) -> int:
"""Number of nodes in the graph."""
...
def edge_count(self) -> int:
"""Number of directed edges in the graph."""
...
def nearest_node(
self, lat: float, lon: float
) -> tuple[int, float, float] | None:
"""
Return ``(osm_id, lat, lon)`` for the node nearest to ``(lat, lon)``.
Uses the internal R-tree spatial index -- O(log n).
Returns ``None`` if the graph is empty.
"""
...
def isochrone(
self,
origin: tuple[float, float],
minutes: list[float],
max_snap_m: float | None = 100.0,
) -> list[IsochroneResult]:
"""
Compute isochrones from ``(lat, lon)`` using this graph.
Parameters
----------
origin:
``(lat, lon)`` origin coordinates.
minutes:
Travel-time thresholds in minutes.
Returns
-------
list[IsochroneResult]
One polygon result per time limit, in the same order as
``minutes``. Call ``to_geojson()`` when you need serialized
GeoJSON.
"""
...
def route(
self,
origin: tuple[float, float],
destination: tuple[float, float],
max_snap_m: float | None = 100.0,
) -> RouteResult:
"""
Find the fastest route between two coordinates using A*.
The network type (drive/walk/bike) is inherited from the ``SpatialGraph``.
Returns
-------
RouteResult
Structured result with ``distance_m``, ``duration_s``,
``coordinates``, ``cumulative_times_s``, and snap diagnostics.
"""
...
def fetch_pois(self, isochrone: IsochroneResult | str) -> PoiCollection:
"""
Fetch OSM points of interest within a given isochrone polygon.
Parameters
----------
isochrone:
An ``IsochroneResult`` from :meth:`isochrone`, or a GeoJSON
geometry string.
Returns
-------
str
Structured POI collection. Call ``to_geojson()`` for a GeoJSON
``FeatureCollection``.
"""
...
def snap_point(self, lat: float, lon: float) -> SnapResult | None:
"""
Return snap diagnostics for the nearest graph node to ``(lat, lon)``.
Use ``as_dict()`` if you need a plain dictionary.
"""
...
def reachable(
self,
origin: tuple[float, float],
minutes: float,
max_snap_m: float | None = 100.0,
) -> ReachableGraph:
"""
Compute one-sided reachability from ``(lat, lon)`` within ``minutes``.
"""
...
def prism(
self,
origin: tuple[float, float],
destination: tuple[float, float],
max_minutes: float,
stop_minutes: float = 0.0,
buffer_minutes: float = 0.0,
max_snap_m: float | None = 100.0,
) -> PrismGraph:
"""
Return the network-time prism for nodes that fit within:
``origin -> node -> destination + stop_minutes + buffer_minutes <= max_minutes``.
"""
...
def nodes_geojson(self) -> str:
"""
All graph nodes as a GeoJSON ``FeatureCollection`` of ``Point`` features.
Properties per feature: ``id``, ``lat``, ``lon``.
"""
...
def edges_geojson(self) -> str:
"""
All graph edges as a GeoJSON ``FeatureCollection`` of ``LineString`` features.
Properties per feature: ``highway``, ``length_m``, ``speed_kph``,
``drive_time_s``, ``walk_time_s``, ``bike_time_s``.
"""
...
def __repr__(self) -> str: ...
# ---------------------------------------------------------------------------
# Module-level functions
# ---------------------------------------------------------------------------
def geocode(place: str) -> tuple[float, float]:
"""
Convert a place name to ``(lat, lon)`` via the Nominatim API.
Parameters
----------
place:
Any Nominatim-supported query string (e.g. ``"Marienplatz, Munich, Germany"``).
Returns
-------
tuple[float, float]
``(latitude, longitude)``
"""
...
def cache_dir() -> str:
"""
Return the path to the on-disk XML cache directory.
Override the default by setting the ``GRAPHWAYS_CACHE_DIR`` environment variable.
"""
...
def clear_cache() -> None:
"""
Clear both the in-memory and on-disk XML caches.
"""
...