c# - 使用 map 坐标确定点是否在矩形中

标签 c# geography

我的大脑今天不工作了。我需要测试一个点(纬度、经度)是否位于 map 上的矩形内。矩形由它的北、东、南和西边界定义。问题是所有点或值都在 map 坐标系中。为了处理日期变更线环绕,我假设如果我们从左到右,经度总是“介于”之间。

bool PointInRectangle(Point pt, double North, double East, double South, double West)
{
    // ????
}

最佳答案

假设东和北为正:

bool PointInRectangle(Point pt, double North, double East, double South, double West)
{
    // you may want to check that the point is a valid coordinate
    if (West < East)
    {
        return pt.X < East && pt.X > West && pt.Y < North && pt.Y > South;
    }

    // it crosses the date line
    return (pt.X < East || pt.X > West) && pt.Y < North && pt.Y > South;        
}

关于c# - 使用 map 坐标确定点是否在矩形中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10657098/

相关文章:

c# - 如何为用户控件属性设置初始值?

c# - 上传文件wcf

jquery - 地理测验,突出显示正确答案

html - 如何使我的 SVG map 在浏览器中正确渲染?

nlp - 识别文字中的地理位置

c# - HTML 到格式化文本 C#

c# - Visual Studio - 通过完全限定名称导航到方法

javascript - 为什么巴基斯坦的所有省份都不是绿色的?

c# - NHibernate 中的多对一映射不起作用?

sql - PostGIS:注册一个没有 AddGeometryColumn 的 "geometry"列