You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

S2Polygon包含判断异常:非内部点被误判为包含(返回true)

S2Polygon点包含判断异常排查

我使用S2Polygon判断点是否位于多边形内部或外部,编写了如下测试用例:

@Test
void testPolygonContainsPoint() {
    
    // 创建经纬度点列表
    List<S2Point> points = new ArrayList<>();
    
    // 最后一个点与第一个点重合,闭合多边形
    points.add(S2LatLng.fromDegrees(40.7711, -73.9345).toPoint());
    points.add(S2LatLng.fromDegrees(40.7710, -73.9342).toPoint());
    points.add(S2LatLng.fromDegrees(40.7704, -73.9344).toPoint());
    points.add(S2LatLng.fromDegrees(40.7702, -73.9345).toPoint());
    points.add(S2LatLng.fromDegrees(40.7711, -73.9345).toPoint());

    // 用S2Point创建S2Loop
    S2Loop loop = new S2Loop(points);

    // 用S2Loop创建S2Polygon
    S2Polygon polygon = new S2Polygon(loop);

    // 创建待校验的经纬度点
    S2LatLng pointToCheck = S2LatLng.fromDegrees(40.7705, -73.9394);

    boolean isContained = polygon.contains(pointToCheck.toPoint());
    
    // 预期结果为false,但实际返回true
    Assertions.assertEquals(false, isContained);
}

从GeoViz截图可见,该待判断点实际不在多边形范围内:
GeoViz截图

我已参考过相关问题,但给出的方案不适用于当前场景,恳请帮忙排查问题,谢谢!

内容的提问来源于stack exchange,提问作者CPJoshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 12:15:00