Hi Anderea,
Was it something like this you meant?

Geometry newHole;
Geometry orgGeo;
...
...
//The new hole
Polygon[] pNewHole = new Polygon[] { (Polygon) newHole };
LinearRing erNewHole = (LinearRing) pNewHole[0].getExteriorRing();

//The original geometry to add the hole to
Polygon[] pOrgGeo = new Polygon[] { (Polygon) orgGeo };
LinearRing erOrgGeo = (LinearRing) pOrgGeo[0].getExteriorRing();

int noInterialRings = pOrgGeo[0].getNumInteriorRing();
LinearRing[] holes = new LinearRing[noInterialRings + 1];
int holeNo;
// add all holes in geo to an array
for (holeNo = 0; holeNo < noInterialRings; holeNo++) {
  holes[holeNo] = ((LinearRing) pOrgGeo[0].getInteriorRingN(holeNo));
}

// now, add newHole as a hole to the "hole"-array
holes[holeNo] = erNewHole;
//
// create the new geo with all holes
Geometry newGeo = geomFactory.createPolygon(erOrgGeo, holes);

Thanks,
Paul

-----Original Message-----
From: Andrea Aime [mailto:[email protected]] 
Sent: den 30 mars 2009 10:38
To: Malm Paul
Cc: [email protected]
Subject: Re: [Geotools-gt2-users] Adding a hole to a geometry

Malm Paul ha scritto:
> Hi list,
> I have 2 defined geometries, does anybody know how to add a geometry 
> as a hole to the other geometry?

I see two ways:
- grab a geometry factory and rebuild the hull/holes set of your polygon
   (taking the hull and the holes from the first polygon, adding the
    hull of the second polygon as an extra hole)
- use a constructive method such as geometry.difference to have JTS
   compute the result for you

The first is fast but you have the responsibility of checking the hole sits 
fully inside the first polygon, the second will works anyways no matter where 
the hole is but is more CPU expensive.

Cheers
Andrea


--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to