}
LOGGER.fine("Query is " + query + "\n To gt2: " + query.toDataQuery(Integer.MAX_VALUE));
//DJB: note if maxFeatures gets to 0 the while loop above takes care of this! (this is a subtle situation)
FeatureCollection featuresCheck = source.getFeatures(query.toDataQuery(Integer.MAX_VALUE));
// find nearest feature
Unit fromUnit = SI.METER;
Unit toUnit = UnitFormat.getInstance().parseUnit(request.getUnits());
Converter unitConvert = fromUnit.getConverterTo(toUnit);
Feature nearestFeature = null;
double nearestDistance = 9e9;
double nearestBearing = 0;
for (Iterator sItr = featuresCheck.iterator(); sItr.hasNext();) {
Feature f = (Feature)sItr.next();
if (f.getDefaultGeometry() == null) continue;
DistanceOp op = new DistanceOp(request.getPoint(), f.getDefaultGeometry());
Coordinate[] co = op.closestPoints();
Measure m = DefaultGeographicCRS.WGS84.distance(new double[] { co[0].x, co[0].y, }, new double[] { co[1].x, co[1].y, });
if (m.doubleValue() > nearestDistance) continue;
nearestFeature = f;
nearestDistance = m.doubleValue();
nearestBearing = calcBearing(co);
}
//GR: I don't know if the featuresults should be added here for later
//encoding if it was a lock request. may be after ensuring the lock
//succeed?
FeatureCollection features = FeatureCollections.newCollection();
if (nearestFeature != null) features.add(superFeature(nearestFeature, unitConvert.convert(nearestDistance), nearestBearing));
// we may need to shave off geometries we did load only to make bounds
// computation happy
if(extraGeometries.size() > 0) {
List residualProperties = new ArrayList(properties);