首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何利用点空间与半径相交边界盒和点

如何利用点空间与半径相交边界盒和点
EN

Stack Overflow用户
提问于 2014-03-28 09:57:17
回答 1查看 2.4K关注 0票数 1

我需要检查radius的lat/lon是否与使用Dotspatial的包围盒相交。

利用点空间方法可以利用特征进行相交。我现在的问题是创建一个圆圈/球面/椭圆。

我找到了关于如何创建一个圆的下面的代码片段。

代码语言:javascript
复制
IGeometry g = GeometryFactory.Default.CreatePoint(new Coordinate(lon,lat)); 
g = g.Buffer(10); Radius of Circle 1
f = new Feature(g);
fs.Features.Add(f);

然而,我无法找到任何有用的缓冲选项(什么单位?(米或公里),这与相交功能工作吗?)

有人能用包围框和半径点指出我在交叉口的正确方向吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-23 23:34:08

缓冲区的单位将位于数据集中的任何单元中。如果你是在一个投影坐标系,单位可能是英尺或米,取决于投影。如果你在地理投影中,比如WGS84,那么度量单位是十进制。

在使用DotSpatial时,经常需要在地理单元和像素单元之间来回切换。对于命中测试,这里有一些包含矩形和信封的示例代码,这些矩形和信封是正方形的,但提供了一种方便的方法,可以在您的坐标周围为命中测试提供一个近似区域。

使用缓冲区,就像上面的例子一样,主要用于更详细的几何计算,在这里,您要创建一个永久的几何图形,不仅可以用于相交,还可以用于缓冲区域的可视化。

几何图形都遵循IGeometry相关运算符,所以您使用的原始点和缓冲区操作的输出LineString都可以用于相交,但比使用信封要慢。

下面是一些使用像素和坐标的基本命中测试代码:

代码语言:javascript
复制
    /// <summary>
    /// This method creates a rectangular geographic envelope that is expanded by the 
    /// specified geographic amount in the original geographic units.  Envelopes 
    /// are useful in that they are simpler than geographic shapes,
    /// and so are much quicker to do intersection testing with.
    /// </summary>
    /// <param name="center">The center point in X and Y.</param>
    /// <returns>A rectangular Envelope that contains the center point.</returns>
    public static Envelope Extend(Coordinate center, double distance)
    {
        Envelope result = new Envelope(center);
        result.ExpandBy(distance);
        return result;
    }

    /// <summary>
    /// Intersection testing with an envelope works the same as with the slower 
    /// and heavier geometries, but should be considerably faster.
    /// </summary>
    /// <param name="testPoint">The test point.</param>
    /// <param name="box">The Envelope that has the box.</param>
    /// <returns>Boolean, true if the box intersects with (contains, or touches) the 
    /// test point.</returns>
    public static bool ContainsTest(Coordinate testPoint, Envelope box)
    {
        return box.Intersects(testPoint);
    }

    /// <summary>
    /// To get a geographic envelope 10 pixels around an X, Y position of a pixel 
    /// coordinate on the map, in terms of the actual visible map component (and not 
    /// the possibly extended buffer of the map frame).
    /// </summary>
    /// <param name="center">The pixel position of the center on the map control</param>
    /// <param name="map">The map control</param>
    /// <returns>A Geographic envelope</returns>
    public static Envelope Expand(Point center, Map map)
    {
        Rectangle rect = new Rectangle(center.X - 10, center.Y - 10, 20, 20);
        // Get the geographic points
        return map.PixelToProj(rect);
    }

    /// <summary>
    /// To get a pixel coordinate bounding rectangle around a geographic point for 
    /// hit testing is similar.
    /// </summary>
    /// <param name="test">The geographic coordinate</param>
    /// <param name="map">The map control</param>
    /// <returns>A pixel coordinate rectangle for the specified coordinate</returns>
    public static Rectangle Bounds(Coordinate test, Map map)
    {
        Envelope result = new Envelope(center);
        result.ExpandBy(distance);
        return map.ProjToPixel(result);
    }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22709413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档