I'm new to GeoTools and GIS generally. I have a shapefile containing feature polygons representing NY City taxi zones. I also have the coordinates in latitude and longitude for the pickup and drop-off locations for a (large) number of taxi trips.
I have read the Shapefile into a DataStore and can iterate over the features, but have no idea how to actually query it. I assume that this is a function that Geotools provides, but perhaps I'm wrong.
My code so far is below:
File file = new File("taxi_zones.shp");
FileDataStore myData = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource source = myData.getFeatureSource();
SimpleFeatureType schema = source.getSchema();
Query query = new Query(schema.getTypeName());
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(query);
try (FeatureIterator<SimpleFeature> features = collection.features()) {
while (features.hasNext()) {
SimpleFeature feature = features.next();
System.out.println(feature.getID() + ": ");
for (Property attribute : feature.getProperties()) {
if (attribute.getName().toString().equals("the_geom")) {
System.out.println("\t" + attribute.getName() + ":" + attribute.getValue());
}
}
}
}
EDIT: I have since found the CQL subproject and realize i need something like: Filter filter = ECQL.toFilter("")
, but I don't know how to formulate the query text