Skip to content

Instantly share code, notes, and snippets.

@worthlutz
worthlutz / pgrw_xyroute.sql
Last active July 8, 2016 14:23
pgrw_xyroute is an example of a wrapper around the pgr_trsp function to require only x/y inputs for source and target points. Routing is then done by pgr_trsp using the nearest location on the closest edges to the source and target points.
/*
pgrw_xyroute is an example of a wrapper around the pgr_trsp function to require only x/y inputs
for source and target points. Routing is then done by pgr_trsp using the nearest location on
the closest edges to the source and target points. To achieve this result, the details of the
specific routing network are hard-coded as constants in the wrapper. Modification to your
specific situation should be simple.
*/
CREATE OR REPLACE FUNCTION pgrw_xyroute(source_x double precision, source_y double precision,
target_x double precision, target_y double precision)
<?php
/**
* Convert a comma separated file into an associated array.
* The first row should contain the array keys.
*
* Example:
*
* @param string $filename Path to the CSV file
* @param string $delimiter The separator used in the file
* @return array