3

Find the median line from the input broken line

I already tried to use ST_Simplify, but as the result Wrong Line was gotten, because the function reduced the number of points significantly and curvature was lost.

Is it possible to get the Desired Line while keeping maximum shape?

Example of data:

LINESTRING(-84.28218748821607 36.062298255863915,-84.28016833333335 36.06324,-84.27880833333332 36.06454166666666,-84.27893 36.06476833333333,-84.27872 36.064645000000006,-84.27883333333332 36.06478833333333,-84.278695 36.06469833333333,-84.27877333333332 36.064825000000006,-84.27838166666668 36.06502,-84.27849166666668 36.06512166666666,-84.27825166666668 36.06514166666667,-84.27825333333334 36.06540333333333,-84.27802833333332 36.06537333333333,-84.27746333333334 36.06598666666666,-84.27755333333334 36.06616,-84.27733000000002 36.06611833333333,-84.27603333333333 36.067495,-84.27615666666667 36.067618333333336,-84.27601666666666 36.06750666666667,-84.27550333333332 36.06791,-84.27550833333335 36.067775,-84.27350833333334 36.06926833333333,-84.27332499999999 36.06935166666666,-84.27321500000001 36.06911333333333,-84.27326166666666 36.06934833333333,-84.27319333333335 36.06917666666666,-84.27325 36.069345,-84.27318166666667 36.069185,-84.27323166666665 36.06935666666666,-84.27252166666668 36.06989333333333,-84.27162000000001 36.07021,-84.27155666666667 36.07054666666667,-84.27138166666667 36.07033833333333,-84.27020166666668 36.07092333333333,-84.26993666666667 36.07100666666667,-84.26991666666666 36.070863333333335,-84.269795 36.07106666666667,-84.26972666666667 36.070926666666665,-84.26942 36.07131,-84.26936499999998 36.07111333333333,-84.269075 36.07123166666667,-84.26888333333333 36.07168833333333,-84.26881999999999 36.071331666666666,-84.26854166666665 36.071668333333335,-84.26848999999999 36.071435,-84.26794 36.07182833333333,-84.26790833333334 36.071686666666665,-84.26755166666665 36.07184,-84.26770166666665 36.072091666666665,-84.26753333333333 36.071848333333335,-84.26718333333335 36.07227,-84.26692 36.07221666666667,-84.26699833333332 36.072363333333335,-84.26679333333335 36.072195,-84.26689833333333 36.07241,-84.26648833333333 36.07212666666667,-84.26671166666665 36.072455,-84.26652833333334 36.07269333333333,-84.26631833333334 36.07255833333333,-84.266325 36.072853333333335,-84.26438666666667 36.07391,-84.255975 36.075763333333335,-84.25457999999999 36.07587,-84.252335 36.07546333333333,-84.25030666666667 36.07452166666667,-84.25044166666666 36.07442,-84.24964666666668 36.07429666666667,-84.249725 36.07410333333333,-84.24952666666668 36.07419333333333,-84.24870666666666 36.07376,-84.24784 36.07313166666667,-84.24774833333335 36.07281666666667,-84.24759 36.072905,-84.24768999999999 36.07273333333333,-84.24753166666666 36.072835000000005,-84.24728833333332 36.07254666666667,-84.24679499999999 36.071555,-84.24689666666667 36.07124666666667,-84.24674666666667 36.07128,-84.24668666666666 36.07081166666667,-84.24715333333333 36.07058166666666,-84.24667166666669 36.070675,-84.24714 36.07045,-84.24667166666669 36.07066666666666,-84.24663833333334 36.07052,-84.24711833333335 36.07021333333333,-84.24662333333332 36.07024333333333,-84.247105 36.07006166666667,-84.24658333333333 36.07017166666667,-84.24701666666667 36.06991666666667,-84.24657499999999 36.06998166666666,-84.24651 36.06975333333333,-84.24673666666668 36.06971333333333,-84.24646333333334 36.06959333333334,-84.24668333333332 36.06948333333333,-84.24645666666666 36.069563333333335,-84.24616833333333 36.06881333333333,-84.24609000000001 36.068425000000005,-84.24636333333335 36.06827166666667,-84.24608666666667 36.06840166666667,-84.24635833333332 36.068216666666665,-84.24603166666665 36.068325,-84.24583066258008 36.06700621709043)
3
  • looks like you used too high a tolerance in your simplify command try a smaller number
    – Ian Turton
    Sep 22 at 10:04
  • I tried, but it is super hard to find an optimal tolerance value.
    – Slava
    Sep 22 at 10:06
  • 1
    then reproject to a better projection and use a distance in metres
    – Ian Turton
    Sep 22 at 10:09

