0

我得到了经度和纬度的地理坐标,例如西北和东南经度/纬度。所以,当我得到它们时,我会翻译成公制。所以在这里我得到了我的第一个矩形,带有north_west和south_east坐标,然后我在具有北、南、西和东坐标的同一公制系统中有边界矩形。我需要在边缘触摸的交叉点上检查这两个矩形,我写的是:

bool filter(TilePosition const& tile_position) const noexcept override 
{
    MetricBoundingBox tile_bounds{tile_position};

    bool cond1 = (tile_bounds.north <= south_east_.lon);
    bool cond2 = (tile_bounds.south >= north_west_.lon);
    bool cond3 = (tile_bounds.west <= south_east_.lat);
    bool cond4 = (tile_bounds.east >= north_west_.lat);

    return cond1 && cond2 && cond3 && cond4;
} 

而且我不确定我是否做对了?我的要求是,如果第二个矩形的边界与第一个矩形的边界相交,则必须留下第二个。否则,过滤。

4

1 回答 1

1

您的解决方案不正确。

除了混淆纬度和经度的含义之外,您还有一个基本问题,即为笛卡尔坐标空间设计的算法不适用于柱坐标,因为经度是周期性的。对于子午线附近的矩形,情况可能看起来不错,但是当您在环绕点(+/- 180 度经度)附近开始测试时,此方法将失败。

一个简单的解决方法是将每个穿过环绕点的矩形分成两个不相交的矩形。

于 2018-12-28T16:15:01.320 回答