Create equally spaced lines within a polygon

1,437 views
Skip to first unread message

Karl Zinglersen

unread,
Nov 29, 2013, 12:25:53 PM11/29/13
to postgi...@googlegroups.com
I need to create transect lines across polygons for planning aerial surveys for musk oxen and caribous in Greenland.
1. In QGIS I have made polygons of the polygon zones for each survey. Each polygon hold an attribute of spacing value, e.g. 5, 10 and 20 km.
2. Lines must be equally spaced and parallel.
3. Lines must be perpendicular to the polygon centerline.
4. Centerline must run at the longest distance across the polygon - and consequently the transects run as the shorter distances.
I've attached a hand made sketch, which display the concept.

I've tried this query
SELECT GENERATE_SERIES(FLOOR(ST_YMin(the_polygon))::int , CEILING(ST_YMax(the_polygon))::int,200) y_value, ST_XMin(the_polygon) x_min, ST_XMax(the_polygon) x_max from 
            (SELECT the_geom AS the_polygon FROM lakes) l

SELECT ST_Intersection(the_geom, the_polygon)  AS the_geom FROM
    (SELECT the_polygon, ST_Setsrid(ST_MakeLine(ST_MakePoint(x_min, y_value),ST_MakePoint(x_max, y_value) ), ST_Srid(the_polygon)) AS the_geom FROM 
        (SELECT the_polygon, GENERATE_SERIES(FLOOR(ST_YMin(the_polygon))::int , CEILING(ST_YMax(the_polygon))::int,200) y_value, ST_XMin(the_polygon) x_min, ST_XMax(the_polygon) x_max from 
            (SELECT the_geom AS the_polygon FROM lakes) l
        )
) lines 


however these transects runs horisontally and don't seem to take into account the shape and rotation of the polygon centerline.

Should I be able to change the query or should take a different approach?

Karl Zinglersen
sketch.png

Nicolas Ribot

unread,
Nov 30, 2013, 11:21:46 AM11/30/13
to PostGIS Users Discussion
Hi,

You should look at this french article for skeletonization of
irregular polygons. The st_delaunayTriangles method can also help.
Note that the middle line of a polygon is not always a straight line.
Then, using linear referencing, it should be easy to walk the middle
line to create perpendicular segments.

Nicolas
> _______________________________________________
> postgis-users mailing list
> postgi...@lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
postgi...@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

Karl Zinglersen

unread,
Dec 3, 2013, 1:04:37 PM12/3/13
to postgi...@googlegroups.com, nicola...@gmail.com, PostGIS Users Discussion
Hi, I believe I was unclear - the centerlines have to straight. But I'll keep in mind your reference to delauney triangles and skeletonization for future purposes.
To create the centerline a manual sketch is probably OK. Could I then just move on with linear referencing? Which function should I use - most seems to be percentages of a linestring.

Karl

Rémi Cura

unread,
Dec 3, 2013, 1:28:56 PM12/3/13
to PostGIS Users Discussion, postgi...@googlegroups.com, nicola...@gmail.com
Hm what you seem to do is
compute a minimal bouding box (not aligned with NS or EW),
then use the greatest side as a reference, translate it so it passes by the center of this bbox,
then several times offset the shortest side by a small step in the normal direction, until you are out of the bounding box.
After this, keep only part of the created geom that are inside polygon.

I suspect this is not at all optimal, but your handdrawing is not precise enough (what if the survey zone is a donut?).

It is not difficult but need some time, now the shopping :
_minimal bounding box (not axis aligned) :http://en.wikipedia.org/wiki/Minimum_bounding_box_algorithms,
if perf is not a factor, you can try rotate your polygon by 10 degree steps (36 steps), taking the rotation that gives the smallest box, then rotate this box of the same amount.
_translate : http://postgis.net/docs/ST_Translate.html
_offset : http://postgis.net/docs/ST_OffsetCurve.html (by choosing the sign you take care of the normal thing)
And you didn't tell why you would need "linear referencing" ...
Good luck with that,

Cheers,

Rémi-C






2013/12/3 Karl Zinglersen <karl.zi...@gmail.com>

Nicolas Ribot

unread,
Dec 5, 2013, 8:19:20 AM12/5/13
to postgi...@googlegroups.com, PostGIS Users Discussion
Hi,

If baseline is straight and can be drawn, I was thinking about linear
referencing to identify steps for perpendicular lines, then using
translate/rotate operations to move the centerline to each point and
to rotate it to create perpendicular segments.
Then an intersection is done with original polygon to cut segments:

The below query shows the steps in separate CTE's to illustrate. they
could be grouped:
On the attached picture, the red points are steps (70 units in my
example) computed from the centerline.

with iter as (
    -- computes the number of steps required to cut the centerline by a fixed distance (70m here)

    select generate_series(1,ceil(st_length(geom)/70)::int) as idx, ceil(st_length(geom)/70)::int as steps
    from centerline
), npoints as (
   -- computes the point geometries with LR functions

    select  idx, steps, st_lineInterpolatePoint(p.geom, (idx::double precision/steps::double precision)) as pt, p.geom
    from iter n, centerline p
), rot_trans as (
   -- translate the centerline to move it to one step point (center of line is taken for the move, then rotate it by pi/2 around
   -- the step point to create perpendicular segment

    select st_rotate(st_translate(n.geom,
        st_x(n.pt) - st_X(st_lineInterpolatePoint(n.geom, 0.5)),
--xcenter -xtarget,
        st_y(n.pt)   - st_Y(st_lineInterpolatePoint(n.geom, 0.5))),
--ycenter - ytarget
        pi()/2, n.pt) as geom
    from npoints n
)
-- finaly, cut each segment by the original polygon

select st_intersection(r.geom, t.geom) as geom
from rot_trans r, testpg t;


Nicolas
Screen Shot 2013-12-05 at 2.17.40 PM.png

Nicolas Ribot

unread,
Dec 5, 2013, 8:23:13 AM12/5/13
to Karl Zinglersen, postgi...@googlegroups.com, PostGIS Users Discussion
Hi,

If baseline is straight and can be drawn, I was thinking about linear
referencing to identify steps for perpendicular lines, then using
translate/rotate operations to move the centerline to each point and
to rotate it to create perpendicular segments.
Then an intersection is done with original polygon to cut segments:

The below query shows the steps in separate CTE's to illustrate. they
could be grouped:
On the picture (http://imgur.com/pozhnZn), the red points are steps (70 units in my
Reply all
Reply to author
Forward
0 new messages