* we show everything unless otherwise instructed).
* <p>
* This method takes into account {@link #isAoiFilter()} and {@link #getFilter()}
*/
public Filter toFilter( FeatureType schema){
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Filter filter = getFilter(); // start with user supplied filter!
if( filter == Filter.INCLUDE ){
filter = null; // please ignore the user they want it all
}
if( isAoiFilter() ){
try {
IAOIService aoiService = PlatformGIS.getAOIService();
ReferencedEnvelope extent = aoiService.getExtent();
if( extent != null ){
CoordinateReferenceSystem crs = extent.getCoordinateReferenceSystem();
Geometry geometry = aoiService.getGeometry();
CoordinateReferenceSystem dataCRS = schema.getCoordinateReferenceSystem();
if (!CRS.equalsIgnoreMetadata(crs,dataCRS)) {
MathTransform transform = CRS.findMathTransform(crs, dataCRS);
geometry = JTS.transform(geometry, transform);
}
String the_geom = schema.getGeometryDescriptor().getName().getLocalPart();
Filter spatialFilter = ff.intersects( ff.property(the_geom), ff.literal( geometry ) );
if( filter != null ){
return ff.and( filter, spatialFilter );
}
else {
return spatialFilter;
}
}