Search in sources :

Example 1 with TLongProcedure

use of gnu.trove.procedure.TLongProcedure in project OpenTripPlanner by opentripplanner.

the class HashGridSpatialIndex method insert.

public final void insert(LineString geom, final Object item) {
    Coordinate[] coord = geom.getCoordinates();
    final TLongSet keys = new TLongHashSet(coord.length * 8);
    for (int i = 0; i < coord.length - 1; i++) {
        // TODO Cut the segment if longer than bin size
        // to reduce the number of wrong bins
        Envelope env = new Envelope(coord[i], coord[i + 1]);
        visit(env, true, new BinVisitor<T>() {

            @Override
            public boolean visit(List<T> bin, long mapKey) {
                keys.add(mapKey);
                return false;
            }
        });
    }
    keys.forEach(new TLongProcedure() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean execute(long key) {
            // Note: bins have been initialized in the previous visit
            bins.get(key).add((T) item);
            nEntries++;
            return true;
        }
    });
    nObjects++;
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope) TLongProcedure(gnu.trove.procedure.TLongProcedure) Coordinate(com.vividsolutions.jts.geom.Coordinate) TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 TLongProcedure (gnu.trove.procedure.TLongProcedure)1 TLongSet (gnu.trove.set.TLongSet)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1