-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GeometryCollection difference #833
Labels
Comments
I made an RFC for this: #761. It needs a bit more detail about the exact semantics, however. What is the behaviour that you are proposing? |
For difference, I am currently doing this:
This is the utility method I now use to do this. Perhaps GeometryCollection.difference could do something similar. public static Geometry difference(Geometry g0, Geometry g1) {
if (g0.getClass().equals(GeometryCollection.class)) {
// left side is geometry collection
GeometryCollection gc = (GeometryCollection) g0;
List<Geometry> geoms = new ArrayList<>(g0.getNumGeometries());
for (int i = 0; i < gc.getNumGeometries(); i++) {
Geometry g = gc.getGeometryN(i);
g = difference(g, g1);
if (!g.isEmpty()) {
geoms.add(g);
}
}
if (geoms.isEmpty()) {
return // empty;
}
Geometry result = UnaryUnionOp.union(geoms);
if (result == null) {
return // empty;
}
return result;
} else if (g1.getClass().equals(GeometryCollection.class)) {
// right side is geometry collection
GeometryCollection gc = (GeometryCollection) g1;
Geometry result = g0;
for (int i = 0; i < gc.getNumGeometries(); i++) {
Geometry g = gc.getGeometryN(i);
result = difference(result, g);
}
return result;
}
return g0.difference(g1);
} Today, I also got trapped with the same issue for the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should we add support for
Geometry.difference
from/to a non-emptyGeometryCollection
? I just made a method for this in one of my projects to get around some Exceptions, but having support for more such operations for GeometryCollection would make it easier to use JTS.The text was updated successfully, but these errors were encountered: