Multipoint geometry to Line geometry

l pro 1 Reputation point
2020-09-15T00:05:40.663+00:00

HI,

I have a multipoint shape geometry.

1) How do I convert this to a line geometry?. The points in the multipoint geometry are sorted.

2) Generalize the line. Reducing the amount of points by an algorithm e.g. Douglas Peucker with a variable tolerance = X meters... There are other algorithm' around.
See link below.

3) Convert lines which have exactly overlapping geometry to one line.

https://www.google.com/url?sa=i&url=https%3A%2F%2Fcommons.wikimedia.org%2Fwiki%2FFile%3ADouglas-Peucker_animated.gif&psig=AOvVaw1ZJy_KQdSXBDfWsGtZwmyt&ust=1600213853053000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCKDjyajr6esCFQAAAAAdAAAAABAK

Regards,

L Pro

Developer technologies | Transact-SQL
{count} votes

2 answers

Sort by: Most helpful
  1. Ronen Ariely 15,206 Reputation points
    2020-09-15T12:03:15.477+00:00

    Good day @l pro ,

    In order to discuss your specific case and save us the time to play the "guessing game" please remember ALWAYS to provide in each question:

    1) Queries to CREATE your table(s) including indexes
    2) Queries to INSERT sample data.
    3) The desired result given the sample, as text or image of excel for example.
    4) A short description of the business rules, and how you got 1-2 of the results
    5) Which version of SQL Server you are using (this will help to fit the query to your version).

    1) How do I convert this to a line geometry?

    As explained above, we do not know what is "this" but a simple solution for "CONVERT MULTIPOINT into LINESTRING" you can find in this demo on GitHub (scroll to the bottom).

    2) Generalize the line. Reducing the amount of points by an algorithm e.g. Douglas Peucker with a variable tolerance = X meters... There are other algorithm' around.

    This is actually build-in in SQL Server :-)

    Check the this official document on how to use Reduce() method to simplify a LineString.

    3) Convert lines which have exactly overlapping geometry to one line.

    More information and clarifications on option including sample demo will help. In the meantime check this post which is related to this but not directly solve this specific need

    https://ariely.info/Blog/tabid/83/EntryId/228/Grouping-continuous-Ranges-together-Part-2-Using-geometry-Data-type.aspx

    My image explains exactly what the post is about :-)

    Grouping%20continuous%20Ranges%20CP.gif

    0 comments No comments

  2. l pro 1 Reputation point
    2020-09-22T00:14:14.453+00:00

    Good day @Ronen Ariely 26218-threelines.txt26219-query.png and @EchoLiu-MSFT

    I attached the query of 3 multipoint lines and the result exported as Tab delimited. Ignore the z value. so x,y,m where m is the measure as a sequential number which is sorted.

    It is stored as multipoint in SQL server where I am sourcing from. And not able to change the data model unfortunately :) . I hoped from the sample data I could make a line without de-aggregating to points and then build it up from scratch again to line geometry. I am not sure if there is another way I got a 100k multipoint 'lines' and looking for a solution which doesn't take to much processing time. Essentially the multi-points are already lines, although not connected.

    Thanks L pro


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.