[postgis-users] splitting linestrings with a polygon

paul.malm at lfv.se paul.malm at lfv.se
Tue Aug 20 04:15:11 PDT 2019


Thanks, Nicolas!

Från: postgis-users [mailto:postgis-users-bounces at lists.osgeo.org] För Nicolas Ribot
Skickat: den 20 augusti 2019 09:21
Till: PostGIS Users Discussion
Ämne: Re: [postgis-users] splitting linestrings with a polygon

Hi,

Keep the geometry column as multilinestring, as resulting splitting can produce such objects, but add a st_multi after the intersection, on the update clause:
... SET the_geom = st_multi(ST_Intersection(b.the_geom, p.the_geom))

It will force geometries to be multi, even if it only contains one object.
You can also extract the linear part of the intersection (as it can returns point, line, or combination of both):
... SET the_geom = st_multi(st_collectionExtract(ST_Intersection(b.the_geom, p.the_geom), 2))

Nicolas

On Tue, 20 Aug 2019 at 09:09, <paul.malm at lfv.se<mailto:paul.malm at lfv.se>> wrote:
Hi, I have a problem with MultiLinestrings/Linestrings.
I have one layer with Linestrings which I would like to split in the intersections of a polygon (MultiPolygon) in a polygon layer.

I tried this:
UPDATE public."linelayer" b
    SET the_geom = ST_Intersection(b.the_geom, p.the_geom)
    FROM public."polygonlayer" p
    WHERE ST_Intersects(b.the_geom, p.the_geom)


I’m getting this error: ERROR: Geometry type (MultiLineString) does not match column type (LineString) SQL state: 22023

Then I tried to make the Linsestrings to MultiLinestrings, before splitting the lines:
ALTER TABLE public."linelayer" ALTER COLUMN "the_geom" TYPE geometry(MultiLinestring,"32633") USING ST_Multi("the_geom")

And tried to split the lines again with the first expression, but gets this opposite error instead:
ERROR: FEL: Geometry type (LineString) does not match column type (MultiLineString) SQL state: 22023

What is it that I missed with MultiLinestring/Linestring?

What the heck can I do, seems like “Moment 22”?
Kind regards,
Paul

_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org<mailto:postgis-users at lists.osgeo.org>
https://lists.osgeo.org/mailman/listinfo/postgis-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20190820/f557c4a9/attachment.html>


More information about the postgis-users mailing list