}
// load shapefile end (docs marker)
final SpatialIndex index = new STRtree();
FeatureCollection features = source.getFeatures();
System.out.println("Slurping in features ...");
features.accepts(new FeatureVisitor() {
@Override
public void visit(Feature feature) {
SimpleFeature simpleFeature = (SimpleFeature) feature;
Geometry geom = (MultiLineString) simpleFeature.getDefaultGeometry();
// Just in case: check for null or empty geometry
if (geom != null) {
Envelope env = geom.getEnvelopeInternal();
if (!env.isNull()) {
index.insert(env, new LocationIndexedLine(geom));
}
}
}
}, new NullProgressListener());
// cache features end (docs marker)
/*
* For test data, we generate a large number of points placed randomly
* within the bounding rectangle of the features.
*/
final int NUM_POINTS = 10000;
ReferencedEnvelope bounds = features.getBounds();
Coordinate[] points = new Coordinate[NUM_POINTS];
Random rand = new Random(file.hashCode());
for (int i = 0; i < NUM_POINTS; i++) {
points[i] = new Coordinate(
bounds.getMinX() + rand.nextDouble() * bounds.getWidth(),