1

I would like to extract polygon parts using points to cut it. I have seen ST_Dump and ST_Split but they do not seem to do the trick. Should I create more points in order to create a line segment and use st_split to cut them? I think thats too much but I would do it if necessary :)

Any suggestions would be nice :) Cheers, A

Antony
  • 15,257
  • 4
  • 17
  • 18
  • You might have better luck asking this at gis.stackexchange.com. Also, I think we need a little more info about what polygon parts you are trying to extract. It sounds like split it what you want though. – Nate Dec 23 '11 at 19:46
  • hm, yes i think i was not clear, I wish to use the polygon perimeter to extract line segments to use as paths. Well, I can get the polygon boundary which returns a linestring and then try to use split using that linestring and the points I have to get a collection of geometries every time. I have also found ST_linesubstring but it gets a starting and ending float8 which really is not very helpful for me. Is there a way to give it latitude longitude coordinates to get the line substring? Thx for your help! – Antony Dec 28 '11 at 13:52

1 Answers1

0

So, you want a linestring from each edge a polygon? I think I have an answer if that is true.

First: I would create a view that has all you polygons as linestrings. As you've pointed out, you can use ST_Boundary. (So that the second query is easy to write and read)

CREATE VEIW my_linestrings as 
    SELECT id,..., ST_BOUNDARY(the_geom) 
    FROM <yourtable>

Second: Since its a linestring you can use ST_POINTN to get the nth point and ST_MAKELINE to make a two segment line.

SELECT id,..., ST_MakeLine(ST_PointN(the_geom,x),ST_PointN(the_geom,x+1))
FROM my_linestrings

The ST_MakeLine will get you your linestring segment. You can make a loop in python to iterate though all the points. If this is something you need to do a lot, it would probably be best to create a new table with these segments.

Also, come join us at gis.stackexchange.com ;) This question is similiar to yours and uses SQL to create a series to loop through all the geometries (instead of python).

Community
  • 1
  • 1
Nate
  • 1,889
  • 1
  • 20
  • 40
  • Hi, What I am trying to do is to buffer the perimeter of a polygon and get line segments of the buffer. But I want to define the points, I do not want to take the edges as input for my line paths. My points are random every time so I want to use my random starting and ending points to cut the linestring and keep the line curve. But now that I found a way, the st_split function is not working.. I have posted in the GIS forum. Thank you so much for your interest and input on this! – Antony Dec 28 '11 at 18:24