2

I want to create a LINESTRING from a MULTILINESTRING. However in the following case ST_MultiLineString is returned:

Select ST_GeometryType(ST_LineMerge(ST_AsText('
MULTILINESTRING(
(-70.52570888 -33.48112668,-70.52552472 -33.48116414),
(-70.52552472 -33.48116414,-70.52453208 -33.48121471,-70.52552472 -33.48116414)
)')));

Why is this the case? The linestrings are not self intersecting and are connected. How can I resolve this?

3

Reason is probably in accuracy of numeric computing. Removing the last decimal from the Y coordinate of the connecting points is enough for making the query to return LINESTRING

SELECT ST_AsText(ST_LineMerge(
ST_GeomFromText('MULTILINESTRING(
(-70.52570888 -33.48112668,-70.52552472 -33.4811641),
(-70.52552472 -33.4811641,-70.52453208 -33.48121471,-70.52552472 -33.48116414)
)')));

EDIT:

It is possible to drop decimals on-the-fly by using function ST_SnapToGrid:

SELECT ST_AsText(ST_LineMerge(ST_SnapToGrid(
    ST_GeomFromText('MULTILINESTRING(
    (-70.52570888 -33.48112668,-70.52552472 -33.48116414),
    (-70.52552472 -33.48116414,-70.52453208 -33.48121471,-70.52552472 -33.48116414)
    )'),0.001)));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.