【问题标题】:How to intersect boundingbox and point with radius using dotspatial如何使用点空间与半径相交边界框和点
【发布时间】:2015-07-15 05:43:22
【问题描述】:

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

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

我找到了以下关于如何创建圆的代码 sn-p。

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

但我找不到关于缓冲区选项的任何有用信息(什么单位?(米或公里),这是否适用于相交函数?)

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

【问题讨论】:

    标签: c# dotspatial


    【解决方案1】:

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

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

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

    几何图形都遵循 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);
        }
    

    【讨论】:

    • 感谢您详细解释的答案!
    猜你喜欢
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 2019-05-13
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多