I have several polygon objects and I need to "merge (or combine or dissolve)" them toghether into one polygon object. With a GIS tool like Quantum GIS, I do this with Geoprocessing option "Combine selected spatial objects" and the result is what I expect. But doing programmatically with Java and Geotools library, I'm not able to get this behaviour.
To give you an idea, I have two polygons in one layer like this:
Each square is an independent polygon in my shapefile (an independent object with its attributes).
Now I want to transform them into one object. I tried with "union" method of Geometry class in this way:
//polygon1 and polygon2 are Polygon objects (the squares in the above image) Geometry combine = polygon1.union(polygon2);
And this is the result when I visualize the union in the GIS:
As you can see, a line is added between the two figures (although the union is made succesfully and I have only one entity as I wish). But I want this without the line connecting them!! The polygons are well formed because doing with Quantum GIS the operation is made right so... Anyone know if is it possible? I'm looking for some time and I'm concluding that maybe my approach to achieve this is bad...
Bellow is the union achieved with Quantum geoprocessing option "Dissolve":
Thank you in advance,