Hallo Wissende,
ich bin neu in PostGIS und weiß deshalb nicht so recht wo ich hingreifen soll.
Ich habe eine Polylinie. An/neben dieser Linie möchte ich Punkte in einem bestimmten Abstand und mit einem bestimmten Offset erstellen.
Punkt an bestimmter Position auf der Linie ist kein Problem,
-- Punkt auf Linie nach 3.5m generieren
SELECT ST_Length (geom),
ST_AsEWKT(ST_LineInterpolatePoint(geom, 3.5/ ST_Length (geom)))
FROM meinetab
LIMIT 1;
Aber für den Offset (z.B. 0,5m rechts neben der Linie) habe ich noch keine richtige Idee/Funktion gefunden.
create or replace function st_line_interpolate_point(m_geom geometry, m_distance double precision, m_offset double precision)
returns geometry as
$BODY$
/*
Interpolate a point across a line and then offset to the left ( negative ) or right by m_distance
Quelle: https://trac.osgeo.org/postgis/wiki/UsersWikiExamplesInterpolateWithOffset
*/
declare m_seg geometry;
declare p1 geometry;
declare p2 geometry;
declare m_percent double precision;
BEGIN
m_percent := m_distance / ST_Length (m_geom);
m_seg := st_linesubstring(m_geom,0, m_percent);
/* Grab the 2 points of the matching line segment */
p1:=st_pointn(m_seg,st_npoints(m_seg)-1);
p2:=st_endpoint(m_seg);
/* get the delta of the line segment and offset the interpolated point */
/* Rotate deltas by 90 degrees (invert dx/dy ) */
/* spheroid projections will need the offset to vary based on lat/lon */
return st_translate(
p2,
((st_y(p2) - st_y(p1)) / st_distance(p1,p2)) * m_offset,
((st_x(p2) - st_x(p1)) / st_distance(p1,p2)) * (-m_offset)
);
END;
$BODY$
language plpgsql;