Union for lots of polygons

8 messages Options
Embed this post
Permalink
Markus Eichhorn

Union for lots of polygons

Reply Threaded More More options
Print post
Permalink
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. In the end. it should work with collection within 20.000 and more geometries.My code looks like this:

private Geometry unionIntoOneGeometry(
            Collection<Geometry> geometryCollection) {
        Geometry all = null;
        for (Iterator<Geometry> i = geometryCollection.iterator(); i.hasNext();) {
            Geometry geometry = i.next();
            if (geometry == null)
                continue;
            if (all == null) {
                all = geometry;
            } else {
                all = all.union(geometry);
            }
        }
        return all;
    }
Is there a better way to union all these polygons? I don't find a way with good performace.
Thanks,
Markus


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Union for lots of polygons

Reply Threaded More More options
Print post
Permalink
HI Markus,

Try the JTS UnaryUnionOp...

Collection<Geometry> geoms = ...
UnaryUnionOp op = new UnaryUnionOp(geoms);
Geometry result = op.union();

Hope this helps,
Michael

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Markus Eichhorn

Re: Union for lots of polygons

Reply Threaded More More options
Print post
Permalink
I'm sorry.
Your answer is not solving my problem completely.
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. 
Any hints?
Thanks
Markus


2009/9/11 <[hidden email]>
That's it!
Good performance, short handling...
Thanks
Markus

Am 11.09.2009 14:46 schrieb Michael Bedward <[hidden email]>:

> HI Markus,
>
>
>
> Try the JTS UnaryUnionOp...
>
>
>
> Collection geoms = ...

>
> UnaryUnionOp op = new UnaryUnionOp(geoms);
>
> Geometry result = op.union();
>
>
>
> Hope this helps,
>
> Michael
>


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Union for lots of polygons

Reply Threaded More More options
Print post
Permalink
Hi Markus

Bummer !

At this point you probably need to consult the geometry gurus on the JTS list...

You can search the archive of the JTS list here:
http://n2.nabble.com/jts-devel-f219725.html

And join the list to post on it here:
http://lists.refractions.net/mailman/listinfo/jts-devel

If you get some useful feedback there please let us know here too.

Michael

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Hans Bogaards-2

Re: Union for lots of polygons

Reply Threaded More More options
Print post
Permalink
In reply to this post by Markus Eichhorn
Hi Markus and all,

geometry.union(other);  it is much to slow for huge collection. In the end. it should work with collection within 20.000 and more geometries.My code looks like this:

private Geometry unionIntoOneGeometry(
            Collection<Geometry> geometryCollection) {
        Geometry all = null;
        for (Iterator<Geometry> i = geometryCollection.iterator(); i.hasNext();) {
            Geometry geometry = i.next();
            if (geometry == null)
                continue;
            if (all == null) {
                all = geometry;
            } else {
                all = all.union(geometry);
            }
        }
        return all;
    }

What I have found somewhere in the JTS documents is:
        Geometry geom = geometryCollection.buffer(0);

Hope this helps
--
Hans
With great power comes great responsibility

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Markus Eichhorn

Re: Union for lots of polygons

Reply Threaded More More options
Print post
Permalink
Hi Hans,

I've tried this already.... with my polygons i'll get an OutOfMemory-Exception. It seems this class cannot handle my number of polygons.
But thanks, reminding me of that way points me to new ways to try.
Markus


Am 14.09.2009 11:48 schrieb Hans Bogaards <[hidden email]>:

> Hi Markus and all,
>
> geometry.union(other);  it is much to slow for huge collection. In the end. it should work with collection within 20.000 and more geometries.My code looks like this:
>
>
>
> private Geometry unionIntoOneGeometry(            Collection geometryCollection) {
>
>         Geometry all = null;        for (Iterator i = geometryCollection.iterator(); i.hasNext();) {
>
>             Geometry geometry = i.next();            if (geometry == null)
>
>                 continue;            if (all == null) {
>
>                 all = geometry;            } else {
>
>                 all = all.union(geometry);            }
>
>         }        return all;
>
>     }
>
> What I have found somewhere in the JTS documents is:
>         Geometry geom = geometryCollection.buffer(0);
>
> Hope this helps
>
> --
> Hans
>
>
> With great power comes great responsibility
>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Markus Eichhorn

Re: Union for lots of polygons

Reply Threaded More More options
Print post
Permalink
In reply to this post by Hans Bogaards-2
Hi Hans,

I've tried this already.... with my polygons i'll get an OutOfMemory-Exception. It seems this class cannot handle my number of polygons.
But thanks, reminding me of that way points me to new ways to try.
Markus


Am 14.09.2009 11:48 schrieb Hans Bogaards <[hidden email]>:

> Hi Markus and all,
>
> geometry.union(other);  it is much to slow for huge collection. In the end. it should work with collection within 20.000 and more geometries.My code looks like this:
>
>
>
> private Geometry unionIntoOneGeometry(            Collection geometryCollection) {
>
>         Geometry all = null;        for (Iterator i = geometryCollection.iterator(); i.hasNext();) {
>
>             Geometry geometry = i.next();            if (geometry == null)
>
>                 continue;            if (all == null) {
>
>                 all = geometry;            } else {
>
>                 all = all.union(geometry);            }
>
>         }        return all;
>
>     }
>
> What I have found somewhere in the JTS documents is:
>         Geometry geom = geometryCollection.buffer(0);
>
> Hope this helps
>
> --
> Hans
>
>
> With great power comes great responsibility
>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Paul Ramsey

Re: Union for lots of polygons

Reply Threaded More More options
Print post
Permalink
In reply to this post by Markus Eichhorn
http://lin-ear-th-inking.blogspot.com/2007/11/fast-polygon-merging-in-jts-using.html

?

On Fri, Sep 11, 2009 at 5:26 AM, Markus Eichhorn
<[hidden email]> wrote:

> 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. In the end.
> it should work with collection within 20.000 and more geometries.My code
> looks like this:
>
> private Geometry unionIntoOneGeometry(
>             Collection<Geometry> geometryCollection) {
>         Geometry all = null;
>         for (Iterator<Geometry> i = geometryCollection.iterator();
> i.hasNext();) {
>             Geometry geometry = i.next();
>             if (geometry == null)
>                 continue;
>             if (all == null) {
>                 all = geometry;
>             } else {
>                 all = all.union(geometry);
>             }
>         }
>         return all;
>     }
> Is there a better way to union all these polygons? I don't find a way with
> good performace.
> Thanks,
> Markus
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Geotools-gt2-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users