# How to offset point perpendicular to line direction in PostGIS

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?

In mathematical terms would need to calculate the normal of the road section and unit vector of that normal. The first will find which direction you need to move to get your new point and the latter will help you find out how far to go in that direction (i.e. the translation). Exactly how this is best achieved in a postgis sql statement depends on how the geometries are stored.

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."