Simplifying Polygon Points

231 views
Skip to first unread message

Richard S

unread,
Oct 31, 2012, 5:21:52 AM10/31/12
to rgeo-...@googlegroups.com
tldr; How do you union a series of polygons and remove redundant lines

Hi there,

Just started using RGeo. Firstly thought I would ask a broader question as you guys might know a better solution to the problem I'm trying to solve.
Basically I have a series of coordinates that I am mapping out into a cartesian space. For each of these, what can be described as lines, I have converted these to rectangles using some basic perpendicular maths. For each of these newly generated rectangles I want to merge these into a single polygon. So imagining you went for a walk, that single path would now be turned into a polygon representing an area.

My questions now are:
  • What is the most cost effective way of union-ing all of these rectangle/polygons into one.
  • How can I simplify the points on the newly created polygon to remove any redundant lines.
I ask this because I tried union-ing two rectangles:
    • a = [[0, 0], [2, 0], [2, 10], [0, 10]]
    • b = [[1, 0], [3, 0], [3, 10], [1, 10]]
    • a.union(b)
Of which produced:
POLYGON ((1.0 0.0, 0.0 0.0, 0.0 10.0, 1.0 10.0, 2.0 10.0, 3.0 10.0, 3.0 0.0, 2.0 0.0, 1.0 0.0))

Immediately you can see (0.0, 0.0) among many others should be removed this this list.

Daniel Azuma

unread,
Nov 18, 2012, 11:14:01 PM11/18/12
to RGeo-Users
Richard,

That's an interesting and somewhat unexpected result. The "union" method definitely is what I would use to merge polygons, but the fact that it doesn't simplify out those "extra" vertices in the polygon is a bit surprising. But you're right; I just ran it myself, and got the same result.

I'll ask on the GEOS list and try to find out if this is expected behavior. In the meantime, though, if you need to simplify them out, it's not hard to write a quick algorithm to identify superfluous vertices. Just find sets of three consecutive points where the middle is on a line between the ends. Particularly straightforward if your rectangles are axis-aligned.

Daniel

Richard S

unread,
Feb 27, 2013, 1:24:29 AM2/27/13
to rgeo-...@googlegroups.com
Hi Daniel,

Thank you very much for your reply. Did you get any response from the GEOs list?
I will try and give that algorithm a go, as you said it shouldn't be too hard but if I have any difficulty will reply back :)

Thanks again,
Richard
Reply all
Reply to author
Forward
0 new messages