gtfs_segments.geom_utils
code(zone, lat)
If the latitude is negative, the EPSG code is 32700 + the zone number. If the latitude is positive, the EPSG code is 32600 + the zone number
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zone |
List
|
The UTM zone number. |
required |
lat |
float
|
latitude of the point |
required |
Returns:
Type | Description |
---|---|
int
|
The EPSG Code |
Source code in gtfs_segments/geom_utils.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
get_zone_epsg(stop_df)
The function takes a dataframe with a geometry column and returns the EPSG code for the UTM zone that contains the geometry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_df |
GeoDataFrame
|
a dataframe with a geometry column |
required |
Returns:
Type | Description |
---|---|
int
|
The EPSG code for the UTM zone that the stop is in. |
Source code in gtfs_segments/geom_utils.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
increase_resolution(geom, spat_res=5)
This function increases the resolution of a LineString geometry by adding points along the line at a specified spatial resolution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geom |
LineString
|
The input geometry that needs to be modified (in this case, a LineString). |
required |
spat_res |
int
|
spatial resolution, which is the desired distance between consecutive points on the LineString. If the distance between two consecutive points is greater than the spatial resolution, the function will add additional points to the LineString to increase its resolution. Defaults to 5 |
5
|
Returns:
Type | Description |
---|---|
LineString
|
a LineString object with increased resolution based on the input spatial resolution. |
Source code in gtfs_segments/geom_utils.py
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 |
|
make_gdf(df)
It takes a dataframe and returns a geodataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
the dataframe you want to convert to a geodataframe |
required |
Returns:
Type | Description |
---|---|
GeoDataFrame
|
A GeoDataFrame |
Source code in gtfs_segments/geom_utils.py
61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
nearest_points(stop_df, k_neighbors=3)
The function takes a dataframe of stops and snaps them to the nearest points on a line geometry, with an option to specify the number of nearest neighbors to consider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_df |
GeoDataFrame
|
a pandas DataFrame containing information about stops along a set of trips, including the |
required |
trip ID, the stop location (as a Shapely Point object), and the geometry of the trip (as a Shapely LineString object) k_neighbors: The number of nearest neighbors to consider when snapping stops to a line geometry. Default value is 3. Defaults to 3
Returns:
Type | Description |
---|---|
DataFrame
|
the stop_df dataframe with an additional column 'snap_start_id' which contains the indices of the |
nearest points on the trip route for each stop. If any trips failed to snap, they are excluded from the returned dataframe.
Source code in gtfs_segments/geom_utils.py
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 |
|
nearest_snap(route_string, stop_point)
It takes a dataframe of bus stops and a dataframe of bus routes and returns a dataframe of the nearest bus stop to each bus stop
Parameters:
Name | Type | Description | Default |
---|---|---|---|
route |
the route geometry |
required | |
point |
the point you want to snap to the nearest point on the route |
required |
Returns:
Type | Description |
---|---|
str
|
A list of tuples. Each tuple contains the route_id, segment_id, and |
str
|
the distance between the two stops. |
Source code in gtfs_segments/geom_utils.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
ret_high_res_shape(shapes, trips, spat_res=5)
This function increases the resolution of the geometries in a given dataframe of shapes by a specified spatial resolution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shapes |
GeoDataFrame
|
a pandas DataFrame containing a column named 'geometry' that contains shapely geometry |
required |
objects spat_res: spatial resolution, which is the size of each pixel or cell in a raster dataset. In this function, it is used to increase the resolution of the input shapes by creating more vertices in their geometries. The default value is 5, which means that the resolution will be increased by adding vertices. Defaults to 5
Returns:
Type | Description |
---|---|
GeoDataFrame
|
a GeoDataFrame with the geometry column updated to have higher resolution shapes. |
Source code in gtfs_segments/geom_utils.py
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 |
|
ret_high_res_shape_parallel(shapes, spat_res=5)
This function increases the resolution of the geometries in a given dataframe of shapes by a specified spatial resolution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shapes |
GeoDataFrame
|
a pandas DataFrame containing a column named 'geometry' that contains shapely geometry |
required |
objects spat_res: spatial resolution, which is the size of each pixel or cell in a raster dataset. In this function, it is used to increase the resolution of the input shapes by creating more vertices in their geometries. The default value is 5, which means that the resolution will be increased by adding vertices. Defaults to 5
Returns:
Type | Description |
---|---|
GeoDataFrame
|
a GeoDataFrame with the geometry column updated to have higher resolution shapes. |
Source code in gtfs_segments/geom_utils.py
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 |
|
split_route(row)
It takes a row from a dataframe, and if the row has a start and end point, it splits the route into two segments
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row |
Series
|
row in stop_df |
required |
Returns:
Type | Description |
---|---|
str
|
the geometry of the route segments. |
Source code in gtfs_segments/geom_utils.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
view_heatmap(gdf, column='distance', cmap='RdYlBu', light_mode=True, interactive=False)
Generates a heatmap visualization of a GeoDataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf |
GeoDataFrame
|
The GeoDataFrame containing the data to be visualized. |
required |
cmap |
Optional[str]
|
The colormap to be used for the heatmap. Defaults to "RdYlBu". |
'RdYlBu'
|
light_mode |
bool
|
Specifies whether to use a light mode basemap. Defaults to True. |
True
|
interactive |
bool
|
Specifies whether to generate an interactive map. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The generated heatmap visualization. |
Source code in gtfs_segments/geom_utils.py
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 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
|
view_spacings(gdf, basemap=False, map_provider=cx.providers.CartoDB.Positron, show_stops=False, level='whole', axis='on', dpi=300, **kwargs)
The view_spacings
function plots the spacings of a bus network, route, or segment, with options to
add a basemap and show stops.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf |
GeoDataFrame
|
The GTFS segments GeoDataframe containing the bus network data. |
required |
basemap |
bool
|
The |
False
|
the plot. If set to True
, a basemap will be added. If set to False
, no basemap will be added.
The default value is False
. Defaults to False
map_provider: The map_provider
parameter is used to specify the source of the basemap that
will be added to the plot. It is set to cx.providers.CartoDB.Positron
by default, which means
that the basemap will be sourced from CartoDB's Positron. Use contextily.providers
to see full
list of providers
show_stops: The show_stops
parameter is a boolean flag that determines whether or not to display
the bus stops on the plot. If set to True
, the bus stops will be shown as white markers on the
plot. If set to False
, the bus stops will not be shown. Defaults to False
level: The "level" parameter determines the level of detail to plot the spacings. It can take one
of three values:. Defaults to whole
axis: The axis
parameter determines whether the axis of the plot should be displayed or not. If
axis
is set to "on", the axis will be displayed. If axis
is set to "off", the axis will not be
displayed. Defaults to on
dpi: The dpi
parameter determines the resolution of the plot. Defaults to 300
Returns:
Type | Description |
---|---|
Figure
|
a matplotlib Figure object. |
Source code in gtfs_segments/geom_utils.py
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 |
|
view_spacings_interactive(gdf, basemap=True, show_stops=False, level='whole', **kwargs)
Generates an interactive Folium map to visualize stop spacings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf |
GeoDataFrame
|
The GeoDataFrame containing the stop spacing data. |
required |
basemap |
bool
|
Whether to add a basemap to the map. Defaults to True. |
True
|
show_stops |
bool
|
Whether to show the stops on the map. Defaults to False. |
False
|
level |
str
|
The level at which to filter the data. Can be 'whole', 'route', or 'segment'. Defaults to 'whole'. |
'whole'
|
**kwargs |
Any
|
Additional keyword arguments for filtering the data based on level. |
{}
|
Returns:
Type | Description |
---|---|
Map
|
folium.Map: The generated Folium map. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the required attributes for filtering the data are not provided. |
Example usage
gdf = gpd.GeoDataFrame(...) map = view_spacings_interactive(gdf, basemap=True, show_stops=True, level='route', route='123')
Source code in gtfs_segments/geom_utils.py
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 |
|