如何使用点空间与半径相交的边界框和点
本文关键字:边界 何使用 空间 | 更新日期: 2023-09-27 17:54:19
我需要使用dotspace检查具有半径的经纬度是否与边界框相交。
使用点空间可以使用i特征相交。我现在的问题是创建一个圆/球/椭圆。
我找到了下面这个关于如何创建圆的代码片段。
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);
然而,我找不到任何有用的缓冲区选项(什么单位?(米或公里),这是否适用于相交函数?
有人能在使用边界框和半径点的交叉点上为我指出正确的方向吗?
缓冲区的单位将是您的数据集所在的单位。如果在投影坐标系中,单位可能是英尺或米,取决于投影。如果您在地理投影中,如WGS84,则度量单位为十进制。
当使用DotSpatial时,经常需要在地理单位和像素单位之间来回转换。对于命中测试,这里有一些涉及矩形和信封的示例代码,它们是正方形的,但提供了一种方便的方法,可以在你的坐标周围给出一个近似区域来进行命中测试。
使用Buffer,就像你上面的例子一样,主要用于更详细的几何计算,在这些计算中,你要创建一个永久的几何图形,不仅可以用于相交,还可以用于缓冲区域的可视化。
几何都服从几何相关运算符,因此您使用的原始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);
}