gtfs_kit 4.0.2__tar.gz → 5.0.0__tar.gz
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.
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/PKG-INFO +1 -1
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/__init__.py +1 -1
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/cleaners.py +0 -1
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/feed.py +4 -3
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/helpers.py +5 -3
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/miscellany.py +54 -62
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/routes.py +12 -4
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/shapes.py +6 -6
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/stops.py +12 -33
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/trips.py +2 -2
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/pyproject.toml +1 -1
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/setup.py +1 -1
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/LICENSE.txt +0 -0
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/README.rst +0 -0
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/calendar.py +0 -0
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/constants.py +0 -0
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/stop_times.py +0 -0
- {gtfs_kit-4.0.2 → gtfs_kit-5.0.0}/gtfs_kit/validators.py +0 -0
|
@@ -109,7 +109,7 @@ class Feed(object):
|
|
|
109
109
|
geometrize_stops,
|
|
110
110
|
build_geometry_by_stop,
|
|
111
111
|
stops_to_geojson,
|
|
112
|
-
|
|
112
|
+
get_stops_in_area,
|
|
113
113
|
map_stops,
|
|
114
114
|
)
|
|
115
115
|
from .stop_times import (
|
|
@@ -137,10 +137,11 @@ class Feed(object):
|
|
|
137
137
|
compute_feed_time_series,
|
|
138
138
|
create_shapes,
|
|
139
139
|
compute_bounds,
|
|
140
|
-
|
|
140
|
+
compute_convex_hull,
|
|
141
|
+
compute_centroid,
|
|
141
142
|
restrict_to_dates,
|
|
142
143
|
restrict_to_routes,
|
|
143
|
-
|
|
144
|
+
restrict_to_area,
|
|
144
145
|
compute_screen_line_counts,
|
|
145
146
|
)
|
|
146
147
|
from .validators import (
|
|
@@ -234,13 +234,15 @@ def is_not_null(df: pd.DataFrame, col_name: str) -> bool:
|
|
|
234
234
|
|
|
235
235
|
def get_utm_crs(lat: float, lon: float) -> Dict:
|
|
236
236
|
"""
|
|
237
|
-
Return a GeoPandas coordinate reference system (CRS)
|
|
237
|
+
Return a GeoPandas coordinate reference system (CRS) string
|
|
238
238
|
corresponding to the UTM projection appropriate to the given WGS84
|
|
239
239
|
latitude and longitude.
|
|
240
|
+
|
|
241
|
+
Code inspired by https://github.com/Turbo87/utm/issues/51.
|
|
240
242
|
"""
|
|
241
243
|
zone = utm.from_latlon(lat, lon)[2]
|
|
242
|
-
|
|
243
|
-
|
|
244
|
+
result = f"EPSG:326{zone:02d}" if lat >= 0 else f"EPSG:327{zone:02d}"
|
|
245
|
+
return result
|
|
244
246
|
|
|
245
247
|
def linestring_to_utm(linestring: sg.LineString) -> sg.LineString:
|
|
246
248
|
"""
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
Functions about miscellany.
|
|
3
3
|
"""
|
|
4
4
|
from collections import OrderedDict
|
|
5
|
-
import
|
|
6
|
-
from typing import List, Optional, Tuple, TYPE_CHECKING
|
|
5
|
+
from typing import List, Optional, TYPE_CHECKING
|
|
7
6
|
|
|
8
7
|
import pandas as pd
|
|
9
8
|
import numpy as np
|
|
10
9
|
import shapely.geometry as sg
|
|
11
|
-
import geopandas as
|
|
10
|
+
import geopandas as gp
|
|
12
11
|
|
|
13
12
|
from . import helpers as hp
|
|
14
13
|
from . import constants as cs
|
|
@@ -574,36 +573,37 @@ def create_shapes(feed: "Feed", *, all_trips: bool = False) -> "Feed":
|
|
|
574
573
|
return feed
|
|
575
574
|
|
|
576
575
|
|
|
577
|
-
def compute_bounds(feed: "Feed") ->
|
|
576
|
+
def compute_bounds(feed: "Feed", stop_ids: Optional[List[str]] = None) -> np.array:
|
|
578
577
|
"""
|
|
579
|
-
Return the
|
|
580
|
-
max latitude)
|
|
581
|
-
the
|
|
578
|
+
Return the bounding box (Numpy array [min longitude, min latitude, max longitude,
|
|
579
|
+
max latitude]) of the given Feed's stops or of the subset of stops
|
|
580
|
+
specified by the given stop IDs.
|
|
582
581
|
"""
|
|
583
|
-
|
|
584
|
-
return lons.min(), lats.min(), lons.max(), lats.max()
|
|
582
|
+
from .stops import geometrize_stops
|
|
585
583
|
|
|
584
|
+
return geometrize_stops(feed, stop_ids=stop_ids).total_bounds
|
|
586
585
|
|
|
587
|
-
|
|
586
|
+
|
|
587
|
+
def compute_convex_hull(
|
|
588
|
+
feed: "Feed", stop_ids: Optional[List[str]] = None
|
|
589
|
+
) -> sg.Polygon:
|
|
588
590
|
"""
|
|
589
|
-
Return a Shapely Polygon representing the convex hull
|
|
590
|
-
|
|
591
|
+
Return a convex hull (Shapely Polygon) representing the convex hull of the given
|
|
592
|
+
Feed's stops or of the subset of stops specified by the given stop IDs.
|
|
591
593
|
"""
|
|
592
|
-
|
|
593
|
-
|
|
594
|
+
from .stops import geometrize_stops
|
|
595
|
+
|
|
596
|
+
return geometrize_stops(feed, stop_ids=stop_ids).unary_union.convex_hull
|
|
594
597
|
|
|
595
598
|
|
|
596
|
-
def
|
|
599
|
+
def compute_centroid(feed: "Feed", stop_ids: Optional[List[str]] = None) -> sg.Point:
|
|
597
600
|
"""
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
respectively, a kind of center of the feed.
|
|
601
|
+
Return the centroid (Shapely Point) of the convex hull the given Feed's stops
|
|
602
|
+
or of the subset of stops specified by the given stop IDs.
|
|
601
603
|
"""
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
lat = s.stop_lat.mean()
|
|
606
|
-
return lon, lat
|
|
604
|
+
from .stops import geometrize_stops
|
|
605
|
+
|
|
606
|
+
return geometrize_stops(feed, stop_ids=stop_ids).unary_union.convex_hull.centroid
|
|
607
607
|
|
|
608
608
|
|
|
609
609
|
def restrict_to_dates(feed: "Feed", dates: List[str]) -> "Feed":
|
|
@@ -619,23 +619,22 @@ def restrict_to_dates(feed: "Feed", dates: List[str]) -> "Feed":
|
|
|
619
619
|
feed = feed.copy()
|
|
620
620
|
|
|
621
621
|
# Get every trip that is active on at least one of the dates
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
lambda x: x[[c for c in x.columns if c != "trip_id"]].sum(axis=1) > 0,
|
|
625
|
-
"trip_id",
|
|
626
|
-
]
|
|
627
|
-
except KeyError:
|
|
628
|
-
# No trips
|
|
622
|
+
trip_activity = feed.compute_trip_activity(dates)
|
|
623
|
+
if trip_activity.empty:
|
|
629
624
|
trip_ids = []
|
|
625
|
+
else:
|
|
626
|
+
trip_ids = trip_activity.loc[
|
|
627
|
+
lambda x: x.filter(dates).sum(axis=1) > 0, "trip_id",
|
|
628
|
+
]
|
|
630
629
|
|
|
631
630
|
# Slice trips
|
|
632
|
-
feed.trips = feed.trips.loc[lambda x: x.trip_id.isin(trip_ids)]
|
|
631
|
+
feed.trips = feed.trips.loc[lambda x: x.trip_id.isin(trip_ids)].copy()
|
|
633
632
|
|
|
634
633
|
# Slice routes
|
|
635
|
-
feed.routes = feed.routes.loc[lambda x: x.route_id.isin(feed.trips.route_id)]
|
|
634
|
+
feed.routes = feed.routes.loc[lambda x: x.route_id.isin(feed.trips.route_id)].copy()
|
|
636
635
|
|
|
637
636
|
# Slice stop times
|
|
638
|
-
feed.stop_times = feed.stop_times.loc[lambda x: x.trip_id.isin(trip_ids)]
|
|
637
|
+
feed.stop_times = feed.stop_times.loc[lambda x: x.trip_id.isin(trip_ids)].copy()
|
|
639
638
|
|
|
640
639
|
# Slice stops
|
|
641
640
|
stop_ids = feed.stop_times.stop_id.unique()
|
|
@@ -648,35 +647,39 @@ def restrict_to_dates(feed: "Feed", dates: List[str]) -> "Feed":
|
|
|
648
647
|
# Slice calendar
|
|
649
648
|
service_ids = feed.trips.service_id
|
|
650
649
|
if feed.calendar is not None:
|
|
651
|
-
feed.calendar = feed.calendar.loc[
|
|
650
|
+
feed.calendar = feed.calendar.loc[
|
|
651
|
+
lambda x: x.service_id.isin(service_ids)
|
|
652
|
+
].copy()
|
|
652
653
|
|
|
653
654
|
# Get agency for trips
|
|
654
655
|
if "agency_id" in feed.routes.columns:
|
|
655
656
|
agency_ids = feed.routes.agency_id
|
|
656
657
|
if len(agency_ids):
|
|
657
|
-
feed.agency = feed.agency.loc[lambda x: x.agency_id.isin(agency_ids)]
|
|
658
|
+
feed.agency = feed.agency.loc[lambda x: x.agency_id.isin(agency_ids)].copy()
|
|
658
659
|
|
|
659
660
|
# Now for the optional files.
|
|
660
661
|
# Get calendar dates for trips.
|
|
661
662
|
if feed.calendar_dates is not None:
|
|
662
663
|
feed.calendar_dates = feed.calendar_dates.loc[
|
|
663
|
-
lambda x: x.service_id.isin(service_ids)
|
|
664
|
-
]
|
|
664
|
+
lambda x: x.service_id.isin(service_ids) & x.date.isin(dates)
|
|
665
|
+
].copy()
|
|
665
666
|
|
|
666
667
|
# Get frequencies for trips
|
|
667
668
|
if feed.frequencies is not None:
|
|
668
|
-
feed.frequencies = feed.frequencies.loc[
|
|
669
|
+
feed.frequencies = feed.frequencies.loc[
|
|
670
|
+
lambda x: x.trip_id.isin(trip_ids)
|
|
671
|
+
].copy()
|
|
669
672
|
|
|
670
673
|
# Get shapes for trips
|
|
671
674
|
if feed.shapes is not None:
|
|
672
675
|
shape_ids = feed.trips.shape_id
|
|
673
|
-
feed.shapes = feed.shapes.loc[lambda x: x.shape_id.isin(shape_ids)]
|
|
676
|
+
feed.shapes = feed.shapes.loc[lambda x: x.shape_id.isin(shape_ids)].copy()
|
|
674
677
|
|
|
675
678
|
# Get transfers for stops
|
|
676
679
|
if feed.transfers is not None:
|
|
677
680
|
feed.transfers = feed.transfers.loc[
|
|
678
681
|
lambda x: x.from_stop_id.isin(stop_ids) & x.to_stop_id.isin(stop_ids)
|
|
679
|
-
]
|
|
682
|
+
].copy()
|
|
680
683
|
|
|
681
684
|
return feed
|
|
682
685
|
|
|
@@ -750,33 +753,22 @@ def restrict_to_routes(feed: "Feed", route_ids: List[str]) -> "Feed":
|
|
|
750
753
|
return feed
|
|
751
754
|
|
|
752
755
|
|
|
753
|
-
def
|
|
756
|
+
def restrict_to_area(feed: "Feed", area: gp.GeoDataFrame) -> "Feed":
|
|
754
757
|
"""
|
|
755
758
|
Build a new feed by restricting this one to only the trips
|
|
756
|
-
that have at least one stop intersecting the given
|
|
759
|
+
that have at least one stop intersecting the given GeoDataFrame of polygons,
|
|
757
760
|
then restricting stops, routes, stop times, etc. to those
|
|
758
761
|
associated with that subset of trips.
|
|
759
762
|
Return the resulting feed.
|
|
760
|
-
|
|
761
|
-
Requires GeoPandas.
|
|
762
|
-
|
|
763
|
-
Assume the following feed attributes are not ``None``:
|
|
764
|
-
|
|
765
|
-
- ``feed.stop_times``
|
|
766
|
-
- ``feed.trips``
|
|
767
|
-
- ``feed.stops``
|
|
768
|
-
- ``feed.routes``
|
|
769
|
-
- Those used in :func:`.stops.get_stops_in_polygon`
|
|
770
|
-
|
|
771
763
|
"""
|
|
772
|
-
|
|
773
|
-
|
|
764
|
+
from .stops import get_stops_in_area
|
|
765
|
+
|
|
774
766
|
feed = feed.copy()
|
|
775
767
|
|
|
776
768
|
# Get IDs of stops within the polygon
|
|
777
|
-
stop_ids = feed
|
|
769
|
+
stop_ids = get_stops_in_area(feed, area).stop_id
|
|
778
770
|
|
|
779
|
-
# Get all trips
|
|
771
|
+
# Get all trips with at least one of those stops
|
|
780
772
|
st = feed.stop_times.copy()
|
|
781
773
|
trip_ids = st.loc[lambda x: x.stop_id.isin(stop_ids), "trip_id"]
|
|
782
774
|
feed.trips = feed.trips.loc[lambda x: x.trip_id.isin(trip_ids)].copy()
|
|
@@ -837,7 +829,7 @@ def restrict_to_polygon(feed: "Feed", polygon: sg.Polygon) -> "Feed":
|
|
|
837
829
|
|
|
838
830
|
|
|
839
831
|
def compute_screen_line_counts(
|
|
840
|
-
feed: "Feed", screen_lines:
|
|
832
|
+
feed: "Feed", screen_lines: gp.GeoDataFrame, dates: List[str]
|
|
841
833
|
) -> pd.DataFrame:
|
|
842
834
|
"""
|
|
843
835
|
Find all the Feed trips active on the given YYYYMMDD dates whose shapes
|
|
@@ -906,13 +898,13 @@ def compute_screen_line_counts(
|
|
|
906
898
|
# Get intersection points of shapes and screen lines
|
|
907
899
|
g0 = (
|
|
908
900
|
# Only keep shapes that intersect screen lines to reduce computations
|
|
909
|
-
|
|
901
|
+
gp.sjoin(shapes_g, screen_lines.filter(["screen_line_id", "geometry"])).merge(
|
|
910
902
|
screen_lines, on="screen_line_id"
|
|
911
903
|
)
|
|
912
904
|
# Compute intersection points
|
|
913
905
|
.assign(
|
|
914
|
-
int_point=lambda x:
|
|
915
|
-
|
|
906
|
+
int_point=lambda x: gp.GeoSeries(x.geometry_x, crs=crs).intersection(
|
|
907
|
+
gp.GeoSeries(x.geometry_y, crs=crs)
|
|
916
908
|
)
|
|
917
909
|
)
|
|
918
910
|
)
|
|
@@ -934,7 +926,7 @@ def compute_screen_line_counts(
|
|
|
934
926
|
}
|
|
935
927
|
records.append(record)
|
|
936
928
|
|
|
937
|
-
g =
|
|
929
|
+
g = gp.GeoDataFrame.from_records(records)
|
|
938
930
|
g.crs = crs
|
|
939
931
|
|
|
940
932
|
# Get distance (in meters) of each intersection point along shape
|
|
@@ -5,7 +5,7 @@ from collections import OrderedDict
|
|
|
5
5
|
from typing import Optional, Iterable, List, Dict, TYPE_CHECKING
|
|
6
6
|
import json
|
|
7
7
|
|
|
8
|
-
import geopandas as
|
|
8
|
+
import geopandas as gp
|
|
9
9
|
import pandas as pd
|
|
10
10
|
import numpy as np
|
|
11
11
|
import shapely.geometry as sg
|
|
@@ -685,7 +685,7 @@ def geometrize_routes(
|
|
|
685
685
|
*,
|
|
686
686
|
use_utm: bool = False,
|
|
687
687
|
split_directions: bool = False,
|
|
688
|
-
) ->
|
|
688
|
+
) -> gp.GeoDataFrame:
|
|
689
689
|
"""
|
|
690
690
|
Given a Feed, return a GeoDataFrame with all the columns of ``feed.routes``
|
|
691
691
|
plus a geometry column of (Multi)LineStrings, each of which represents the
|
|
@@ -737,7 +737,7 @@ def geometrize_routes(
|
|
|
737
737
|
.apply(merge_lines)
|
|
738
738
|
.reset_index()
|
|
739
739
|
.merge(feed.routes)
|
|
740
|
-
.pipe(
|
|
740
|
+
.pipe(gp.GeoDataFrame, crs=crs)
|
|
741
741
|
)
|
|
742
742
|
|
|
743
743
|
|
|
@@ -816,7 +816,15 @@ def map_routes(
|
|
|
816
816
|
collection = feed.routes_to_geojson(
|
|
817
817
|
route_ids=[route_id], include_stops=include_stops
|
|
818
818
|
)
|
|
819
|
-
|
|
819
|
+
|
|
820
|
+
# Use route short name for group name if possible; otherwise use route ID
|
|
821
|
+
route_name = route_id
|
|
822
|
+
for f in collection["features"]:
|
|
823
|
+
if "route_short_name" in f["properties"]:
|
|
824
|
+
route_name = f["properties"]["route_short_name"]
|
|
825
|
+
break
|
|
826
|
+
|
|
827
|
+
group = fl.FeatureGroup(name=f"Route {route_name}")
|
|
820
828
|
color = colors[i]
|
|
821
829
|
|
|
822
830
|
for f in collection["features"]:
|
|
@@ -4,7 +4,7 @@ Functions about shapes.
|
|
|
4
4
|
from typing import Optional, Iterable, Dict, TYPE_CHECKING
|
|
5
5
|
import json
|
|
6
6
|
|
|
7
|
-
import geopandas as
|
|
7
|
+
import geopandas as gp
|
|
8
8
|
import pandas as pd
|
|
9
9
|
import numpy as np
|
|
10
10
|
import utm
|
|
@@ -67,7 +67,7 @@ def append_dist_to_shapes(feed: "Feed") -> "Feed":
|
|
|
67
67
|
|
|
68
68
|
def geometrize_shapes_0(
|
|
69
69
|
shapes: pd.DataFrame, *, use_utm: bool = False
|
|
70
|
-
) ->
|
|
70
|
+
) -> gp.GeoDataFrame:
|
|
71
71
|
"""
|
|
72
72
|
Given a GTFS shapes DataFrame, convert it to a GeoDataFrame of LineStrings
|
|
73
73
|
and return the result, which will no longer have the columns
|
|
@@ -84,7 +84,7 @@ def geometrize_shapes_0(
|
|
|
84
84
|
return pd.Series(d)
|
|
85
85
|
|
|
86
86
|
g = f.groupby("shape_id").apply(my_agg).reset_index()
|
|
87
|
-
g =
|
|
87
|
+
g = gp.GeoDataFrame(g, crs=cs.WGS84)
|
|
88
88
|
|
|
89
89
|
if use_utm:
|
|
90
90
|
lat, lon = f[["shape_pt_lat", "shape_pt_lon"]].values[0]
|
|
@@ -94,7 +94,7 @@ def geometrize_shapes_0(
|
|
|
94
94
|
return g
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
def ungeometrize_shapes_0(shapes_g:
|
|
97
|
+
def ungeometrize_shapes_0(shapes_g: gp.GeoDataFrame) -> pd.DataFrame:
|
|
98
98
|
"""
|
|
99
99
|
The inverse of :func:`geometrize_shapes_0`.
|
|
100
100
|
|
|
@@ -120,7 +120,7 @@ def ungeometrize_shapes_0(shapes_g: gpd.GeoDataFrame) -> pd.DataFrame:
|
|
|
120
120
|
|
|
121
121
|
def geometrize_shapes(
|
|
122
122
|
feed: "Feed", shape_ids: Optional[Iterable[str]] = None, *, use_utm: bool = False
|
|
123
|
-
) ->
|
|
123
|
+
) -> gp.GeoDataFrame:
|
|
124
124
|
"""
|
|
125
125
|
Given a Feed instance, convert its shapes DataFrame to a GeoDataFrame of
|
|
126
126
|
LineStrings and return the result, which will no longer have the columns
|
|
@@ -181,7 +181,7 @@ def shapes_to_geojson(feed: "Feed", shape_ids: Optional[Iterable[str]] = None) -
|
|
|
181
181
|
def get_shapes_intersecting_geometry(
|
|
182
182
|
feed: "Feed",
|
|
183
183
|
geometry: sg.base.BaseGeometry,
|
|
184
|
-
shapes_g: Optional[
|
|
184
|
+
shapes_g: Optional[gp.GeoDataFrame] = None,
|
|
185
185
|
*,
|
|
186
186
|
geometrized: bool = False
|
|
187
187
|
) -> pd.DataFrame:
|
|
@@ -5,7 +5,7 @@ from collections import Counter, OrderedDict
|
|
|
5
5
|
from typing import Optional, Iterable, List, Dict, TYPE_CHECKING
|
|
6
6
|
import json
|
|
7
7
|
|
|
8
|
-
import geopandas as
|
|
8
|
+
import geopandas as gp
|
|
9
9
|
import pandas as pd
|
|
10
10
|
import numpy as np
|
|
11
11
|
import shapely.geometry as sg
|
|
@@ -576,7 +576,7 @@ def build_stop_timetable(feed: "Feed", stop_id: str, dates: List[str]) -> pd.Dat
|
|
|
576
576
|
|
|
577
577
|
def geometrize_stops_0(
|
|
578
578
|
stops: pd.DataFrame, *, use_utm: bool = False
|
|
579
|
-
) ->
|
|
579
|
+
) -> gp.GeoDataFrame:
|
|
580
580
|
"""
|
|
581
581
|
Given a stops DataFrame, convert it to a GeoPandas GeoDataFrame of Points
|
|
582
582
|
and return the result, which will no longer have the columns ``'stop_lon'`` and
|
|
@@ -587,7 +587,7 @@ def geometrize_stops_0(
|
|
|
587
587
|
geometry=lambda x: [sg.Point(p) for p in x[["stop_lon", "stop_lat"]].values]
|
|
588
588
|
)
|
|
589
589
|
.drop(["stop_lon", "stop_lat"], axis=1)
|
|
590
|
-
.pipe(lambda x:
|
|
590
|
+
.pipe(lambda x: gp.GeoDataFrame(x, crs=cs.WGS84))
|
|
591
591
|
)
|
|
592
592
|
|
|
593
593
|
if use_utm:
|
|
@@ -598,7 +598,7 @@ def geometrize_stops_0(
|
|
|
598
598
|
return g
|
|
599
599
|
|
|
600
600
|
|
|
601
|
-
def ungeometrize_stops_0(stops_g:
|
|
601
|
+
def ungeometrize_stops_0(stops_g: gp.GeoDataFrame) -> pd.DataFrame:
|
|
602
602
|
"""
|
|
603
603
|
The inverse of :func:`geometrize_stops_0`.
|
|
604
604
|
|
|
@@ -614,7 +614,7 @@ def ungeometrize_stops_0(stops_g: gpd.GeoDataFrame) -> pd.DataFrame:
|
|
|
614
614
|
|
|
615
615
|
def geometrize_stops(
|
|
616
616
|
feed: "Feed", stop_ids: Optional[Iterable[str]] = None, *, use_utm: bool = False
|
|
617
|
-
) ->
|
|
617
|
+
) -> gp.GeoDataFrame:
|
|
618
618
|
"""
|
|
619
619
|
Given a Feed instance, convert its stops DataFrame to a GeoDataFrame of
|
|
620
620
|
Points and return the result, which will no longer have the columns
|
|
@@ -669,37 +669,16 @@ def stops_to_geojson(feed: "Feed", stop_ids: Optional[Iterable[str]] = None) ->
|
|
|
669
669
|
return result
|
|
670
670
|
|
|
671
671
|
|
|
672
|
-
def
|
|
673
|
-
feed: "Feed",
|
|
674
|
-
polygon: sg.Polygon,
|
|
675
|
-
stops_g: Optional[gpd.GeoDataFrame] = None,
|
|
676
|
-
*,
|
|
677
|
-
geometrized: bool = False,
|
|
678
|
-
) -> pd.DataFrame:
|
|
672
|
+
def get_stops_in_area(feed: "Feed", area: gp.GeoDataFrame,) -> pd.DataFrame:
|
|
679
673
|
"""
|
|
680
674
|
Return the subset of ``feed.stops`` that contains all stops that lie
|
|
681
|
-
within the given
|
|
682
|
-
WGS84 coordinates.
|
|
683
|
-
|
|
684
|
-
If ``geometrized``, then return the stops as a GeoDataFrame.
|
|
685
|
-
Specifying ``stops_g`` will skip the first step of the
|
|
686
|
-
algorithm, namely, geometrizing ``feed.stops``.
|
|
675
|
+
within the given GeoDataFrame of polygons.
|
|
687
676
|
"""
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
cols = f.columns
|
|
694
|
-
f["hit"] = f["geometry"].within(polygon)
|
|
695
|
-
f = f.loc[lambda x: x.hit].filter(cols)
|
|
696
|
-
|
|
697
|
-
if geometrized:
|
|
698
|
-
result = f
|
|
699
|
-
else:
|
|
700
|
-
result = ungeometrize_stops_0(f)
|
|
701
|
-
|
|
702
|
-
return result
|
|
677
|
+
return (
|
|
678
|
+
gp.sjoin(geometrize_stops(feed), area.to_crs(cs.WGS84))
|
|
679
|
+
.filter(["stop_id"])
|
|
680
|
+
.merge(feed.stops)
|
|
681
|
+
)
|
|
703
682
|
|
|
704
683
|
|
|
705
684
|
def map_stops(feed: "Feed", stop_ids: Iterable[str], stop_style: Dict = STOP_STYLE):
|
|
@@ -5,7 +5,7 @@ from collections import OrderedDict
|
|
|
5
5
|
import json
|
|
6
6
|
from typing import Optional, Iterable, List, Dict, TYPE_CHECKING
|
|
7
7
|
|
|
8
|
-
import geopandas as
|
|
8
|
+
import geopandas as gp
|
|
9
9
|
import pandas as pd
|
|
10
10
|
import numpy as np
|
|
11
11
|
import shapely.geometry as sg
|
|
@@ -409,7 +409,7 @@ def locate_trips(feed: "Feed", date: str, times: List[str]) -> pd.DataFrame:
|
|
|
409
409
|
|
|
410
410
|
def geometrize_trips(
|
|
411
411
|
feed: "Feed", trip_ids: Optional[Iterable[str]] = None, *, use_utm=False
|
|
412
|
-
) ->
|
|
412
|
+
) -> gp.GeoDataFrame:
|
|
413
413
|
"""
|
|
414
414
|
Return a GeoDataFrame with the columns in ``feed.trips`` and a geometry column
|
|
415
415
|
of LineStrings, each of which represents the shape of the corresponding trip.
|
|
@@ -20,7 +20,7 @@ install_requires = \
|
|
|
20
20
|
|
|
21
21
|
setup_kwargs = {
|
|
22
22
|
'name': 'gtfs-kit',
|
|
23
|
-
'version': '
|
|
23
|
+
'version': '5.0.0',
|
|
24
24
|
'description': 'A Python 3.6.1+ library for analyzing GTFS feeds.',
|
|
25
25
|
'long_description': 'GTFS Kit\n********\n.. image:: https://travis-ci.org/mrcagney/gtfs_kit.svg?branch=master\n :target: https://travis-ci.org/mrcagney/gtfs_kit\n\nGTFS Kit is a Python 3.6+ kit for analyzing `General Transit Feed Specification (GTFS) <https://en.wikipedia.org/wiki/GTFS>`_ data in memory without a database.\nIt uses Pandas and Shapely to do the heavy lifting.\n\nThis project supersedes `GTFSTK <https://github.com/mrcagney/gtfstk>`_.\n\n\nInstallation\n=============\n``pip install gtfs_kit``.\n\n\nExamples\n========\nExamples are in the Jupyter notebook ``notebooks/examples.ipynb``.\n\n\nAuthors\n=========\n- Alex Raichev, 2019-09\n\n\nDocumentation\n=============\nOn Github Pages `here <https://mrcagney.github.io/gtfs_kit_docs>`_.\n\n\nNotes\n=====\n- Development status is Alpha\n- This project uses semantic versioning\n- Thanks to `MRCagney <http://www.mrcagney.com/>`_ for donating to this project\n- Constructive feedback and code contributions welcome. Please issue pull requests into the ``develop`` branch and include tests.\n',
|
|
26
26
|
'author': 'Alex Raichev',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|