HappyProgrammerUser
HappyProgrammerUser

Reputation: 81

JTS/Geotools Correct union/difference of multiple geometry

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 :

  1. 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

  2. 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

Upvotes: 5

Views: 2287

Answers (1)

HappyProgrammerUser
HappyProgrammerUser

Reputation: 81

My problems were solved in the end like @mdup had suggested the use of

.buffer(0)

Upvotes: 1

Related Questions