[geos-devel] Multipolygon from Linestrings
frederik at remote.org
Sun Aug 2 18:14:20 EDT 2009
I'm not really a GEOS developer, just a developer using GEOS, but I
hope that's ok ;-)
I'm writing a C/C++ program, and have a problem which I thought was simple:
* I have a number of linestrings which together from the edges of a
multipolygon. I actually know which of those make up rings (e.g. I know
that Linestrings A, B, C together form ring #1, Linestring D forms ring
#2, and Linestrings E, F together form ring #3) but I don't have
information about which of those are shells or holes. I read these from
a file, in WKB notation, and they really are Linestrings even if their
first and last point is the same.
* I want to make these into a Multipolygon using either the GEOS C++ or
the C API.
* Special requirement: After the process is through, I want to know
which of my Linestrings have become (parts of) shells and which have
become (parts of) holes.
The last requirement seems to rule out the "Polygonizer" magic for me,
so I have to do it by hand:
1. assemble rings from my linestrings,
2. find out which are inside which (i.e. which are shells, which are holes)
3. then call createPolygon.
I'm having problems with #1 and #2. For #1, I need to (a) combine a
chain of n linestrings into one linestring and/or (b) make a LinearRing
from a simple and closed linestring. I have spent half a day on the
documentation and tried out everything, but for both problems (a) and
(b) I have found no other solution than to extract the
CoordinateCollections from each Geometry and create a completely new
Geometry afterwards, as in
CoordinateSequence *cs1 = g1->getCoordinates();
CoordinateSequence *cs2 = g2->getCoordinates();
cs1->add(cs2, false, true);
LinearRing *l1 = new LinearRing(cs1, global_factory);
LinearRing *l2 = new LinearRing(linestring->getCoordinates(),
With #2 the problem is that even once I have LinearRings, I cannot call
"within" on them because something can only be "within" a polygon and
not a LinearRing (any combination of "within" on two concentric rings
gives false). So I'd first have to convert my rings into individual
polygons to find out which is inside which...?
Maybe I'm overly cautious here but I am trying to write a program that
can process a lot of these in a short time, and all solutions I have
found until now sound like an awful lot of copying data around!
I understand that the Polygonizer is supposed to do all this by magic
but as I said it doesn't tell me enough about what it does...
Frederik Ramm ## eMail frederik at remote.org ## N49°00'09" E008°23'33"
More information about the geos-devel