Skip to content

Instantly share code, notes, and snippets.

@hamishcampbell
Created February 21, 2011 19:18
Show Gist options
  • Save hamishcampbell/837545 to your computer and use it in GitHub Desktop.
Save hamishcampbell/837545 to your computer and use it in GitHub Desktop.
Example statement to determine linear chainage from line segment (PostgreSQL + PostGIS)
/**
* @lon = longitude of selected point
* @lat = latitude of selected point
*/
SELECT
name,
CAST(
offset +
ST_Length(the_geom) * ST_Line_Locate_Point(the_geom, ST_Point(@lon, @lat))
) AS Double)
AS chainage
FROM carriageway
ORDER BY ST_Distance(the_geom, ST_Point(@lon, @lat)) ASC
LIMIT 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment