Hi Vurfem,
> May be it is very simple for you but I can't solve it. I want to check, one
> of the selected parcel (polygon type) contains a building in it. With
> contains filter I can check the parcels that contain building. But I want to
> check this only for the selected parcel.
Here's one way that you might do it...
public void checkParcel(SimpleFeature parcel, FeatureSource buildings) {
FilterFactory2 filterFactory =
CommonFactoryFinder.getFilterFactory2(null);
Geometry parcelGeom = (Geometry) parcel.getDefaultGeometry();
Filter withinFilter = filterFactory.within(
filterFactory.property("the_geom"),
filterFactory.literal(parcelGeom));
try {
FeatureCollection buildingsInParcel =
buildings.getFeatures(withinFilter);
if (buildingsInParcel.isEmpty()) {
System.out.println("parcel does not contain any buildings");
} else {
System.out.println("parcel has these buildings...");
FeatureIterator iter = buildingsInParcel.features();
try {
SimpleFeature building = (SimpleFeature) iter.next();
// print out info about building...
} catch (Exception ex) {
// do something
} finally {
iter.close();
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
Hope this helps,
Michael
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users