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

C# 如何使用点空间将边界框和点与半径相交,c#,dotspatial,C#,Dotspatial,我需要检查具有半径的lat/lon是否与使用点空间相交 使用点空间可以使用iFeature相交。 我现在的问题是创建一个圆/球体/椭圆 我找到了下面关于如何创建圆的代码片段 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); 然而,我找不到任

我需要检查具有半径的lat/lon是否与使用点空间相交

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

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

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);
然而,我找不到任何关于缓冲区选项的有用信息(什么单位?(米或公里),这与intersect功能一起工作吗?)


有人能用边界框和半径点在交叉点上为我指出正确的方向吗?

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

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

使用缓冲区(如上面的示例)主要用于更详细的几何体计算,其中创建的永久几何体不仅可用于相交,还可用于缓冲区域的可视化

所有几何图形都遵循IGometry relate操作符,因此使用的原点和缓冲区操作的输出线字符串都适用于相交,但速度会比使用封套慢

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

    /// <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);
    }
//
///此方法创建矩形地理封套,该封套由
///以原始地理单位表示的指定地理金额。信封
///因为它们比地理形状更简单,
///因此,进行交叉测试要快得多。
/// 
///X和Y的中心点。
///包含中心点的矩形封套。
公共静态包络线延伸(坐标中心,双倍距离)
{
包络结果=新包络(中心);
结果:ExpandBy(距离);
返回结果;
}
/// 
///使用包络线进行交叉测试的工作原理与使用较慢包络线的工作原理相同
///和更重的几何图形,但速度应该更快。
/// 
///测试点。
///装盒子的信封。
///布尔值,如果框与(包含或接触)对象相交,则为true
///测试点。
公共静态bool CONTANSTEST(坐标测试点、信封盒)
{
返回框。相交(测试点);
}
/// 
///获取像素X、Y位置周围10个像素的地理封套
///根据实际可见地图组件在地图上的坐标(而不是
///映射帧的可能扩展缓冲区)。
/// 
///地图控件上中心的像素位置
///地图控件
///地理范围
公共静态封套展开(点中心、地图)
{
矩形rect=新矩形(center.X-10,center.Y-10,20,20);
//获取地理点
返回图。像素点(rect);
}
/// 
///获取一个像素坐标包围矩形的步骤
///命中测试与此类似。
/// 
///地理坐标
///地图控件
///指定坐标的像素坐标矩形
公共静态矩形边界(坐标测试、地图)
{
包络结果=新包络(中心);
结果:ExpandBy(距离);
返回map.ProjToPixel(结果);
}

谢谢你解释得很好的答案!