5

I created a set of points by intersecting a linestring layer with the boundary of a multipolygon layer like this:

CREATE TABLE freiraumkataster_grenze AS
SELECT
gid,
ST_CollectionHomogenize(ST_Collect(ST_Boundary(geom))) AS geom
FROM
(SELECT
    gid,
    (ST_Dump(geom)).geom As geom
FROM freiraumkataster fk
) As foo
GROUP BY gid;

And

CREATE TABLE zugaenge AS
SELECT
w.gid as wgid,
ST_Intersection(w.geom, fkg.geom) as geom
FROM
wegenetz w
LEFT JOIN freiraumkataster_grenze fkg
ON ST_Intersects(w.geom, fkg.geom);

Now I try to split the linestrings of wegenetz at the location of the points of zugaenge. Since they are created on locations where the two layer intersect, this seems to be an easy task.

I read about ST_Split and learned that it has (had?) problems with multigeometries, so I used the (old?) wrapper from here: Split lines into non-overlapping subsets based on points With the magic:

result := input_geom;           
-- Loop on all the points in the blade
FOR simple_blade IN SELECT (ST_Dump(ST_CollectionExtract(blade, 1))).geom
LOOP
    -- keep splitting the previous result
    result := ST_CollectionExtract(ST_Split(result, simple_blade), 2);
END LOOP;
RETURN result;

In my (limited) understanding of this, ST_Split(result, simple_blade) should work and should produce a geometrycollection containing at least two line strings in the case any intersection is found. But it won't do that. The result stays the same single-piece linestring I put into it.

I convert the multipoint layer to singlepoint:

CREATE TABLE zugaenge_single AS
SELECT
wgid,
ST_GeometryN(geom, generate_series(1, ST_NumGeometries(geom))) AS geom 
FROM zugaenge;

And group them, so there is one multipoint geometry for each linestring.

CREATE TABLE zugaenge_pro_weg AS
SELECT wgid, ST_Union(geom) as geom 
FROM zugaenge_single GROUP BY wgid;

And then I run the geometries (line string and multipoint) through the wrapper.

CREATE TABLE wegenetz_splitted AS
SELECT 
split_line_multipoint(w.geom, z.geom) as geom,
w.gid as wgid
FROM 
wegenetz w
LEFT JOIN 
zugaenge_pro_weg z 
ON w.gid=z.wgid;

This results in the same geometry as I find in wegenetz, the layer I put into it.

Why is it that way? Why isn't any intersection found? Or do I use any function totally wrong? I even tried to use ST_Split() right away instead of the wrapper, since it should be able to do this task since 2.2, but the result stays the same.

I also tried to enhance the wrapper by using

result := ST_CollectionExtract(ST_Split(result, ST_ClosestPoint(result, simple_blade), 2);

in case there is a precision problem present. But no change despite a longer run time.

What is it, I can't see?

  • Just a thought, since you are creating a number of tables along the way. If you import each of these tables to QGIS you can verify what each step does visually. – Nate Wanner Feb 3 '17 at 1:19

Your Answer

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

Browse other questions tagged or ask your own question.