[Jts-topo-suite-user] Dealing with Precision errors in union adjacent polygons From: Brian Sanjeewa Rupasinghe - 2013-05-27 09:55 Attachments: Message as HTML ```Hi, I have four adjoining polygons in a Geometry Array. I union all these polygons with *UnionWithUnionOp(). *After union, i must end up with a single polygon. However, may be due to precision exceptions i end up with a MultiPolygon. When i reduced the Precision to Floating_Single in the resultant MultiPolygon, It becomes a single polygon. However, when i reduce the precision of all geometries before union, it does not give a single polygon. I wonder if there any other efficient method to solve this. I used Geometry.Buffer(0.0001).Buffer(-0.0001) method on the MultiPolygon (with a small distance) , but it did not work though. My problem is that i have a set of these type of adjoining polygon clusters for union. I am going to use *UnionWithUnionOp() *iteratively for this. I want to have a consistent method, that will give polygons after union in each iteration. Any idea or solution welcome?? Here is the input Geometry of one iteration: [POLYGON ((573.2208405362504 319.14591696023655, 626.988029985886 259.3613429321679, 629.6108197151369 271.93570183372697, 573.2208405362504 319.14591696023655)), POLYGON ((626.988029985886 259.3613429321679, 662.7825445411077 244.565783113429, 629.6108197151369 271.93570183372697, 626.988029985886 259.3613429321679)), POLYGON ((686.3237768753402 234.83508231929972, 657.7256658615997 232.33180753459465, 645.5024406099801 224.89104962150418, 617.5658326202788 237.9154455890137, 626.988029985886 259.3613429321679, 686.3237768753402 234.83508231929972)), POLYGON ((679.443824570897 298.1635991262324, 629.6108197151369 271.93570183372697, 573.2208405362504 319.14591696023655, 634.8563991736378 327.01428614798823, 679.443824570897 298.1635991262324))] This is the result of the union without reducing precision: MULTIPOLYGON (((686.3237768753402 234.83508231929972, 657.7256658615997 232.33180753459465, 645.5024406099801 224.89104962150418, 617.5658326202788 237.9154455890137, 626.988029985886 259.3613429321679, 686.3237768753402 234.83508231929972)), ((629.6108197151369 271.93570183372697, 662.7825445411077 244.565783113429, 626.988029985886 259.3613429321679, 573.2208405362504 319.14591696023655, 634.8563991736378 327.01428614798823, 679.443824570897 298.1635991262324, 629.6108197151369 271.93570183372697))) The resultant polygon after reducing precision of above MultiPolygon to Floating_Single POLYGON ((626.988037 259.361328, 573.220825 319.145905, 634.856384 327.014282, 679.443848 298.163605, 629.61084 271.935699, 662.782532 244.565796, 686.323792 234.835083, 657.725647 232.331802, 645.502441 224.891052, 617.565857 237.915451, 626.988037 259.361328)) Best, Brian. ```
 Re: [Jts-topo-suite-user] Dealing with Precision errors in union adjacent polygons From: Martin Davis - 2013-05-27 17:04 Attachments: Message as HTML ```There is a method on GeometrySnapper which snaps a geometry to itself using a given tolerance, and then cleans the result (to eliminate topology collapes). You can try running this after unions which don't produce Polygons. http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/operation/overlay/snap/GeometrySnapper.html#snapToSelf(double, boolean) On Mon, May 27, 2013 at 2:55 AM, Brian Sanjeewa Rupasinghe < jinkabs@...> wrote: > Hi, > > I have four adjoining polygons in a Geometry Array. I union all these > polygons with *UnionWithUnionOp(). *After union, i must end up with a > single polygon. > However, may be due to precision exceptions i end up with a MultiPolygon. > When i reduced the Precision to Floating_Single in the resultant > MultiPolygon, > It becomes a single polygon. However, when i reduce the precision of all > geometries before union, it does not give a single polygon. > I wonder if there any other efficient method to solve this. I used > Geometry.Buffer(0.0001).Buffer(-0.0001) method on the MultiPolygon (with a > small distance) > , but it did not work though. My problem is that i have a set of these > type of adjoining polygon clusters for union. I am going to use *UnionWithUnionOp() > *iteratively for this. > I want to have a consistent method, that will give polygons after union in > each iteration. Any idea or solution welcome?? > > Here is the input Geometry of one iteration: > > [POLYGON ((573.2208405362504 319.14591696023655, 626.988029985886 > 259.3613429321679, 629.6108197151369 271.93570183372697, 573.2208405362504 > 319.14591696023655)), POLYGON ((626.988029985886 259.3613429321679, > 662.7825445411077 244.565783113429, 629.6108197151369 271.93570183372697, > 626.988029985886 259.3613429321679)), POLYGON ((686.3237768753402 > 234.83508231929972, 657.7256658615997 232.33180753459465, 645.5024406099801 > 224.89104962150418, 617.5658326202788 237.9154455890137, 626.988029985886 > 259.3613429321679, 686.3237768753402 234.83508231929972)), POLYGON > ((679.443824570897 298.1635991262324, 629.6108197151369 271.93570183372697, > 573.2208405362504 319.14591696023655, 634.8563991736378 327.01428614798823, > 679.443824570897 298.1635991262324))] > > This is the result of the union without reducing precision: > > MULTIPOLYGON (((686.3237768753402 234.83508231929972, 657.7256658615997 > 232.33180753459465, 645.5024406099801 224.89104962150418, 617.5658326202788 > 237.9154455890137, 626.988029985886 259.3613429321679, 686.3237768753402 > 234.83508231929972)), ((629.6108197151369 271.93570183372697, > 662.7825445411077 244.565783113429, 626.988029985886 259.3613429321679, > 573.2208405362504 319.14591696023655, 634.8563991736378 327.01428614798823, > 679.443824570897 298.1635991262324, 629.6108197151369 271.93570183372697))) > > The resultant polygon after reducing precision of above MultiPolygon to > Floating_Single > > POLYGON ((626.988037 259.361328, 573.220825 319.145905, 634.856384 > 327.014282, 679.443848 298.163605, 629.61084 271.935699, 662.782532 > 244.565796, 686.323792 234.835083, 657.725647 232.331802, 645.502441 > 224.891052, 617.565857 237.915451, 626.988037 259.361328)) > > Best, Brian. > > > ------------------------------------------------------------------------------ > Try New Relic Now & We'll Send You this Cool Shirt > New Relic is the only SaaS-based application performance monitoring service > that delivers powerful full stack analytics. Optimize and monitor your > browser, app, & servers with just a few lines of code. Try New Relic > and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may > _______________________________________________ > Jts-topo-suite-user mailing list > Jts-topo-suite-user@... > https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user > > ```