FeatureStream for FeatureSource - dvntucker/geotools GitHub Wiki
This page contains notes on implementing Java 8's Streaming interfaces for FeatureSources in GeoTools.
The Streaming interfaces are both simple to use and -- when implemented correctly -- allow for better parallel collection processing and SQL-esque queries into them.
Parts FeatureSource/FeatureCollection interfaces already map in a straightforward manner to concepts in Streaming, take for example feature Filters and Streaming predicates:
http://docs.geotools.org/stable/javadocs/org/opengis/filter/Filter.html https://docs.oracle.com/javase/8/docs/api/java/util/function/Predicate.html
As you can see, these are already very similar and Filter can very easily implement the Predicate interface. In this way Stream.filter can already be implemented in terms of FeatureSource.query. In general it would be nice if we could provide as much of the Streaming implementation as possible in terms of existing functionality.
There are two principles we'd like to keep in mind in this implementation:
-
Allow current FeatureSource/FeatureCollection implementations to get as much functionality out-of-the-box, without having do implement anything new. This involves providing as many default implementations implemented with existing API as possible.
-
At the same time implementors should be able to take advantage of their internal details in order to provide more efficient implementations of some or all of the Streaming methods.
A simple approach would be simply to add a stream method to FeatureSource, which returns a Stream. This stream could have a default implementation with some methods implemented, with others potentially just throwing UnsupportedOperationExceptions.
Downstream implementors could then override this implementation with their own.
Another approach would be to add