Search in sources :

Example 1 with Geometries.point

use of com.github.davidmoten.rtree2.geometry.Geometries.point in project rtree2 by davidmoten.

the class GreekEarthquakes method entries.

public static Stream<Entry<Object, Point>> entries(final Precision precision) {
    return Stream.using(() -> new GZIPInputStream(GreekEarthquakes.class.getResourceAsStream("/greek-earthquakes-1964-2000.txt.gz")), in -> Stream.lines(new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)))).flatMap(line -> {
        if (line.trim().length() > 0) {
            String[] items = line.split(" ");
            double lat = Double.parseDouble(items[0]);
            double lon = Double.parseDouble(items[1]);
            Entry<Object, Point> entry;
            if (precision == Precision.DOUBLE)
                entry = Entries.entry(new Object(), Geometries.point(lat, lon));
            else
                entry = Entries.entry(new Object(), Geometries.point((float) lat, (float) lon));
            return Stream.of(entry);
        } else
            return Stream.empty();
    });
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) List(java.util.List) GZIPInputStream(java.util.zip.GZIPInputStream) Geometries(com.github.davidmoten.rtree2.geometry.Geometries) BufferedReader(java.io.BufferedReader) Stream(org.davidmoten.kool.Stream) InputStreamReader(java.io.InputStreamReader) StandardCharsets(java.nio.charset.StandardCharsets) Point(com.github.davidmoten.rtree2.geometry.Point) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Point(com.github.davidmoten.rtree2.geometry.Point)

Aggregations

Geometries (com.github.davidmoten.rtree2.geometry.Geometries)1 Point (com.github.davidmoten.rtree2.geometry.Point)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 StandardCharsets (java.nio.charset.StandardCharsets)1 List (java.util.List)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Stream (org.davidmoten.kool.Stream)1