[postgis-users] River dataset

Marcin Mionskowski mionskowskimarcin at gmail.com
Fri Oct 5 02:28:01 PDT 2018


In your original mail the image didn't attach as Darafei wrote. Because of that i think that you should tell us how you need the split to be done.
Can it be done in "custom" direction, or you need it to be "perpendicular to the river"?
1) If 1st - I would suggest to simply intersect your polygons with generated lines (see code below).
2) If 2nd, then how you want this perpendicularity to be defined?
Is it supposed to be perpendicular to the river axis/side? How the right axis/side should be determined? Can you draw a line "by hand" or does it have to be calculated? Do you realize that lines generated this way, can and probably will intersect?

Take a look at SQL below. It's little long, but also clear (in my opinion), and it shows my approach step by step.

WITH
floodplain AS (
	SELECT ST_SetSRID(ST_MakePolygon(
		ST_GeomFromText('LINESTRING(100000 100000,100004 100000,100004 100004,100000 100004,100000 100000)'),
			ARRAY[ST_GeomFromText('LINESTRING(100002 100002,100002 100003,100003 100003,100003 100002,100002 100002)')]
			),3035) geom
	)
, river AS (
	SELECT ST_SetSRID(ST_MakePolygon(
		ST_GeomFromText('LINESTRING(100001 100000,100003 100000,100000 100003,100000 100002,100001 100000)')
		),3035) geom
	)
, min_max AS ( --I assume that floodplain polygon covers river polygon (https://postgis.net/docs/ST_Covers.html).
	SELECT ST_XMin(geom) xmin
		, ST_XMax(geom) xmax
		, ST_YMin(geom) ymin
		, ST_YMax(geom) ymax
	FROM floodplain
	)
, gs AS (
	SELECT generate_series(ymin::INT,ymax::INT,1) gs --last parameter is not required, change 1 to 0.5 for "better looking" numeric results in my example
	FROM min_max
	)
, splitlines AS (
	SELECT ST_SetSRID(ST_MakeLine(ST_MakePoint(xmin, gs), ST_MakePoint(xmax, gs)),3035) geom
	FROM gs
		, min_max
	)
SELECT ST_Length(ST_Intersection(r.geom,s.geom)) river_width
	,ST_Length(ST_Intersection(f.geom,s.geom)) floodplain_width
	,ST_Length(ST_Intersection(r.geom,s.geom))/ST_Length(ST_Intersection(f.geom,s.geom)) river_floodplain_ratio
 FROM floodplain f
	, river r
	, splitlines s

Greetings,
Marcin

On Wed, 03 Oct 2018 15:18:19 +0200, Shane Carey <careyshan at gmail.com> wrote:

> Hi,
>
> Just wondering  did anyone have a chance to look at my issue with regards
> the river and polygon dataset that I was trying to split up?
>
> Thanks
>
> Le gach dea ghui,
> *Shane Carey*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rf1.png
Type: image/png
Size: 11991 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20181005/d189ffad/attachment.png>


More information about the postgis-users mailing list