Hari S. Khalsa ha scritto:
> Does anyone know whether it is possible to read in only the features
> from a point shapefile that are contained within a specific geometry?
> I'm trying to read in business locations from a point shapefile that are
> contained within a polygon using a Geometry filter. I've successfully
> used the bounding Box filter and so I could use this to get all of the
> points within the envelope of a polygon. Then I could traverse through
> these points and get just the ones that are in the polygon. I'd rather
> not go through this extra processing though.
> I'm including the (rough) code that I've tried to use but with no
> success. If it is possible to do what I'm trying, can someone point me
> at an example or guide me how to modify my code below.
>
> Thanks,
> Hari
>
> *public* FeatureCollection getBusinesses(Geometry businessArea, String
> businessDataset)
> {
> *try* {
> File businessFile = *new* File(businessDataset);
> URL businessURL = businessFile.toURL();
>
> //get feature results
> ShapefileDataStore store = *new* ShapefileDataStore(businessURL);
> //feature type name is defaulted to the name of shapefile (without
> extension
> String name = store.getTypeNames()[0];
> FeatureSource source = store.getFeatureSource(name);
>
> //source.getBounds().intersects((Envelope)businessArea.getEnvelope());
>
> FeatureCollection currentFeatures;
> FilterFactory filterFactory = FilterFactoryFinder./createFilterFactory/();
>
> //GeometryFilter businessAreaFilter =
> filterFactory.createGeometryFilter(FilterType.GEOMETRY_BBOX);
> //GeometryFilter businessAreaFilter =
> filterFactory.createGeometryFilter(FilterType.GEOMETRY_CONTAINS);
> //GeometryFilter businessAreaFilter =
> filterFactory.createGeometryFilter(FilterType.GEOMETRY_WITHIN);
> GeometryFilter businessAreaFilter =
> filterFactory.createGeometryFilter(AbstractFilter. /GEOMETRY_WITHIN/ );
>
> //businessAreaFilter.addRightGeometry(filterFactory.
> // createBBoxExpression(overLappingEnvelope));
>
>
> businessAreaFilter.addRightGeometry(filterFactory.createAttributeExpression(businessArea.toString()));
Here lies the error, you want to compare against a constant, a literal,
not an attribute of the features you're loading.
businessAreaFilter.addRightGeometry(filterFactory.createLiteralExpression(businessArea)))
should do the trick (haven't tested the above, let me know).
Cheers
Andrea
-------------------------------------------------------------------------
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