I'm working with two datasets: a set of precincts and a set of census block groups. The census block groups include water; the precincts don't. I would like to trim the census block groups to get only the land area of the census block groups (for a later calculation).
To do this, I find all the precincts that intersect the census block group, and calculate their intersections. I then union all of the precinct intersections together. The end result would, ideally, be the land area of the census block group. However, this is not the case. Rather, the intersections return a GeometryCollection of assorted LineStrings, MultiLineStrings, and Polygons. Attempts to union this collection are unsuccessful (the end goal would be to union it all into a polygon). Here's a rough example:
The translucent red/pink area would be the census block group, the light purple off to the right would be the water area of the census block group, and the blue, orange, and red areas would be precincts (land only). The aim is to get the areas of the translucent figure that intersect with the blue, orange, and red polygons, and then union those areas together to get the land area of the census block group.
I'm currently using GeoTools, a Java library built on the JTS implementation the OpenGIS standard, but I can use/translate a PostGIS query. I would also be open to any suggestions on better ways to do this (I'm sure there are a few).