如何使用点空间将边界框和点与半径相交

时间:2014-03-28 09:57:17

标签: c# dotspatial

我需要使用Dotspatial检查半径的纬度/经度是否与bounding box相交。

使用点空间可以使用Ifeatures交叉。 我现在的问题是创建一个圆/球/椭圆。

我找到了以下有关如何创建圆圈的代码段。

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);

然而,我找不到有关缓冲选项的任何有用信息(什么单位?(米或公里),这是否适用于交叉功能?)

有人可以使用边界框和具有半径的点来指示我在交叉路口的正确方向吗?

1 个答案:

答案 0 :(得分:3)

缓冲区的单位将位于数据集所在的任何单位中。如果您处于投影坐标系中,则单位可能以英尺或米为单位,具体取决于投影。如果您在地理投影中,如WGS84,则度量单位为十进制度。

使用DotSpatial时,经常需要在地理单位和像素单位之间来回切换。对于命中测试,这里有一些示例代码涉及矩形和包络,它们是方形的,但提供了一种方便的方法来给出坐标周围的近似区域以进行命中测试。

使用缓冲区,就像上面的示例一样,主要用于更详细的几何计算,您可以在其中创建可以使用的永久几何体,不仅用于交叉,还用于缓冲区域的可视化。

Geometries都遵循IGeometry相关运算符,因此您使用的原始Point和Buffer操作中的输出LineString都可以用于交叉,但是比使用信封要慢。

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

    /// <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);
    }