[geos-devel] Unioning a polygon + linestring => collection?

Graham Toal gtoal at gtoal.com
Wed Jan 18 12:59:10 PST 2023


I'm using GEOS with the C API - I am trying to do something that as far as
I can tell from the documentation should be possible but I've tried every
call I think might do it and cannot get it to work:

I have a GEOS_POLYGON (or GEOS_MULTIPOLYGON) in one GEOSGeometry object and
a GEOS_LINESTRING (or GEOS_MULTILINESTRING) in another, and I want to merge
them into a single GEOS_GEOMETRYCOLLECTION object containing both lines and
polygons.

What's the right way to do this?

The example I'm testing with is that I take a polygon and create a set of
overlapping lines to hatch it. I can clip the lines using the polygon to
create the hatching pattern OK, but I can't add the polygon to those lines
to include the outline. (I'd also rather leave the polygon as a polygon and
not be forced to downgrade it to a set of lines in order to add it to the
compound object.)

For the moment I'm working around the problem by drawing the hatch pattern
and the outline separately, but ultimately I need to union them into a
single object.

I'll try to include an image with this post of what the result should look
like.

The top-level code for the test is in
http://gtoal.com/src/polygon/testnew.c and the code for the hatching is in
http://gtoal.com/src/polygon/polygon-package.c   (  see void Hatch(Polygon
g, double gap, double rot)  )

I would have expected the "Union()" procedure in the latter file to have
done what I wanted, but it didn't - I tried creating a "Merge()" procedure
instead in a desperate effort to force the two objects into a single
collection, but like all the attempts before it, it did not work. Most
efforts ended up with only one of the two input objects being present in
the output object. (That version of Merge() was but the last of many, the
methods I tried getting more esoteric with each attempt, starting from the
basic "c = GEOSUnion(a, b);" )

Hopefully this is a newbie error with a simple solution!  I'ld appreciate
any suggestions.

thanks,

Graham
PS  what I'm working on is an interface to the polygon code that will make
it easier to use with some code that drives my CNC cutter.

[image: poly.png]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geos-devel/attachments/20230118/2bc14ff1/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: poly.png
Type: image/png
Size: 8078 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/geos-devel/attachments/20230118/2bc14ff1/attachment.png>


More information about the geos-devel mailing list