1717from shared_utils import DBSession , schedule_rt_utils
1818from shared_utils .models .dim_gtfs_dataset import DimGtfsDataset
1919from shared_utils .models .fct_daily_schedule_feeds import FctDailyScheduleFeeds
20+ from shared_utils .models .fct_daily_scheduled_shapes import FctDailyScheduledShapes
2021from shared_utils .models .fct_scheduled_trips import FctScheduledTrips
2122from siuba import *
2223from sqlalchemy import and_ , create_engine , func , or_ , select
@@ -407,7 +408,7 @@ def get_shapes(
407408 get_df : bool = True ,
408409 crs : str = geography_utils .WGS84 ,
409410 custom_filtering : dict = None ,
410- ) -> gpd .GeoDataFrame :
411+ ) -> Union [ gpd .GeoDataFrame | sqlalchemy . sql . selectable . Select ] :
411412 """
412413 Query fct_daily_scheduled_shapes.
413414
@@ -416,21 +417,15 @@ def get_shapes(
416417 """
417418 check_operator_feeds (operator_feeds )
418419
419- # If pt_array is not kept in the final, we still need it
420- # to turn this into a gdf
421- if "pt_array" not in shape_cols :
422- shape_cols_with_geom = shape_cols + ["pt_array" ]
423- elif shape_cols :
424- shape_cols_with_geom = shape_cols [:]
420+ search_conditions = [
421+ FctDailyScheduledShapes .service_date == selected_date ,
422+ FctDailyScheduledShapes .feed_key .in_ (operator_feeds ),
423+ ]
425424
426- tables = _get_tables ()
425+ for k , v in (custom_filtering or {}).items ():
426+ search_conditions .append (getattr (FctDailyScheduledShapes , k ).in_ (v ))
427427
428- shapes = (
429- getattr (tables , "test_shared_utils" ).fct_daily_scheduled_shapes ()
430- >> filter_date (selected_date , date_col = "service_date" )
431- >> filter_operator (operator_feeds , include_name = False )
432- >> filter_custom_col (custom_filtering )
433- )
428+ shapes = select (FctDailyScheduledShapes ).where (and_ (* search_conditions ))
434429
435430 if get_df :
436431 shapes = shapes >> collect ()
@@ -442,7 +437,12 @@ def get_shapes(
442437 return shapes_gdf
443438
444439 else :
445- return shapes >> subset_cols (shape_cols_with_geom )
440+ columns = {FctDailyScheduledShapes .pt_array }
441+
442+ for column in shape_cols :
443+ columns .add (getattr (FctDailyScheduledShapes , column ))
444+
445+ return shapes .with_only_columns (* list (columns ))
446446
447447
448448def get_stops (
0 commit comments