﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Manifold Community Site: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193</link><description>Manifold Community Site thread</description><image><url>http://95.79.92.2:8080/forum/images/img-logo.png</url><title>Manifold Community Site: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193</link></image><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143194</link><description>&lt;P&gt;Does M9 have an ability to make lines out of point data, the way that M8 does?  I can&amp;#39;t tell by looking over the new function list.&lt;/P&gt;</description><dc:creator>Forest</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143194</comments><guid>http://95.79.92.2:8080/forum/t143193#143194</guid><pubDate>Tue, 01 May 2018 08:00:19 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143195</link><description>&lt;P&gt;Yes. Pass an ordered multipoint to GeomConvertToLine.&lt;/P&gt;</description><dc:creator>tjhb</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143195</comments><guid>http://95.79.92.2:8080/forum/t143193#143195</guid><pubDate>Tue, 01 May 2018 08:24:36 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143201</link><description>&lt;P&gt;Sorry, that was a bit terse.&lt;/P&gt;&lt;P&gt;It would make a nice example, if you have sample that would be useful?&lt;/P&gt;&lt;P&gt;Ensuring point order in SQL9 (in a thread-safe way) involves use of COLLECT.&lt;/P&gt;</description><dc:creator>tjhb</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143201</comments><guid>http://95.79.92.2:8080/forum/t143193#143201</guid><pubDate>Tue, 01 May 2018 21:13:13 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143202</link><description>&lt;P&gt;Terse is fine.  Use of COLLECT will almost certainly require an example.&lt;/P&gt;&lt;P&gt;I wrote my own code to import gpx files but tracks come in as track points.  I used to use Manifold 8 to rebuild the tracks. &lt;/P&gt;</description><dc:creator>Forest</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143202</comments><guid>http://95.79.92.2:8080/forum/t143193#143202</guid><pubDate>Wed, 02 May 2018 00:46:08 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143207</link><description>&lt;P&gt;Sample data would help focus the example.&lt;/P&gt;</description><dc:creator>tjhb</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143207</comments><guid>http://95.79.92.2:8080/forum/t143193#143207</guid><pubDate>Wed, 02 May 2018 03:47:44 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143214</link><description>&lt;P&gt;Or is that too hard.&lt;/P&gt;</description><dc:creator>tjhb</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143214</comments><guid>http://95.79.92.2:8080/forum/t143193#143214</guid><pubDate>Thu, 03 May 2018 05:42:14 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143256</link><description>&lt;P&gt;Try this:&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=c&gt;--SQL9&lt;/span&gt;&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=k&gt;FUNCTION&lt;/span&gt;&amp;#160;makeline(t&amp;#160;&lt;span class=k&gt;TABLE&lt;/span&gt;)&amp;#160;&lt;span class=k&gt;GEOM&lt;/span&gt;&amp;#160;&lt;span class=k&gt;AS&lt;/span&gt;&amp;#160;(&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&amp;#160;&lt;span class=k&gt;SELECT&lt;/span&gt;&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;GeomConvertToLine(GeomConvertToPoint(GeomMergePoints(&lt;span class=i&gt;[Geom]&lt;/span&gt;),&amp;#160;false))&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&amp;#160;&lt;span class=k&gt;FROM&lt;/span&gt;&amp;#160;t&lt;/P&gt;&lt;P class='code'&gt;)&amp;#160;&lt;span class=k&gt;END&lt;/span&gt;;&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=k&gt;DELETE&lt;/span&gt;&amp;#160;&lt;span class=k&gt;FROM&lt;/span&gt;&amp;#160;&lt;span class=i&gt;[Lines]&lt;/span&gt;;&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=k&gt;INSERT&lt;/span&gt;&amp;#160;&lt;span class=k&gt;INTO&lt;/span&gt;&amp;#160;&lt;span class=i&gt;[Lines]&lt;/span&gt;&amp;#160;(&lt;span class=i&gt;[Geom]&lt;/span&gt;)&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=k&gt;SELECT&lt;/span&gt;&amp;#160;makeline((&lt;span class=k&gt;COLLECT&lt;/span&gt;&amp;#160;&lt;span class=i&gt;[Geom]&lt;/span&gt;&amp;#160;&lt;span class=k&gt;ORDER&lt;/span&gt;&amp;#160;&lt;span class=k&gt;BY&lt;/span&gt;&amp;#160;&lt;span class=i&gt;[LineCoord]&lt;/span&gt;))&amp;#160;&lt;span class=k&gt;FROM&lt;/span&gt;&amp;#160;&lt;span class=i&gt;[Points]&lt;/span&gt;&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&amp;#160;&lt;span class=k&gt;GROUP&lt;/span&gt;&amp;#160;&lt;span class=k&gt;BY&lt;/span&gt;&amp;#160;&lt;span class=i&gt;[Line]&lt;/span&gt;;&lt;/P&gt;&lt;P&gt;The query assumes points are in [Points] and each point has [Line] which specifies which line it belongs to and [LineCoord] which specified the coordinate order on that line.&lt;/P&gt;&lt;P&gt;The query takes these points, joins them into lines and writes the resulting geoms into [Lines]. The coordinates for each line are first grouped using SELECT ... GROUP, then ordered internally using COLLECT ... ORDER. The result - a table of ordered coordinates - is then passed to a function which joins individual points into a single geom using GeomMergePoints, then removes branches and puts all points into a single branch, then converts the result to line.&lt;/P&gt;&lt;P&gt;See attached MAP file.&lt;/P&gt;&lt;p class='file'&gt;&lt;b&gt;Attachments:&lt;/b&gt;&lt;br&gt;&lt;a href='bOTgvMTQzMjU2L2pvaW4tcG9pbnRzLWludG8tbGluZXMubXhi'&gt;&lt;img src='images/dwn-ftp.gif' align='absmiddle'&gt;&lt;/a&gt; &lt;a href='bOTgvMTQzMjU2L2pvaW4tcG9pbnRzLWludG8tbGluZXMubXhi'&gt;join-points-into-lines.mxb&lt;/a&gt;&lt;br&gt;&lt;/p&gt;</description><dc:creator>adamw</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143256</comments><guid>http://95.79.92.2:8080/forum/t143193#143256</guid><pubDate>Sat, 05 May 2018 13:49:05 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143299</link><description>&lt;P&gt;Hi Tim,&lt;/P&gt;&lt;P&gt;I am sometimes out of the office.  Please find the attached mxb file.  It includes some driving through country and a search through rainforest for rare flora, which is a very messy trail.  I am yet to test my data against Adams query.&lt;/P&gt;&lt;p class='file'&gt;&lt;b&gt;Attachments:&lt;/b&gt;&lt;br&gt;&lt;a href='bQzMvMTQzMjk5L1RyYWNrUG9pbnRzLm14Yg__'&gt;&lt;img src='images/dwn-ftp.gif' align='absmiddle'&gt;&lt;/a&gt; &lt;a href='bQzMvMTQzMjk5L1RyYWNrUG9pbnRzLm14Yg__'&gt;TrackPoints.mxb&lt;/a&gt;&lt;br&gt;&lt;/p&gt;</description><dc:creator>Forest</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143299</comments><guid>http://95.79.92.2:8080/forum/t143193#143299</guid><pubDate>Tue, 08 May 2018 00:42:02 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143307</link><description>&lt;P&gt;Well, here is what I did:&lt;/P&gt;&lt;P&gt;Opened the MXB. Created a new drawing on a new table, named it Lines.&lt;/P&gt;&lt;P&gt;Opened command window, copy / pasted the query from above, adjusted the names, and ran it:&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=c&gt;--SQL9&lt;/span&gt;&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=k&gt;FUNCTION&lt;/span&gt;&amp;#160;makeline(t&amp;#160;&lt;span class=k&gt;TABLE&lt;/span&gt;)&amp;#160;&lt;span class=k&gt;GEOM&lt;/span&gt;&amp;#160;&lt;span class=k&gt;AS&lt;/span&gt;&amp;#160;(&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&amp;#160;&lt;span class=k&gt;SELECT&lt;/span&gt;&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;GeomConvertToLine(GeomConvertToPoint(GeomMergePoints(&lt;span class=i&gt;[Geom]&lt;/span&gt;),&amp;#160;false))&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&amp;#160;&lt;span class=k&gt;FROM&lt;/span&gt;&amp;#160;t&lt;/P&gt;&lt;P class='code'&gt;)&amp;#160;&lt;span class=k&gt;END&lt;/span&gt;;&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=k&gt;DELETE&lt;/span&gt;&amp;#160;&lt;span class=k&gt;FROM&lt;/span&gt;&amp;#160;&lt;span class=i&gt;[Lines]&lt;/span&gt;;&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=k&gt;INSERT&lt;/span&gt;&amp;#160;&lt;span class=k&gt;INTO&lt;/span&gt;&amp;#160;&lt;span class=i&gt;[Lines]&lt;/span&gt;&amp;#160;(&lt;span class=i&gt;[Geom]&lt;/span&gt;)&lt;/P&gt;&lt;P class='code'&gt;&lt;span class=k&gt;SELECT&lt;/span&gt;&amp;#160;makeline((&lt;span class=k&gt;COLLECT&lt;/span&gt;&amp;#160;&lt;span class=i&gt;[Geom]&lt;/span&gt;&amp;#160;&lt;span class=k&gt;ORDER&lt;/span&gt;&amp;#160;&lt;span class=k&gt;BY&lt;/span&gt;&amp;#160;&lt;B&gt;&lt;span class=i&gt;[TrackPointID]&lt;/span&gt;&lt;/B&gt;))&amp;#160;&lt;span class=k&gt;FROM&lt;/span&gt;&amp;#160;&lt;B&gt;&lt;span class=i&gt;[TrackData]&lt;/span&gt;&lt;/B&gt;&lt;/P&gt;&lt;P class='code'&gt;&amp;#160;&amp;#160;&lt;span class=k&gt;GROUP&lt;/span&gt;&amp;#160;&lt;span class=k&gt;BY&lt;/span&gt;&amp;#160;&lt;B&gt;&lt;span class=i&gt;[LineID]&lt;/span&gt;&lt;/B&gt;;&lt;/P&gt;&lt;P&gt;This created 2 lines.&lt;/P&gt;&lt;P&gt;Opened the drawing. Noticed that I forgot to set the coordinate system, pressed Ctrl-1 to go to the Component pane. Clicked the button next to the coordinate system readout, selected Repair Initial Coordinate System - Latitude / Longitude.&lt;/P&gt;&lt;P&gt;Dropped the original drawing into the window with the lines. They lined up.&lt;/P&gt;</description><dc:creator>adamw</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143307</comments><guid>http://95.79.92.2:8080/forum/t143193#143307</guid><pubDate>Tue, 08 May 2018 09:11:52 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143312</link><description>&lt;P&gt;I have been meaning to post a detailed question on this, regarding coordinate order.&lt;/P&gt;&lt;P&gt;We can now intentionally (or just maybe, inadvertently) mess up the operation of a custom aggregate function like makeline() above, by adding a THREADS specifier (&amp;gt; 1) to the function’s embedded SELECT statement. Then the table passed to the function is not handled strictly in order, making line(s) short-circuited by spurious arcs (between branches constructed by different threads).&lt;/P&gt;&lt;P&gt;Is it always safe to assume—now and in the future—that an optimization like this will never be applied &lt;B&gt;automatically&lt;/B&gt; (that is, with no explicit THREADS specifier, or with explicit THREADS 1)? Even when passing a very large table?&lt;/P&gt;&lt;P&gt;If it is not completely safe, or might not be later, then that seems a good reason to always prefer a script function to build a custom aggregate, rather than an SQL function, I think?&lt;/P&gt;&lt;P&gt;[Added.] If this kind of automatic optimization might come later (even for SELECT inside FUNCTION), perhaps it would be good (and enough) to add a PRAGMA allowing automatic multi-threading to be disabled (per node I think?).&lt;/P&gt;</description><dc:creator>tjhb</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143312</comments><guid>http://95.79.92.2:8080/forum/t143193#143312</guid><pubDate>Tue, 08 May 2018 09:54:05 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143317</link><description>&lt;P&gt;We really don&amp;#39;t think we will be inserting THREADS automatically. The way to tell the system &amp;quot;use threads if this is beneficial and figure out how many is best as well&amp;quot; will be THREADS AUTO or something like this.&lt;/P&gt;</description><dc:creator>adamw</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143317</comments><guid>http://95.79.92.2:8080/forum/t143193#143317</guid><pubDate>Tue, 08 May 2018 10:05:28 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143318</link><description>&lt;P&gt;Great. That sounds clear and simple. Thanks Adam.&lt;/P&gt;</description><dc:creator>tjhb</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143318</comments><guid>http://95.79.92.2:8080/forum/t143193#143318</guid><pubDate>Tue, 08 May 2018 10:09:12 GMT</pubDate></item><item><title>RE: Making lines from point data</title><link>http://95.79.92.2:8080/forum/t143193#143325</link><description>&lt;P&gt;Thanks, Forest, for the .mxb and thanks, Adam, for the query!   This has been used in a &lt;B&gt;&lt;A HREF='https://www.youtube.com/watch?v=5sRYniibTQE'&gt;video&lt;/A&gt;&lt;/B&gt;.  :-)&lt;/P&gt;</description><dc:creator>Dimitri</dc:creator><comments>http://95.79.92.2:8080/forum/t143193#143325</comments><guid>http://95.79.92.2:8080/forum/t143193#143325</guid><pubDate>Tue, 08 May 2018 13:30:13 GMT</pubDate></item></channel></rss>