Hi Oliver,

You can make use of a GeoTools filter to retrieve the features that
are within distance d of a given point...

FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null);

FeatureCollection<SimpleFeatureType, SimpleFeature> findFeatures(
        FeatureCollection<SimpleFeatureType, SimpleFeature> collection,
        DirectPosition2D pos, double maxDistance, String geomAttributeName) {

    DirectPosition2D pos = new DirectPosition2D(10.0, 10.0);
    Point jtsPoint = gf.createPoint(new Coordinate(pos.x, pos.y));
    Filter filter = ff2.dwithin(ff2.property(geomAttributeName),
ff2.literal(jtsPoint), radius, null);

    return fc.subCollection(filter);
}

We don't have a FilterLab page yet in the new examples and I'm afraid
the javadocs for the filter classes are not the best. But there is an
example of another, related kind of filter in the SelectionLab
example...

http://geotools.org/examples/selectionlab.html#what-features-did-the-user-click-on

And Jody has just put this FOSS4G tutorial workbook online...
http://snapshots.dist.codehaus.org/geotools/workshop/FilterWorkbook.pdf

Make friends with filters and you can do pretty much anything :)

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

Reply via email to