I need to check if a lat/lon with radius is intersecting with a bounding box using Dotspatial.
Using dotspatial one can intersect using Ifeatures. My problem right now is creating a circle/sphere/ellipse.
I found the following code snippet on how to create a circle.
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);
Yet i can't find anything usefull about the buffer option (what unit?(meter or km), does this work with intersect function?)
Can someone point me in the right direction on intersection using bounding boxes and points with a radius?
The unit for Buffer will be in whatever unit your dataset is in. If you are in a projected coordinate system, the unit will probably either be in feet or meters, depending on the projection. If you are in a geographic projection, like WGS84, then the unit of measure is in decimal degrees.
When working with DotSpatial, it is frequently necessary to go back and forth between geographic units and pixel units. For hit testing, here is some sample code involving rectangles and envelopes which are square but provide a convenient way to give an approximate region around your coordinate for hit testing.
Using Buffer, like your example above, is mostly used for more detailed geometry calculations where you are creating a permanent geometry that can be used, not just for intersecting, but also for visualization of the buffered area.
Geometries all obey the IGeometry relate operators, so both the original Point you used and the output LineString from the Buffer operation would work for intersecting, but will be slower than if you use an envelope.
Here is some basic hit-testing code working with pixels and coordinates:
/// <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);
}