Search code examples
linepostgis

Turning line segments in to arcs, pretty transport display


I am trying to turn a line segment display enter image description here in to arc segment display

enter image description here My linput data is encoded as a series of MultiLineString geometries,
I have tried things like st_forcecurve(st_linemerge(geom)) which turns my data in to series of very nice straight lines encoded as CompoundCurve geometries. Its there any way to acutal generate a curved line instead off a straight line.


Solution

  • It seems I am not the only one that has run in to issues like this A very similair problem

    One of the answers did what I wanted. I just converted that answer in to an psql function that generates a curved arc, using a factor for how curved you want the answer, low values very curvy, high values a stright line.

    --
    -- Draw an arc geom between two differentlocations
    --
    --   point1                 must be a point starting location
    --   point2                 must be a point ending location
    --   arc_fractor            how curved you want the result
    --   returns                a curved geometry
    
    create or replace function mk_arg_geom(point1 geometry, point2 geometry, arc_factor integer ) 
    
    returns geometry 
            as $$
    
    DECLARE
            ret                 geometry;
            ret_srid            integer;
            tmp_geom            geometry;
            c_geom              geometry;
    BEGIN
    
            ret := null;
            ret_srid:=st_srid(point1);
    
            tmp_geom=st_makeline(point1,point2);
    
            c_geom:= ST_CurveToLine('CIRCULARSTRING(' || 
                    st_x(st_startpoint(tmp_geom)) || 
                    ' ' || 
                    st_y(st_startpoint(tmp_geom)) || 
                    ', ' || 
                    st_x(st_centroid(ST_OffsetCurve(tmp_geom, st_length(tmp_geom)/arc_factor, 'quad_segs=4 join=bevel'))) || 
                    ' ' || 
                    st_y(st_centroid(ST_OffsetCurve(tmp_geom, st_length(tmp_geom)/arc_factor, 'quad_segs=4 join=bevel'))) || 
                    ', ' || 
                    st_x(st_endpoint(tmp_geom)) || 
                    ' ' ||  
                    st_y(st_endpoint(tmp_geom)) 
                    || ')');
    
            ret=st_setsrid(c_geom,ret_srid);
    
            return ret;
    END;
    
    $$
            LANGUAGE plpgsql;