我有一个问题需要帮助。我在postgis中有parces map layer,它包含多边形。该层遵循不重叠的拓扑规则。 我怎样才能获得与geotools api所选功能“旁边”的功能? “旁边”功能的功能至少有一个相同的边缘。
例如在这张图片中,当选择特征A时,我需要获得特征B,C,D,而不是获得特征E。
任何帮助都很高兴!谢谢!
答案 0 :(得分:1)
我通过此代码解决了我的问题
public static void getRoundFeature(SimpleFeature feature,SimpleFeatureSource featureSource){ FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); 几何g =(几何)feature.getAttribute(“the_geom”);
Polygon polygon = geometryFactory.createPolygon(g.getCoordinates());
//Polygon poly = (Polygon) feature;
Filter filter = ff.intersects(ff.property("the_geom"), ff.literal(polygon));
try {
SimpleFeatureCollection featureCollection = featureSource.getFeatures(filter);
//System.out.println("feature around: "+ featureCollection.size());
FeatureIterator iter = featureCollection.features();
while(iter.hasNext()){
SimpleFeature rfeature = (SimpleFeature) iter.next();
System.out.println("so to: "+rfeature.getAttribute("soto")+ "so thua: "+rfeature.getAttribute("sothua"));
}
} catch (IOException e) { LOGGER.log(Level.FINER, e.getMessage(), e);
}
}