1 Answer 1

4

Transform to a projected coordinate system, simplify, buffer, smooth, find its medial axis.

with cte as (
select st_setsrid(
st_geomfromewkt('LINESTRING(-84.28218748821607 36.062298255863915,-84.28016833333335 36.06324,-84.27880833333332 36.06454166666666,-84.27893 36.06476833333333,-84.27872 36.064645000000006,-84.27883333333332 36.06478833333333,-84.278695 36.06469833333333,-84.27877333333332 36.064825000000006,-84.27838166666668 36.06502,-84.27849166666668 36.06512166666666,-84.27825166666668 36.06514166666667,-84.27825333333334 36.06540333333333,-84.27802833333332 36.06537333333333,-84.27746333333334 36.06598666666666,-84.27755333333334 36.06616,-84.27733000000002 36.06611833333333,-84.27603333333333 36.067495,-84.27615666666667 36.067618333333336,-84.27601666666666 36.06750666666667,-84.27550333333332 36.06791,-84.27550833333335 36.067775,-84.27350833333334 36.06926833333333,-84.27332499999999 36.06935166666666,-84.27321500000001 36.06911333333333,-84.27326166666666 36.06934833333333,-84.27319333333335 36.06917666666666,-84.27325 36.069345,-84.27318166666667 36.069185,-84.27323166666665 36.06935666666666,-84.27252166666668 36.06989333333333,-84.27162000000001 36.07021,-84.27155666666667 36.07054666666667,-84.27138166666667 36.07033833333333,-84.27020166666668 36.07092333333333,-84.26993666666667 36.07100666666667,-84.26991666666666 36.070863333333335,-84.269795 36.07106666666667,-84.26972666666667 36.070926666666665,-84.26942 36.07131,-84.26936499999998 36.07111333333333,-84.269075 36.07123166666667,-84.26888333333333 36.07168833333333,-84.26881999999999 36.071331666666666,-84.26854166666665 36.071668333333335,-84.26848999999999 36.071435,-84.26794 36.07182833333333,-84.26790833333334 36.071686666666665,-84.26755166666665 36.07184,-84.26770166666665 36.072091666666665,-84.26753333333333 36.071848333333335,-84.26718333333335 36.07227,-84.26692 36.07221666666667,-84.26699833333332 36.072363333333335,-84.26679333333335 36.072195,-84.26689833333333 36.07241,-84.26648833333333 36.07212666666667,-84.26671166666665 36.072455,-84.26652833333334 36.07269333333333,-84.26631833333334 36.07255833333333,-84.266325 36.072853333333335,-84.26438666666667 36.07391,-84.255975 36.075763333333335,-84.25457999999999 36.07587,-84.252335 36.07546333333333,-84.25030666666667 36.07452166666667,-84.25044166666666 36.07442,-84.24964666666668 36.07429666666667,-84.249725 36.07410333333333,-84.24952666666668 36.07419333333333,-84.24870666666666 36.07376,-84.24784 36.07313166666667,-84.24774833333335 36.07281666666667,-84.24759 36.072905,-84.24768999999999 36.07273333333333,-84.24753166666666 36.072835000000005,-84.24728833333332 36.07254666666667,-84.24679499999999 36.071555,-84.24689666666667 36.07124666666667,-84.24674666666667 36.07128,-84.24668666666666 36.07081166666667,-84.24715333333333 36.07058166666666,-84.24667166666669 36.070675,-84.24714 36.07045,-84.24667166666669 36.07066666666666,-84.24663833333334 36.07052,-84.24711833333335 36.07021333333333,-84.24662333333332 36.07024333333333,-84.247105 36.07006166666667,-84.24658333333333 36.07017166666667,-84.24701666666667 36.06991666666667,-84.24657499999999 36.06998166666666,-84.24651 36.06975333333333,-84.24673666666668 36.06971333333333,-84.24646333333334 36.06959333333334,-84.24668333333332 36.06948333333333,-84.24645666666666 36.069563333333335,-84.24616833333333 36.06881333333333,-84.24609000000001 36.068425000000005,-84.24636333333335 36.06827166666667,-84.24608666666667 36.06840166666667,-84.24635833333332 36.068216666666665,-84.24603166666665 36.068325,-84.24583066258008 36.06700621709043)'),
4326) as geom)

select ST_ChaikinSmoothing(
(ST_ApproximateMedialAxis(
st_simplify(st_buffer(
st_transform(geom, 32616)
, 20)
, 30)
)), 5) as geometry

from cte

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.