我正在使用Java Geotools库检查POLYGON(...)中是否包含POINT(...)。
我已经做到了:
Geometry sPG = reader.read(wktStartPoint); //startpointgeometry
Geometry sEG = reader.read(wktEndPoint);
if(wktLayerGeo.contains(sPG) || wktLayerGeo.contains(sEG)){
// do something
}
但是现在我必须设置一个公差:例如,我要检查多边形中是否包含点,且公差距离为50 km。
我可以用GeoTools做到吗?
谢谢
最佳答案
您可以在多边形几何(API)上使用JTS buffer
方法:
double yourToleranceDistance = 2;
int numberOfSegmentsPerQuadrant = 2;
// get the geometry with your tolerance
Polygon wktLayerGeoWithTolerance = (Polygon) wktLayerGeo.buffer(yourToleranceDistance, numberOfSegmentsPerQuadrant, BufferParameters.CAP_SQUARE);
// continue with your code...
if(wktLayerGeoWithTolerance.contains(sPG) || wktLayerGeoWithTolerance.contains(sEG)){
// do something
}