Search code examples
sqlspatial

create point in intersection between a buffer and line sql spatial


I need to do the following, let me explain, from the end or start point of the line, I am going to create a variable distance buffer, so what I need is to create a point at the intersection of the buffer with the line, is it possible to do this with SQL Spatial? Thank you


Solution

  • You can try the following (MS SQL Server):

    1. Select the start point of your line with STStartPoint()
    2. Create a variable buffer with size X from the line starting point Y with Y.STBuffer(X)
    3. Intersect Buffer and Line with Buffer.STIntersection(Line) and get the Endpoint of this intersection via STEndPoint()

    See the code example below:

    -- draw line
    DECLARE @l geometry;  
    SET @l = geometry::STGeomFromText('LINESTRING (100 100, 50 100, 25 100)', 0);
    -- get start point of line
    DECLARE @s geometry;
    SET @s = @l.STStartPoint();
    -- draw buffer
    DECLARE @b geometry;
    SET @b = @s.STBuffer(10);
    
    -- get intersecting point with buffer
    SELECT 
    @l as line,
    @b as buff,
    @b.STIntersection(@l).STEndPoint() as intersecting_point_geom,
    @b.STIntersection(@l).STEndPoint().ToString() as intersecting_point_wkt;