Home - General / All posts - Simplifying lines in M9
 Sloots454 post(s) #11-Feb-20 15:56 A few years ago I posted a question regarding the simplification of a road network. See http://www.georeference.org/forum/t69934.3#69935What would be the M9 version of this? I couldn't figure it out so far.... The SPLIT function has changed quit a lot...Any help is highly appreciated.Chris http://www.mppng.nl/manifold/pointlabeler
 Dimitri5,753 post(s) #11-Feb-20 17:34 Try the Smooth transform. See Transform Templates - Drawings and Ctrl-F to find Smooth.
 Sloots454 post(s) #11-Feb-20 18:19 Smoothing is not what I'm looking for. I want to straighten lines (start and end point remain the same) by removing the intermediate inflection points, but I want to keep track of the original distance!The image in the earlier post makers it more clear. http://www.mppng.nl/manifold/pointlabeler
 tjhb9,097 post(s)online #11-Feb-20 23:51 In 9 like this Chris.--SQL9VALUE @source_table TABLE = [Drawing Table];VALUE @source_drawing TABLE = [Drawing];CREATE TABLE [Simplified Table]     (    [mfd_id] INT64,    [Geom] GEOM,    [length] FLOAT64,    INDEX [mfd_id_x] BTREE ([mfd_id]),    INDEX [Geom_x] RTREE ([Geom]),    PROPERTY 'FieldCoordSystem.Geom' ComponentCoordSystem(@source_drawing)    );CREATE DRAWING [Simplified]    (    PROPERTY 'FieldGeom' 'Geom',    PROPERTY 'Table' '[Simplified Table]'    );INSERT INTO [Simplified Table]    ([Geom], [length])SELECT    --[Branch],    GeomMakeSegment(        GeomCoordXY([Value], 0), -- start        GeomCoordXY([Value], GeomCoordCount([Value]) - 1) -- end        ),    GeomLength([Value], 0) AS [length]FROM    (    SELECT    SPLIT CALL GeomToBranches([Network])        --> [Branch] INT32, [Value] GEOM    FROM        (        SELECT GeomMergeLines([Geom]) AS [Network]        FROM @source_table        WHERE GeomIsLine([Geom])        THREADS SystemCpuCount() - 2        )    --THREADS 1    )--THREADS 1;Attachments: Topology and path length.sql
 tjhb9,097 post(s)online #12-Feb-20 00:25 ...But since nothing is being normalized (which you didn't want, probably still don't), we can skip most of the work. No merging, no splitting required.We could have done the same "a few years ago" (!).Let me know if I am missing something. I don't think so--I think I was missing the obvious in the version for 8.--SQL9VALUE @source_table TABLE = [Drawing Table];VALUE @source_drawing TABLE = [Drawing];CREATE TABLE [Simplified Table]     (    [mfd_id] INT64,    [source_id] INT64,    [Geom] GEOM,    [length] FLOAT64,    INDEX [mfd_id_x] BTREE ([mfd_id]),    INDEX [Geom_x] RTREE ([Geom]),    PROPERTY 'FieldCoordSystem.Geom' ComponentCoordSystem(@source_drawing)    );CREATE DRAWING [Simplified]    (    PROPERTY 'FieldGeom' 'Geom',    PROPERTY 'Table' '[Simplified Table]'    );INSERT INTO [Simplified Table]    ([source_id], [Geom], [length])SELECT    [mfd_id],    GeomMakeSegment(        GeomCoordXY([Geom], 0), -- start        GeomCoordXY([Geom], GeomCoordCount([Geom]) - 1) -- end        ),    GeomLength([Geom], 0) AS [length]FROM @source_tableWHERE GeomIsLine([Geom])--THREADS 1;Attachments: Topology and path length simpler.sql
 adamw8,882 post(s) #12-Feb-20 07:51 Also, if the task is just to throw out all intermediate coordinates of each line while saving the length of a former line into a separate field, we can do UPDATE:--SQL9 -- uncomment if you don't have a field to save length to--ALTER TABLE [Drawing Table] (ADD [SavedLength] FLOAT64); -- update data in placeUPDATE [Drawing Table] SET  [SavedLength] = GeomLength([Geom], 0),  [Geom] = GeomMakeSegment(    GeomCoordXY([Geom], 0),    GeomCoordXY([Geom], GeomBranchLast([Geom], 0)));I used a slightly different code to reduce the line to handle lines with multiple branches (by ignoring all branches except the first).