Well, that's an interesting little problem. I don't think there's anything in JTS which computes this, although there's code which is somewhat similar (e.g. ConsistentAreaTester).
The algorithm is pretty easy to state: MultiPolygon components are connected iff they intersect. To determine the number of connected components it's necessary to group the components into connected sets. The trick of course is doing this efficiently. This could be done using the low-level segment intersection machinery in JTS (the classes in the noding package). But I"m always looking for ways to use higher-level operations to make coding geometric algorithms simpler and easier. In this case I think using PreparedPolygons for each of the components is the way to go. This will require some bookkeeping classes to maintain the groups of connected polygons (say ConnectedGroup, with operations intersects(PreparedPolygon) and add(PreparedPolygon). Then it's just a matter of keeping a list of ConnectedGroups, and iterating over the Polygon components and adding them to the ConnectedGroup they intersect. There's probably a more functional/declarative way of implementing this, which would be nice to explore. One of my goals for JTS is to make it more functional, hopefully leading to simpler and more obvious implementations for algorithms such as this one. Pls post the code if you get this going. On Fri, Jun 19, 2015 at 8:01 AM, Jerry Swan <[email protected]> wrote: > How might one determine the number of connected components of a > MultiPolygon? > > Best wishes, > > Jerry. > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Jts-topo-suite-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user > >
------------------------------------------------------------------------------
_______________________________________________ Jts-topo-suite-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user
