Hello,
I'm still a bit new to geotools. I want to extract features out of one
Featurecollection into a new FeatureCollection. To do this, I use a bounding
box geometry filter. This filter is build like shown in the tutorial. But
the subcollection I get in return is empty. If I build the new
FeatureCollection manually, it contains two features.
The following code snippet shows what I'm doing:
...
FeatureIterator it = fc1.features();
FeatureIterator it2 = fc2.features();
Feature f = null;
Feature f2 = null;
FeatureCollection includes = null;
while(it.hasNext()){
f = it.next();
//build filter
Envelope envelope = f.getBounds();
//envelope = f.getDefaultGeometry().getEnvelopeInternal();
FilterFactory ff = FilterFactoryFinder.createFilterFactory();
Expression bbox;
Expression geometry = ff.createAttributeExpression( "the_geom"
);
GeometryFilter bboxFilter;
try {
bbox = ff.createBBoxExpression( envelope );
bboxFilter =
ff.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
bboxFilter.addLeftGeometry( geometry );
bboxFilter.addRightGeometry( bbox );
} catch (IllegalFilterException e) {
throw (RuntimeException) new RuntimeException( ).initCause(
e );
}
//build new featureCollection using filter
includes = fc2.subCollection(bboxFilter);
//now the collection is empty
System.out.println(includes.size());
//build new featureCollection manually:
DefaultFeatureCollections dfc = new DefaultFeatureCollections();
includes = dfc.newCollection();
while (it2.hasNext()) {
f2 = it2.next();
//if(f.getDefaultGeometry().intersects(f2.getDefaultGeometry())){
if(f.getBounds().intersects(f2.getBounds())){
includes.add(f2);
}
}
it2.close();
//now the collection contains two features
System.out.println(includes.size());
}
it.close();
...
Has someone ideas, why the results differ? Your help would be much
appreciated!
Regards,
Kerstin Sälzer
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users