Commit a26ad556 authored by Matija Obreza's avatar Matija Obreza
Browse files

Debug print features near a location

parent cb5b19ae
...@@ -12,6 +12,8 @@ import org.geotools.data.DataStore; ...@@ -12,6 +12,8 @@ import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder; import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource; import org.geotools.data.FeatureSource;
import org.geotools.factory.CommonFactoryFinder; import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.geometry.jts.JTSFactoryFinder; import org.geotools.geometry.jts.JTSFactoryFinder;
import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType; import org.opengis.feature.simple.SimpleFeatureType;
...@@ -32,12 +34,13 @@ public class LandOrSeaServiceImpl implements LandOrSeaService { ...@@ -32,12 +34,13 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
private static final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); private static final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
private static final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); private static final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
private FeatureSource<SimpleFeatureType, SimpleFeature> sourceLand; private FeatureSource<SimpleFeatureType, SimpleFeature> sourceLand;
private FeatureSource<SimpleFeatureType, SimpleFeature> sourceWater; private FeatureSource<SimpleFeatureType, SimpleFeature> sourceWater;
private LoadingCache<LonLatCacheKey, Boolean> waterCache; private LoadingCache<LonLatCacheKey, Boolean> waterCache;
private LoadingCache<LonLatCacheKey, String> classifierCache; private LoadingCache<LonLatCacheKey, String> classifierCache;
private boolean debug = false;
public void afterPropertiesSet() throws MalformedURLException, IOException { public void afterPropertiesSet() throws MalformedURLException, IOException {
// http://openstreetmapdata.com/data/land-polygons // http://openstreetmapdata.com/data/land-polygons
...@@ -89,7 +92,21 @@ public class LandOrSeaServiceImpl implements LandOrSeaService { ...@@ -89,7 +92,21 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
Filter filterBuffered = ff.intersects(ff.property("the_geom"), Filter filterBuffered = ff.intersects(ff.property("the_geom"),
ff.literal(ShapefileUtils.getPointBuffer(longitude, latitude, allowedDistanceMargin))); ff.literal(ShapefileUtils.getPointBuffer(longitude, latitude, allowedDistanceMargin)));
if (sourceLand.getFeatures(filterBuffered).size() > 0) { FeatureCollection<SimpleFeatureType, SimpleFeature> matchingFeatures = sourceLand
.getFeatures(filterBuffered);
if (matchingFeatures.size() > 0) {
if (debug) {
try (FeatureIterator<SimpleFeature> features = matchingFeatures.features()) {
while (features.hasNext()) {
SimpleFeature feature = features.next();
System.err.print(feature.getID());
System.err.print(": ");
System.err.println(feature.getDefaultGeometryProperty().getValue());
System.err.println("Attrs: " + feature.getAttributes());
}
}
}
return "Coastal"; return "Coastal";
} else { } else {
return "Water"; return "Water";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment