Adding a coustom point as new node to an existing (Multi)Polygon or (Multi)LineString

28 views
Skip to first unread message

HansGIS

unread,
Nov 25, 2016, 8:37:47 AM11/25/16
to SpatiaLite Users
Hello,

I was trying to find a way how to add a custom point as new node to an existing (Multi)Polygon or (Multi)LineString.

Googling did not bring me further to a solution.
The only relevant finding was Adding Nodes to Linestrings at Overlapping Points with Polygon Layer in Spatialite on stackexchange. Maybe I missed something.

The original Problem I'm trying to solve is illustrated in the example sketch below. I'd like to add node 5 to Polygon 1 between node 1 and and node 2 so I can dissolve Polygon 1 and 2 with ST_Union(). This Process is supposed to work between two (Multi)Polygons or two (Multi)LineStrings.

Any helpful hint is much appreciated.

a.fu...@lqt.it

unread,
Nov 25, 2016, 9:06:55 AM11/25/16
to spatiali...@googlegroups.com
On Fri, 25 Nov 2016 05:37:47 -0800 (PST), HansGIS wrote:
> Hello,
>
> I was trying to find a way how to add a custom point as new node to
> an
> existing (Multi)Polygon or (Multi)LineString.
>

you can simply use ST_AddPoint()

http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.3.0.html#p7

caveat: this function accepts a single LineString or Ring, so
you must extract first (and then replace) the appropriate
Linesstring or Ring from within your complex (Multi)Polygon
or (Multi)Linestring.

bye Sandro

mj10777

unread,
Nov 25, 2016, 9:21:57 AM11/25/16
to SpatiaLite Users
INSERT INTO  create_cutline_linestrings  (name, cutline_linestring)
SELECT
 "Shortest Line between 'Big Polygon' and point 2 of 'Small Polygon",
 ST_ShortestLine
 (
   (SELECT cutline_polygon FROM create_cutline_polygons WHERE (name="Big Polygon")), 
   -- point 2 of the "Small Polygon" corresponds to your point 5 of Polygon 2
   (SELECT ST_PointN(ST_ExteriorRing(cutline_polygon),2) FROM create_cutline_polygons WHERE (name="Small Polygon"))
 ) AS shorestline
;
INSERT INTO  create_cutline_points  (name, cutline_point)
SELECT
 "First point of Shortest Line on 'Big Polygon' from 'Small Polygon",
  (SELECT ST_PointN(cutline_linestring,1) FROM create_cutline_linestrings WHERE (name="Shortest Line between 'Big Polygon' and point 2 of 'Small Polygon")) AS first_point
;

 


Reply all
Reply to author
Forward
0 new messages