convert multilinestring (with small gaps) to linestring?

2,512 views
Skip to first unread message

Richard Males

unread,
Mar 13, 2013, 5:26:06 PM3/13/13
to spatiali...@googlegroups.com
I have imported a legacy shapefile that was poorly digitized into spatialite.  Some of the features come in as multi-part geometries (e.g. multilinestring with more than one linestring), e.g.:

MULTILINESTRING((-90.019707 29.98066, -90.019656 29.980831, -90.019239 29.980748, -90.019096 29.981058, -90.019051 29.981149, -90.01898 29.981285), (-90.018976 29.981288, -90.018856 29.981499, -90.018758 29.98166, -90.018718 29.981747, -90.017807 29.982343, -90.017308 29.98243))

I would like an automated procedure to convert this multilinestring to a linestring, either by creating a line segment between the end point of the first linestring and the start point of the second line string, or merging the two points.   I have tried various approaches using ST_LineMerge, ST_GeometryN, ST_Collect, etc., none seem to give me what I want.  The only way I seem to be able to do this in QGIS is via manual editing.

Any suggestions (Spatialite preferably or QGIS) would be appreciated.

Thanks in advance.



a.fu...@lqt.it

unread,
Mar 14, 2013, 9:59:38 AM3/14/13
to spatiali...@googlegroups.com
On Wed, 13 Mar 2013 14:26:06 -0700 (PDT), Richard Males wrote:
> Any suggestions (Spatialite preferably or QGIS) would be appreciated.
>

Hi Richard,

the problem in your sample MultiLinestring is in that there is no
overlapping point allowing to reconnect both parts into a single
Linestring.
As you correctly state, "there are small gaps"; anyway from the
topology POV, "huge gaps" and "micro gaps" are absolutely one the
same ... they are just gaps :-)
Consequently, none of ST_LineMerge() and friends will never be
able to be successful.

a possible alternative approach:
a) dissolve first your MultiLinestrings into a MultiPoint
b) then rebuild a Linestring passing for all Points defined within
the above MultiPoint.

SELECT AsText(MakeLine(DissolvePoints(GeomFromText(
'MULTILINESTRING((-90.019707 29.98066, -90.019656 29.980831,
-90.019239 29.980748, -90.019096 29.981058, -90.019051
29.981149,
-90.01898 29.981285), (-90.018976 29.981288, -90.018856
29.981499,
-90.018758 29.98166, -90.018718 29.981747, -90.017807 29.982343,
-90.017308 29.98243))'
)), 1));
----------------------------
LINESTRING(-90.019707 29.98066, -90.019656 29.980831, -90.019239
29.980748, \
-90.019096 29.981058, -90.019051 29.981149, -90.01898 29.981285, \
-90.018976 29.981288, -90.018856 29.981499, -90.018758 29.98166, \
-90.018718 29.981747, -90.017807 29.982343, -90.017308 29.98243)


PLEASE NOTE WELL: the above SQL snippet requires the next to come
v.4.1.0 :-)

for more details, please see:
https://www.gaia-gis.it/fossil/libspatialite/wiki?name=4.1.0+Changes#geom

The current v.4.0.0 already supports MakeLine() [aggregate function],
but
this requires a previous separation of all Points from the MultiPoint
as
individual items.
surely possible, using the spatialite_gui "elementary geometries" tool:
anyway this is rather complex and not at all straightforwards.
The next-to-come implementation will surely be easier to be used.

bye Sandro

--
Il messaggio e' stato analizzato alla ricerca di virus o
contenuti pericolosi da MailScanner, ed e'
risultato non infetto.

Jukka Rahkonen

unread,
Mar 14, 2013, 10:48:34 AM3/14/13
to spatiali...@googlegroups.com
Hi,

You can try the OpenJUMP Network topology cleaning plugin from OpenJUMP
Plus version. Download it from the development snapshots
https://sourceforge.net/projects/jump-pilot/files/OpenJUMP_snapshots/

I made an illustrated how-to
http://latuviitta.org/documents/Snapping%20the%20linestring%20gaps%20with%20OpenJUMP.pdf

As a first step you can convert the whole layer into LineStrings by using
Tools - Edit Geometry - Convert Selected Geometries/Layer to - LineString.

-Jukka Rahkonen-
> --
> You received this message because you are subscribed to the Google Groups
> "SpatiaLite Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to spatialite-use...@googlegroups.com.
> To post to this group, send email to spatiali...@googlegroups.com.
> Visit this group at http://groups.google.com/group/spatialite-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


Richard Males

unread,
Mar 14, 2013, 10:49:37 AM3/14/13
to spatiali...@googlegroups.com
Thank you for your reply.   I understand, of course, that from a topology point of view, a gap is a gap, but many spatial functions utilize distance tolerances.  For my case, your solution will work just fine.   Any thoughts on expected release date of 4.1.0?

Dick




--
You received this message because you are subscribed to a topic in the Google Groups "SpatiaLite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spatialite-users/ORop9dcxr9s/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to spatialite-users+unsubscribe@googlegroups.com.
To post to this group, send email to spatialite-users@googlegroups.com.

a.fu...@lqt.it

unread,
Mar 14, 2013, 10:55:55 AM3/14/13
to spatiali...@googlegroups.com
> Any thoughts on expected release date of 4.1.0?
>

As soon as possible :-)

I'm just finishing to write the accompanying docs, performing
the final tests ... and alike

Next week is expected to be released the most recent SQLite 3.7.16
http://www.sqlite.org/draft/releaselog/3_7_16.html

I hope to be able releasing 4.1.0-RC1 immediately after.

a.fu...@lqt.it

unread,
Mar 14, 2013, 11:21:27 AM3/14/13
to spatiali...@googlegroups.com
On Thu, 14 Mar 2013 10:49:37 -0400, Richard Males wrote:
> I understand, of course, that from a
> topology point of view, a gap is a gap, but many spatial functions
> utilize distance tolerances. 
>

Richard,

you can attempt using ST_Snap() in order to "clean" a dataset
presenting
very poor topology self-consistency.

https://www.gaia-gis.it/fossil/libspatialite/wiki?name=liblwgeom-4.0
Reply all
Reply to author
Forward
0 new messages