[postgis-tickets] [SCM] PostGIS branch master updated. 3.1.0rc1-416-g529e39e

git at osgeo.org git at osgeo.org
Sat Aug 21 16:11:11 PDT 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, master has been updated
       via  529e39e929108a5d7fbd641ab3c2cd490a76008d (commit)
      from  a7990f671d1a8c4f56e3f0b25a6784c91774555f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 529e39e929108a5d7fbd641ab3c2cd490a76008d
Author: Martin Davis <mtnclimb at gmail.com>
Date:   Sat Aug 21 16:11:07 2021 -0700

    Fix doc ST_LineSubstring example

diff --git a/doc/reference_lrs.xml b/doc/reference_lrs.xml
index 7ef7a77..b114516 100644
--- a/doc/reference_lrs.xml
+++ b/doc/reference_lrs.xml
@@ -406,31 +406,35 @@ SELECT ST_AsText(ST_LineSubstring( 'LINESTRING(25 50, 100 125, 150 190)', 0.333,
 
 
 <para>
-A query to cut a LineString into sections of length 100 or less.
-It uses <varname>generate_series()</varname> which creates an implicit JOIN LATERAL
+A query to cut a LineString into sections of length 100 or shorter.
+It uses <varname>generate_series()</varname> with a CROSS JOIN LATERAL
 to produce the equivalent of a FOR loop.
 </para>
 <programlisting>
 WITH data(id, geom) AS (VALUES
-    ( 'a1', 'LINESTRING (0 0, 250 0)'::geometry )
-)
-SELECT id, n, ST_AsText( ST_LineSubstring(geom, n * frac,
-                  CASE
-                  WHEN (n+1) * frac  < 1 THEN (n+1) * frac
-                  ELSE 1
-                  END )) AS geom
-FROM
-  (SELECT id, geom, ST_Length(geom) AS len,
-          100.0 / ST_Length(geom) AS frac,
-          generate_series(0, floor(ST_Length(geom) / 100.0)::integer ) AS n
-  FROM data
-  ) AS t;
-
- id | n |          geom
-----+---+-------------------------
- a1 | 0 | LINESTRING(0 0,100 0)
- a1 | 1 | LINESTRING(100 0,200 0)
- a1 | 2 | LINESTRING(200 0,250 0)
+        ( 'A', 'LINESTRING( 0 0, 200 0)'::geometry ),
+        ( 'B', 'LINESTRING( 0 100, 350 100)'::geometry ),
+        ( 'C', 'LINESTRING( 0 200, 50 200)'::geometry )
+    )
+SELECT id, i, ST_AsText( ST_LineSubstring( d.geom, startfrac, LEAST( endfrac, 1 )) ) AS geom
+FROM (SELECT id, geom, ST_Length(geom) len, 100 sublen FROM data) AS d
+CROSS JOIN LATERAL (
+    SELECT i, (sublen * i) / len AS startfrac,
+              (sublen * (i+1)) / len AS endfrac
+        FROM generate_series(0, floor( d.len / sublen )::integer ) AS t(i)
+        -- skip last i if line length is exact multiple of sublen
+        WHERE (sublen * i)/len <> 1.0
+    ) AS d2;
+
+ id | i |            geom
+----+---+-----------------------------
+ A  | 0 | LINESTRING(0 0,100 0)
+ A  | 1 | LINESTRING(100 0,200 0)
+ B  | 0 | LINESTRING(0 100,100 100)
+ B  | 1 | LINESTRING(100 100,200 100)
+ B  | 2 | LINESTRING(200 100,300 100)
+ B  | 3 | LINESTRING(300 100,350 100)
+ C  | 0 | LINESTRING(0 200,50 200)
 </programlisting>
 		  </refsection>
 

-----------------------------------------------------------------------

Summary of changes:
 doc/reference_lrs.xml | 46 +++++++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 21 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list