sdr_generate_choicesets: Generates a choice set of ten nearest stations for postcodes

Description Usage Arguments Details Value

View source: R/sdr_generate_choicesets.R

Description

For a given station or stations identifies the postcodes within 60 minutes of the station or stations and then generates a choice set of the nearest 10 stations to each of those postcodes. The function is also able to generate before and after choicesets for abstraction analysis.

Usage

1
sdr_generate_choicesets(con, schema, crs, existing = FALSE, abs_crs = NULL)

Arguments

con

An RPostgres database connection object.

schema

Character, the database schema name.

crs

Character vector of the crscode(s) of the station(s) for which a set of postcode choicesets is required.

existing

Logical. Indicates whether the station crscodes contained in crs are for existing (TRUE) or proposed (FALSE) stations. Default is FALSE.

abs_crs

Character, a single crs code of an existing station for which an after set of postcode choicesets is required. Optional.

Details

If existing is set to FALSE then the crscode(s) in crs must be for proposed stations. The function obtains the 60 minute service area geometry from the schema.proposed_stations table. If there is more than one crscode in crs then st_union will be applied to the individual service area geometries to create a single merged 60 minute service area (this is used when the concurrent mode has been selected for the model run). The function uses parallel processing via the foreach package and requires the clusters to be configured prior to calling the function.

If existing is set to TRUE then the crscode(s) in crs must be existing stations (normally a single station). The function will obtain the 60 minute service area geometry from the data.stations table.

If abs_crs is passed to the function then it should be a single crscode of an existing station. This is used to control whether a before or after set of postcode choicesets is required. To obtain a before choiceset for abstraction analysis pass the existing station crscode to the function using crs, set existing to TRUE and do not pass abs_crs. To obtain an after choiceset for abstraction analysis pass the proposed station(s) in crs, set existing to FALSE and pass the crscode of the existing station for which abstraction analysis is being carried out to abs_crs.

The function submits db queries which rely on several bespoke pgRouting wrapper functions that must be located in the openroads schema: create_pgr_vnodes, sdr_crs_pc_nearest_stationswithpoints, sdr_pc_station_withpoints, sdr_pc_station_withpoints_nobbox, and bbox_pgr_withpointscost.

Two materialized views are created for use by these functions. The first is schema.centroidnodes which is a union of virtual nodes for the proposed stations (which are created in the query) and virtual nodes for existing stations. The second is schema.stations which is a union of stations from data.stations and schema.proposed_stations containing the distance-based service areas used in identifying the nearest 10 stations to each postcode.

For maximum flexibility to also use this function for abstraction analysis without code repetition, it should be noted that the union queries are used even when existing is set to TRUE and the crscode in crs is an existing station. In this case there will be no match with any stations in schema.proposed_stations and that part of the union query will simply return null.

Value

Returns a data frame containing the postcode choicesets with stations ranked by distance from the postcode centroid.


station-demand-forecasting-tool/sdft documentation built on July 11, 2021, 4:23 a.m.