Hi list,
I've been trying to union a collection of Geometry-object (all elements are polygons). But with the geometry.union(other); it is much to slow for huge collection. So I used the UnaryUnionOp (see code). private Coordinate[] UnionWithUnionOp(ArrayList<Geometry> allPolygons){ Geometry allinOnePolygon = UnaryUnionOp.union(allPolygons); return allinOnePolygon.getCoordinates(); } After union the polygons with the UnaryUnionOp the order of coordinates of the result polygon is not right ( I think, because of the polygons are not ordered and distributed all over the space). So I get an self overlapping polygon which makes lots of problems for the visualisation. Is my handling of the UnaryUnionOp false? Or can't I handle such spread polygons with it? Thanks for answers or hints! Greets Markus _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
Hi Markus
don't know if I get you right. You probably want to node all the input lines first to avoid intersections (this is from the OpenJump Polygonizer PlugIn) : Polygonizer polygonizer = new Polygonizer(); int inputEdgeCount = fd.size(); ---> the number of polygons Collection lines = getLines(fd_helper); Collection nodedLines = lines; nodedLines = nodeLines((List) lines); for(Iterator it = nodedLines.iterator(); it.hasNext();) { Geometry g = (Geometry) it.next(); polygonizer.add(g); } ArrayList polys = (ArrayList) polygonizer.getPolygons(); ----> move on with union // additional methods private Geometry extractPoint(Collection lines) { int minPts = Integer.MAX_VALUE; Geometry point = null; // extract first point from first non-empty geometry for (Iterator i = lines.iterator(); i.hasNext(); ) { Geometry g = (Geometry) i.next(); if (! g.isEmpty()) { Coordinate p = g.getCoordinate(); point = g.getFactory().createPoint(p); } } return point; } private Collection getLines(FeatureDataset inputFeatures) { List linesList = new ArrayList(); LinearComponentExtracter lineFilter = new LinearComponentExtracter(linesList); for (Iterator i = inputFeatures.iterator(); i.hasNext(); ) { Feature f = (Feature) i.next(); Geometry g = f.getGeometry(); g.apply(lineFilter); } return linesList; } regards Stefan ----- Originalnachricht ----- Von: Markus Eichhorn <[hidden email]> Gesendet: Die, 15.9.2009 10:16 An: [hidden email] Betreff: [jts-devel] UnionOP for huge polygon collection Hi list, I've been trying to union a collection of Geometry-object (all elements are polygons). But with the geometry.union(other); it is much to slow for huge collection. So I used the UnaryUnionOp (see code). private Coordinate[] UnionWithUnionOp(ArrayList<Geometry> allPolygons){ Geometry allinOnePolygon = UnaryUnionOp.union(allPolygons); return allinOnePolygon.getCoordinates(); } After union the polygons with the UnaryUnionOp the order of coordinates of the result polygon is not right ( I think, because of the polygons are not ordered and distributed all over the space). So I get an self overlapping polygon which makes lots of problems for the visualisation. Is my handling of the UnaryUnionOp false? Or can't I handle such spread polygons with it? Thanks for answers or hints! Greets Markus _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
Hi Stefan,
don't know if you got it right. I'm not really sure, what the polygonizer does respectively how it should help me. The Union-operation don't care about intersections of the polygons, right? In my opinion the problem is, the polygons are spread all over the space. The onePolygon (which ist returned from any union-opeartion) includes all input polygons, which are "put together". But because the polygons are spread, the "order" of the merged polygons is like the are used. So the boundary of if isn't just around the area it shound be. So it looks like the picture. Do you get it? After using the Polyginizer the UnaryUnionOp and the CascadedPolygonUnion are throwing an exception: com.vividsolutions.jts.geom.TopologyException: side location conflict. And now? Greets Markus 2009/9/15 Ziegler Stefan <[hidden email]> Hi Markus _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel self_overlapping_polygon.jpg (14K) Download Attachment |
In reply to this post by Markus Eichhorn
Are
you allowed to share some sample data?
_______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
In reply to this post by Markus Eichhorn
So the "too slow" method looks like this:
IList<Geometry> geomList = some list of polygons from somewhere; Geometry retVal = geomList.get(0); for (int x = 1; x < geomList.size(); x++) { retVal = retVal.union(geomList.get(x)); } return retVal; Or something like that? I think it will be much faster to create a GeometryCollection object from your list of polygons, then use the union method that takes no parameters. I can't offer great details on it because I am an NTS user (NTS is a port of JTS to C#, but it is a port of version 1.7 and the union method that takes no parameters was added in a much newer version). The old way to do this (the way I would do it in NTS) was to create a GeometryCollection and then call gc.buffer(0.0). You may see that referenced in your google searches, but that was before the union that takes no parameters was added. It may still work in the current version of JTS also, I don't know. Either way, the idea is take the entire list and union it all at once, rather than unioning each additional polygon in one at a time. Hope this helps, Jeff On Tue, Sep 15, 2009 at 4:16 AM, Markus Eichhorn <[hidden email]> wrote: Hi list, _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
After re-reading your original post, I think maybe you were already trying the same union method I was suggesting, so maybe this was not helpful after all.
On Tue, Sep 15, 2009 at 9:11 AM, Jeff Adams <[hidden email]> wrote: So the "too slow" method looks like this: -- Jeff Adams Avencia, Inc. 215-701-7717 _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
Free forum by Nabble | Edit this page |