Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jts-dev] Struggling with polygon topology again. Overlapping inner polygons.

In TestBuilder are you working with LinearRings or Polygons? If you are using rings then yes, subtracting one ring from another outside it is just going to return the outer ring.  (Rings don't have area). 

When I subtract the first hole polygon from the shell polygon I get a polygon with one hole, as expected.  I'm not sure why the original code doesn't work, however.  Probably something obvious that neither of us is seeing.  Are the intermediate results at all correct?

One reason to avoid using difference for this is that it's a slow operation, and also subject to robustness issues.

Another way to do this is to form the polygon with the holes (which will be invalid), and then run buffer(0) on it. That has the effect of fixing the topology.  It's quite fast.  Not 100% robust, but should be fine if the polygon geometry is "relatively clean" (which is hard to define more precisely!)

On Tue, Sep 20, 2016 at 4:53 PM, Phil Scadden <p.scadden@xxxxxxxxxx> wrote:

The resultant Multipolygon  contains in fact just one polygon at the end of the loop so easy to deal with (but my code would work with multiples as well). In fact I found this to be better way to construct my polygons than using polygonizer as I know I am starting with collection of valid polys.

I couldnt make the operation work in TestBuilder either. Overlap, difference just returned the outer ring.


On 21/09/2016 11:20 a.m., Martin Davis wrote:
Not sure why the first version of the code would not work - it *looks* functionally identical to the second version.

You shouldn't have to use the OverlayOp class directly - not the best JTS style (although supported by the API, might not be as stable as the Geometry method).

The reason a MultiPolygon is returned is exactly what you see in the image.  3 holes touch and surround a disconnected area, which creates an extra polygon when the final one is subtracted.

On Mon, Sep 19, 2016 at 8:14 PM, Phil Scadden <p.scadden@xxxxxxxxxx> wrote:
Hmm, this version works;

                Polygon op = geometryFactory.createPolygon(p.getExteriorRing().getCoordinates());
                Geometry g = op;
                for (k=0;k<p.getNumInteriorRing();k++) {
                   Polygon ip = geometryFactory.createPolygon(p.getInteriorRingN(k).getCoordinates());
                   g = OverlayOp.overlayOp(g, ip, OverlayOp.DIFFERENCE);
                }


Now just need to figure out why the output geometry is a multipolygon...

--
Phil Scadden, Senior Scientist GNS Science Ltd 764 Cumberland St, Private Bag 1930, Dunedin, New Zealand Ph +64 3 4799663, fax +64 3 477 5232

Notice: This email and any attachments are confidential.
If received in error please destroy and immediately notify us.
Do not copy or disclose the contents.

_______________________________________________
jts-dev mailing list
jts-dev@xxxxxxxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.locationtech.org/mailman/listinfo/jts-dev



_______________________________________________
jts-dev mailing list
jts-dev@xxxxxxxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.locationtech.org/mailman/listinfo/jts-dev

--
Phil Scadden, Senior Scientist GNS Science Ltd 764 Cumberland St, Private Bag 1930, Dunedin, New Zealand Ph +64 3 4799663, fax +64 3 477 5232
Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.

_______________________________________________
jts-dev mailing list
jts-dev@xxxxxxxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.locationtech.org/mailman/listinfo/jts-dev



Back to the top