[GIS] Offseting point perpendicular to line direction in PostGIS

linestringoffsetperpendicularpointpostgis

I have a PostGIS table of points, that are sitting on road centerlines (I've linear referenced them). And the second table with road centerlines themselves.

The point table also has a field roadid and a field "offst", that represents the offset in meters (negative values = offest to the left, positive = offset to the right side of the road).

The question is how can I calculate a point geometry, that is offsetted perpendicular to road direction, according to the value of the "offst" field?

Best Answer

There is probably easier way but... in PostGIS 2.0.1 ->

https://postgis.net/docs/ST_OffsetCurve.html

take road, offset it needed amount using ST_OffsetCurve and then use ST_Line_Locate_Point to offsetted line and then ST_Line_Interpolate_Point to find correct place

**SELECT ST_Line_Interpolate_Point(ST_Line_Locate_Point(ST_OffsetCurve(roadcenter_geom, pointoffset), point_geometry ) from xx where yyy**

Another way is get vertex where point intersects line and calculate azimuth there and then use trigometry to figure where new point should be

Edit : Also i found this one :

http://trac.osgeo.org/postgis/wiki/UsersWikiExamplesInterpolateWithOffset

"This code creates another st_line_interpolate_point with a 3rd argument for offset of the point to the left or right side of the line segment. Useful for Geocoding."

Which is ready made implementation of "Another way"