I'm trying to create a line snapping tool in my Android app where I'm using the spatialite-android lib. I'm using the function ST_Snap
where I want to snap a linestring with another linestring on the point where a line string is touching another one. here is the preview
Here is my gis query
SELECT ST_AsText(ST_Snap(line, input, ST_Distance(input,line)*10.0))
FROM (SELECT
ST_GeomFromText('LINESTRING(88.4656805545 22.6896467287,88.4632558376 22.6896841575,88.4614285827 22.6882649519)',4326) As input,
ST_GeomFromText('LINESTRING(88.4654606134 22.690117835,88.4655571729 22.6896761149)',4326) As line);
But the above query snapping the line to the end. I'm guessing the query is not appropriate.
This is what happening
Answer
ST_Snap
will snap to an existing vertice. You would need to project your input endpoint to the line via ST_LineLocatePoint
to find the distance of the projected point from the start of the line. Then, using this distance, you need to find its coordinate via ST_LineInterpolatePoint
. You would then create the snapped-line using the input start point and this found location.
SELECT ST_AsText(
ST_LineInterpolatePoint(line,
ST_LineLocatePoint(line,
ST_EndPoint(input))))
FROM (SELECT
ST_GeomFromText('LINESTRING(88.4656805545 22.6896467287,88.4632558376 22.6896841575,88.4614285827 22.6882649519)',4326) As input,
ST_GeomFromText('LINESTRING(88.4654606134 22.690117835,88.4655571729 22.6896761149)',4326) As line) as foo;
No comments:
Post a Comment