Manifold Community Site: Scripting point along line in M9http://www.georeference.org/forum/t143895Manifold Community Site threadhttp://www.georeference.org/forum/images/img-logo.pngManifold Community Site: Scripting point along line in M9http://www.georeference.org/forum/t143895RE: Scripting point along line in M9http://www.georeference.org/forum/t143895#143896<P>Hi, </P><P>I have the following M8 script to create points at every meter along every lines in a drawing. I would like to know if M9 is able to do that before converting the script. So, is it ?</P><P class='code'><span class=k>function</span>&#160;Main()&#160;{</P><P class='code'>//&#160;javascript</P><P class='code'>var&#160;lignes&#160;=&#160;Document.ComponentSet.Item(<span class=s>&quot;Lignes&quot;</span>);</P><P class='code'>Document.ComponentSet.Item(<span class=s>&quot;Points&quot;</span>).ObjectSet.RemoveAll();</P><P class='code'>var&#160;queryPoints&#160;=&#160;Document.ComponentSet.Item(<span class=s>&quot;Query_Points&quot;</span>);</P><P class='code'>var&#160;i&#160;=&#160;0;</P><P class='code'>var&#160;nb_Lignes&#160;=&#160;lignes.ObjectSet.Count;</P><P class='code'>var&#160;ligne_No&#160;=&#160;0;</P><P class='code'>var&#160;dist&#160;=&#160;0;</P><P class='code'>var&#160;point_No&#160;=&#160;<span class=s>&quot;&quot;</span>;</P><P class='code'>var&#160;longueur&#160;=&#160;0;</P><P class='code'>var&#160;table&#160;=&#160;lignes.OwnedTable.RecordSet;</P><P class='code'><span class=k>for</span>&#160;(&#160;i&#160;=&#160;0&#160;;&#160;i&#160;&lt;&#160;nb_Lignes&#160;;&#160;i++)</P><P class='code'>{</P><P class='code'>ligne_No&#160;=&#160;table.Item(i).Data(<span class=s>&quot;no_ligne&quot;</span>);</P><P class='code'>longueur&#160;=&#160;table.Item(i).Data(<span class=s>&quot;long&quot;</span>);</P><P class='code'><SPAN>&#160;</SPAN><span class=k>for</span>&#160;(&#160;dist&#160;=&#160;0&#160;;&#160;dist&#160;&lt;=&#160;longueur&#160;;&#160;dist++)</P><P class='code'><SPAN>&#160;</SPAN>{</P><P class='code'><SPAN>&#160;</SPAN>point_No&#160;=&#160;ligne_No&#160;+&#160;<span class=s>&quot;_&quot;</span>&#160;+&#160;dist;</P><P class='code'><SPAN>&#160;</SPAN></P><P class='code'><SPAN>&#160;</SPAN>queryPoints.Text&#160;=&#160;<span class=c>'Insert&#160;Into&#160;[Points]&#160;(&#160;[Geom&#160;(I)],&#160;[no_ligne],&#160;[no_point]&#160;)&#160;Values&#160;((Select&#160;LinePoint&#160;(GEO&#160;,'&#160;+&#160;dist&#160;+&#160;',&quot;m&quot;)&#160;from&#160;(Select&#160;[Geom&#160;(I)]&#160;As&#160;GEO&#160;from&#160;[Lignes]&#160;where&#160;ID&#160;=&#160;'+&#160;ligne_No&#160;+&#160;')),'+ligne_No+',&#160;&quot;'+point_No+'&quot;)';</span></P><P class='code'><SPAN>&#160;</SPAN>queryPoints.Run();</P><P class='code'><SPAN>&#160;</SPAN>}</P><P class='code'>}</P><P class='code'>}</P>vincenthttp://www.georeference.org/forum/t143895#143896http://www.georeference.org/forum/t143895#143896Thu, 14 Jun 2018 15:27:27 GMTRE: Scripting point along line in M9http://www.georeference.org/forum/t143895#143897<P>Yes, of course.</P><P>You can either use a script, as in 8 (see the <A HREF='http://manifold.net/doc/api/scripts-net.html'>API doc</A>, if you have issues figuring out what's what after reading the short set of overviews, ask here), or you can use GeomSegmentize in a query.</P>adamwhttp://www.georeference.org/forum/t143895#143897http://www.georeference.org/forum/t143895#143897Thu, 14 Jun 2018 16:21:18 GMTRE: Scripting point along line in M9http://www.georeference.org/forum/t143895#143901<P>Segmentize followed by Convert to Points transforms would have been nice, but Segmentize produces segments equal OR LESS than the specified value. I cannot use that. </P><P>Anything similar to M8's SQL LinePoint available ? </P>vincenthttp://www.georeference.org/forum/t143895#143901http://www.georeference.org/forum/t143895#143901Thu, 14 Jun 2018 17:31:14 GMTRE: Scripting point along line in M9http://www.georeference.org/forum/t143895#143908<P>We don't yet have the analog of LinePoint available in SQL. You can create one using a script.</P><P>But in general, aren't we always going to have a small segment at the end of each branch? If the end coordinate from that segment is unwanted, it can be filtered based on segment length.</P>adamwhttp://www.georeference.org/forum/t143895#143908http://www.georeference.org/forum/t143895#143908Fri, 15 Jun 2018 15:58:03 GMTRE: Scripting point along line in M9http://www.georeference.org/forum/t143895#143919<P>I think the most economical function, whether built-in or custom, would subdivide each branch of each input line (or area boundary) into sections of length L, with a flag to return the last point as well if there is some length left over at the end (for both areas and lines I think).</P><P>That would avoid unnecessary function calls (one call per &quot;LinePoint&quot; would be inefficient), bearing in mind that the most frequent use of the function would be to create a series of evenly-spaced points. </P><P>Needing just one point is less common, but if necessary that could be a separate function.</P><P>I have started sketching a script-function for this. All going well I will come back when it nearly works.</P>tjhbhttp://www.georeference.org/forum/t143895#143919http://www.georeference.org/forum/t143895#143919Sat, 16 Jun 2018 04:45:00 GMTRE: Scripting point along line in M9http://www.georeference.org/forum/t143895#143953<P>Interesting, Tim. </P><P>LinePoint is normalizing geometry I guess. Lines are splitted at intersections. I have one branche lines that I don't want to be splitted. To avoid that, I send each line in another drawing with an Insert Into via a script and a query. Then I run LinePoint on the drawing that contains only one line. A loop process all lines, one by one. The output I what I need. </P><P>So, this is working. But obviously, I'm looking for more speed, considering the number of lines and points to process. </P><P>Using your idea of splitting lines into 1 meter sections and returning the end point might be faster in M9 than my script in M8. </P><P>Modified script goes like : </P><P class='code'><span class=k>function</span>&#160;Main()&#160;{</P><P class='code'>//&#160;javascript</P><P class='code'>var&#160;lignes&#160;=&#160;Document.ComponentSet.Item(<span class=s>&quot;Lignes&quot;</span>);</P><P class='code'>var&#160;lignesIsol&#160;=&#160;Document.ComponentSet.Item(<span class=s>&quot;Lignes_isolees&quot;</span>);</P><P class='code'>Document.ComponentSet.Item(<span class=s>&quot;Points&quot;</span>).ObjectSet.RemoveAll();</P><P class='code'>lignesIsol.ObjectSet.RemoveAll();</P><P class='code'>var&#160;queryPoints&#160;=&#160;Document.ComponentSet.Item(<span class=s>&quot;Query_Points&quot;</span>);</P><P class='code'>var&#160;i&#160;=&#160;0;</P><P class='code'>var&#160;nb_Lignes&#160;=&#160;lignes.ObjectSet.Count;</P><P class='code'>var&#160;ligne_No&#160;=&#160;0;</P><P class='code'>var&#160;dist&#160;=&#160;0;</P><P class='code'>var&#160;point_No&#160;=&#160;<span class=s>&quot;&quot;</span>;</P><P class='code'>var&#160;longueur&#160;=&#160;0;</P><P class='code'>var&#160;table&#160;=&#160;lignes.OwnedTable.RecordSet;</P><P class='code'>var&#160;table2&#160;=&#160;lignesIsol.OwnedTable.RecordSet;</P><P class='code'>var&#160;indexL&#160;=&#160;0;</P><P class='code'>//<span class=k>for</span>&#160;(&#160;i&#160;=&#160;0&#160;;&#160;i&#160;&lt;&#160;nb_Lignes&#160;;&#160;i++)</P><P class='code'><span class=k>for</span>&#160;(&#160;i&#160;=&#160;0&#160;;&#160;i&#160;&lt;&#160;4&#160;;&#160;i++)</P><P class='code'>{</P><P class='code'>indexL&#160;=&#160;table.Item(i).Data(<span class=s>&quot;ID&quot;</span>);</P><P class='code'>queryPoints.Text&#160;=&#160;<span class=c>'Insert&#160;Into&#160;[Lignes_isolees]&#160;Select&#160;*&#160;from&#160;[Lignes]&#160;where&#160;[ID]&#160;=&#160;'&#160;+&#160;indexL&#160;;</span></P><P class='code'>queryPoints.Run();</P><P class='code'>ligne_No&#160;=&#160;table2.Item(0).Data(<span class=s>&quot;no_ligne&quot;</span>);</P><P class='code'>longueur&#160;=&#160;table2.Item(0).Data(<span class=s>&quot;long&quot;</span>);</P><P class='code'><SPAN>&#160;</SPAN><span class=k>for</span>&#160;(&#160;dist&#160;=&#160;0&#160;;&#160;dist&#160;&lt;=&#160;longueur&#160;;&#160;dist++)</P><P class='code'><SPAN>&#160;</SPAN>{</P><P class='code'><SPAN>&#160;</SPAN>point_No&#160;=&#160;ligne_No&#160;+&#160;<span class=s>&quot;_&quot;</span>&#160;+&#160;dist;</P><P class='code'><SPAN>&#160;</SPAN>queryPoints.Text&#160;=&#160;<span class=c>'Insert&#160;Into&#160;[Points]&#160;(&#160;[Geom&#160;(I)],&#160;[no_ligne],&#160;[no_point]&#160;)&#160;Values&#160;((Select&#160;LinePoint&#160;(GEO&#160;,'&#160;+&#160;dist&#160;+&#160;',&quot;m&quot;)&#160;from&#160;(Select&#160;[Geom&#160;(I)]&#160;As&#160;GEO&#160;from&#160;[Lignes_isolees]&#160;where&#160;[no_ligne]&#160;=&#160;'+&#160;ligne_No&#160;+&#160;')),'+ligne_No+',&#160;&quot;'+point_No+'&quot;)';</span></P><P class='code'><SPAN>&#160;</SPAN>queryPoints.Run();</P><P class='code'><SPAN>&#160;</SPAN>}</P><P class='code'>lignesIsol.ObjectSet.RemoveAll();</P><P class='code'>}</P><P class='code'>}</P>vincenthttp://www.georeference.org/forum/t143895#143953http://www.georeference.org/forum/t143895#143953Mon, 18 Jun 2018 14:09:41 GMTRE: Scripting point along line in M9http://www.georeference.org/forum/t143895#143956<P>I removed the WHERE clause in the last loop. It was no longer useful. Interesting speed gain.</P>vincenthttp://www.georeference.org/forum/t143895#143956http://www.georeference.org/forum/t143895#143956Mon, 18 Jun 2018 15:16:48 GMTRE: Scripting point along line in M9http://www.georeference.org/forum/t143895#143995<P>Could you post example MAP file with model data? (Just want to match the input / output exactly.)</P>adamwhttp://www.georeference.org/forum/t143895#143995http://www.georeference.org/forum/t143895#143995Thu, 21 Jun 2018 16:31:17 GMTRE: Scripting point along line in M9http://www.georeference.org/forum/t143895#144009<P>I built a sequence generator based on one of your old post. Amazingly fast ! </P><P class='code'><span class=c>--SQL</span></P><P class='code'><span class=k>SELECT</span>&#160;</P><P class='code'>&#160;</P><P class='code'>&#160;&#160;LinePoint(d.<span class=i>[geom&#160;(i)]</span>,&#160;a.v*1)</P><P class='code'>&#160;</P><P class='code'><span class=k>FROM</span>&#160;<span class=i>[Lignes&#160;3]</span>&#160;<span class=k>AS</span>&#160;d,</P><P class='code'>(<span class=k>SELECT</span>&#160;(a4.v*1000&#160;+&#160;a3.v*100&#160;+&#160;a1.v*10&#160;+&#160;a2.v)&#160;&#160;<span class=k>AS</span>&#160;v&#160;<span class=k>FROM</span></P><P class='code'>((<span class=k>VALUES</span>&#160;(0),&#160;(1),&#160;(2),&#160;(3),&#160;(4),&#160;(5),&#160;(6),&#160;(7),&#160;(8),&#160;(9)&#160;<span class=k>NAMES</span>&#160;(v))&#160;<span class=k>AS</span>&#160;a1,</P><P class='code'>&#160;(<span class=k>VALUES</span>&#160;(0),&#160;(1),&#160;(2),&#160;(3),&#160;(4),&#160;(5),&#160;(6),&#160;(7),&#160;(8),&#160;(9)&#160;<span class=k>NAMES</span>&#160;(v))&#160;<span class=k>AS</span>&#160;a2,</P><P class='code'>(<span class=k>VALUES</span>&#160;(0),&#160;(1),&#160;(2),&#160;(3),&#160;(4),&#160;(5),&#160;(6),&#160;(7),&#160;(8),&#160;(9)&#160;<span class=k>NAMES</span>&#160;(v))&#160;&#160;<span class=k>AS</span>&#160;a3,</P><P class='code'>(<span class=k>VALUES</span>&#160;(0),&#160;(1),&#160;(2),&#160;(3),&#160;(4),&#160;(5),&#160;(6),&#160;(7),&#160;(8),&#160;(9)&#160;<span class=k>NAMES</span>&#160;(v))&#160;&#160;<span class=k>AS</span>&#160;a4</P><P class='code'>))</P><P class='code'><span class=k>As</span>&#160;a</P><P class='code'>&#160;<span class=k>WHERE</span>&#160;d.<span class=i>[length&#160;(i)]</span>&#160;&gt;=&#160;a.v*1</P>vincenthttp://www.georeference.org/forum/t143895#144009http://www.georeference.org/forum/t143895#144009Fri, 22 Jun 2018 17:14:38 GMTRE: Scripting point along line in M9http://www.georeference.org/forum/t143895#144010<P>SQL9 has dedicated syntax for that: ValueSequence(). Much more flexible, and completely succinct.</P><P>And post some sample data! Adam is offering a full script. I am still working on it too, but am glad if that will be irrelevant now.</P>tjhbhttp://www.georeference.org/forum/t143895#144010http://www.georeference.org/forum/t143895#144010Fri, 22 Jun 2018 18:34:33 GMT