while (records.hasNext()) {
SpatialDatabaseRecord record = records.next();
Geometry geom = record.getGeometry();
if (geom instanceof LineString) {
LocationIndexedLine line = new LocationIndexedLine(geom);
LinearLocation here = line.project(point.getCoordinate());
Coordinate snap = line.extractPoint(here);
double distance = snap.distance(point.getCoordinate());
results.add(new PointResult(layer.getGeometryFactory()
.createPoint(snap), record, distance));
} else if (geom instanceof Point) {
Point here = (Point) geom;
results.add(new PointResult(here,record,here.distance(point)));
}
}
Collections.sort(results);
return results;
}