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()));
FeatureType featureType = store.getSchema(name);
businessAreaFilter.addLeftGeometry(filterFactory.
createAttributeExpression(featureType.getDefaultGeometry().getName()));
currentFeatures = source.getFeatures(businessAreaFilter);
Iterator currentIterator;
Feature currentFeature;
currentIterator = currentFeatures.iterator();
while (currentIterator.hasNext()) {
currentFeature = (Feature)currentIterator.next();
System.out.println("Business Id: " +
currentFeature.getID()
+ " Name: " +
(String)currentFeature.getAttribute("NAME"));
}
currentFeatures.close(currentIterator);
//System.exit(1);
return currentFeatures;
}
catch(Exception e){
System.err.println("Error in getBusinesses: " + e.toString());
e.printStackTrace();
}
return null;
} -------------------------------------------------------------------------
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