Stops¶
Stops ¶
Stops(lf: Optional[LazyFrame] = None, gdf: Optional[GeoDataFrame] = None, stop_ids: Optional[List[str]] = None, mean_lon: Optional[float] = None, mean_lat: Optional[float] = None)
A class to manage GTFS stops using Polars LazyFrames and GeoPandas GeoDataFrames.
Provides functionality to:
- Read and optionally filter GTFS stops from one or more directories
- Filter stops by area of interest (AOI)
- Group stops spatially and assign parent_station values
Attributes:
| Name | Type | Description |
|---|---|---|
lf |
LazyFrame
|
LazyFrame containing GTFS stops. |
gdf |
GeoDataFrame
|
GeoDataFrame of stop_id and geometry. |
stop_ids |
list[str]
|
List of stop IDs currently loaded. |
paths |
List[Path]
|
List of GTFS paths (directories). |
Wraps already-loaded stops frames, or leaves them empty for load to fill in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lf
|
Optional[LazyFrame]
|
Optional pre-loaded |
None
|
gdf
|
Optional[GeoDataFrame]
|
Optional pre-built GeoDataFrame of |
None
|
stop_ids
|
Optional[List[str]]
|
Optional pre-computed list of in-scope |
None
|
mean_lon
|
Optional[float]
|
Optional mean stop longitude (used for e.g. holiday lookups elsewhere that need an approximate feed location). |
None
|
mean_lat
|
Optional[float]
|
Optional mean stop latitude. |
None
|
Source code in pyGTFSHandler/models/stops.py
load ¶
load(path: Union[str, Path, List[Union[str, Path]]], aoi: Union[GeoDataFrame, GeoSeries, None] = None, stop_group_distance: float = 0, stop_ids: Union[List[str], DataFrame | LazyFrame] = None, check_files: bool = False, min_file_id: int = 0, collision_registry=None)
Initialize Stops instance and load GTFS stops from one or more files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | list
|
One or more paths to GTFS directories. |
required |
aoi
|
GeoDataFrame | GeoSeries
|
Area of interest for spatial filtering. |
None
|
stop_ids
|
list[str]
|
List of stop IDs to include. |
None
|
Source code in pyGTFSHandler/models/stops.py
filter_by_aoi ¶
Filters stops by a given Area of Interest (AOI).
Performs: 1. Bounding box filter on LazyFrame (approximate). 2. Geometry-based intersection on GeoDataFrame (precise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
GeoDataFrame | GeoSeries
|
Area to filter stops within. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[LazyFrame, GeoDataFrame]
|
(filtered LazyFrame, filtered GeoDataFrame) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no stops are found within AOI. |
Source code in pyGTFSHandler/models/stops.py
group_stops ¶
Groups nearby stops by spatial proximity and assigns consistent parent_station values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
float
|
Max distance (in meters) for grouping. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If projection is missing or invalid. |
Source code in pyGTFSHandler/models/stops.py
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 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
reload_stops_lf ¶
reload_stops_lf(path: Union[str, Path, List[Union[str, Path]]], stop_ids: Optional[LazyFrame] = None, collision_registry=None) -> None
Re-reads stops.txt from path and replaces self.lf.
Used by Feed.load after stop_times.txt has been loaded, so that
stops referenced by in-scope stop_times but dropped by the earlier
AOI/stop_id filtering (e.g. a bordering trip's next stop just
outside the AOI) are brought back into self.lf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path, List[Union[str, Path]]]
|
One or more GTFS directory paths (str, Path, or a list of
either) to search for |
required |
stop_ids
|
Optional[LazyFrame]
|
Optional lazyframe/expression of |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None. |
Source code in pyGTFSHandler/models/stops.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |