FilterFactory fFac = FilterFactory.createFilterFactory();
for (int i = 0; i < nLayers; i++) {
MapLayer layer = layers[i];
FeatureReader featureReader = null;
FeatureSource fSource = layer.getFeatureSource();
FeatureType schema = fSource.getSchema();
try {
Expression bboxExpression = fFac.createBBoxExpression(mapContext
.getAreaOfInterest());
GeometryFilter bboxFilter = fFac.createGeometryFilter(FilterType.GEOMETRY_INTERSECTS);
bboxFilter.addLeftGeometry(bboxExpression);
bboxFilter.addRightGeometry(fFac.createAttributeExpression(
schema, schema.getDefaultGeometry().getName()));
Query bboxQuery = new DefaultQuery(schema.getTypeName(),
bboxFilter);
LOGGER.fine("obtaining FeatureReader for "
+ schema.getTypeName());
featureReader = fSource.getFeatures(bboxQuery).reader();
LOGGER.fine("got FeatureReader, now writing");
String groupId = null;
String styleName = null;
groupId = schema.getTypeName();
styleName = layer.getStyle().getName();
writer.write("<g id=\"" + groupId + "\"");
if (!styleName.startsWith("#")) {
writer.write(" class=\"" + styleName + "\"");
}
writer.write(">\n");
writeDefs(schema);
writer.writeFeatures(featureReader, styleName);
writer.write("</g>\n");
} catch (IOException ex) {
throw ex;
} catch (AbortedException ae) {
LOGGER.info("process aborted: " + ae.getMessage());
throw ae;
} catch (Throwable t) {
LOGGER.warning("UNCAUGHT exception: " + t.getMessage());
IOException ioe = new IOException("UNCAUGHT exception: "
+ t.getMessage());
ioe.setStackTrace(t.getStackTrace());
throw ioe;
} finally {
if (featureReader != null) {
featureReader.close();
}
}
}
}