Problem :
I have a shape file that contains the targeted area (yellow).
I have a shape file that contains the buildings (green).
I need the white space in the yellow area.
picture : ://db.tt/kjjXZlQF
My solutions :
Get all buildings in that area
Filter inPolygon = CQL.toFilter("WITHIN(the_geom,"+wktwriter.write(targetarea) + ")");
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = featureSource.getFeatures(inPolygon);//this works
From every building get it's geometry and use difference on the target area
toCover = toCover.Difference(building);
OR second solution :
Union of every building and then difference at the end.
OR third solution :
Put them all in a GeomtryCollection call union and then use difference
Everyone of these solutions give me something like the following picture
picture : https://dl.dropboxusercontent.com/u/639458/stackoverflow/stfr2.png
Let it be clear I tried out several ways to solve this problem, by using different ways of creating / making or using it. Even with the given code in the site below it did not work correct.
http://docs.geotools.org/latest/userguide/library/jts/combine.html
My problems were solved in the end like @mdup had suggested the use of
.buffer(0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With