}
Geometry geom = (Geometry) geomLiteralExpr.getValue();
// To prevent errors in ArcSDE, we first trim the user's Filter
// geometry to the extents of our layer.
ArcSDEGeometryBuilder gb = ArcSDEGeometryBuilder.builderFor(Polygon.class);
SeExtent seExtent = this.sdeLayer.getExtent();
// If a layer just has one point in it (or one very horizontal or
// vertical line) then we may have
// a layer extent that's a point or line. We need to correct this.
if (seExtent.getMaxX() == seExtent.getMinX()) {
seExtent = new SeExtent(seExtent.getMinX() - 100, seExtent.getMinY(),
seExtent.getMaxX() + 100, seExtent.getMaxY());
}
if (seExtent.getMaxY() == seExtent.getMinY()) {
seExtent = new SeExtent(seExtent.getMinX(), seExtent.getMinY() - 100,
seExtent.getMaxX(), seExtent.getMaxY() + 100);
}
try {
SeShape extent = new SeShape(this.sdeLayer.getCoordRef());
extent.generateRectangle(seExtent);
Geometry layerEnv = gb.construct(extent, new GeometryFactory());
geom = geom.intersection(layerEnv); // does the work
// Now make an SeShape
SeShape filterShape;
// this is a bit hacky, but I don't yet know this code well enough
// to do it right. Basically if the geometry collection is
// completely
// outside of the area of the layer then an intersection will return
// a geometryCollection (two seperate geometries not intersecting
// will
// be a collection of two). Passing this into GeometryBuilder causes
// an exception. So what I did was just look to see if it is a gc
// and if so then just make a null seshape, as it shouldn't match
// any features in arcsde. -ch
if (geom.getClass() == GeometryCollection.class) {
filterShape = new SeShape(this.sdeLayer.getCoordRef());
} else {
gb = ArcSDEGeometryBuilder.builderFor(geom.getClass());
filterShape = gb.constructShape(geom, this.sdeLayer.getCoordRef());
}
// Add the filter to our list
SeShapeFilter shapeFilter = new SeShapeFilter(getLayerName(),
this.sdeLayer.getSpatialColumn(), filterShape, sdeMethod, appliedTruth);
this.sdeSpatialFilters.add(shapeFilter);