我正在尝试确定一个点是否在多边形内.Polygon由Point对象数组定义.我可以很容易地弄清楚该点是否在多边形的有界框内,但我不知道如何判断它是否在实际多边形内.如果可能的话,我只想使用C#和WinForms.我宁愿不打电话给OpenGL或其他什么来做这个简单的任务.
这是我到目前为止的代码:
private void CalculateOuterBounds()
{
//m_aptVertices is a Point[] which holds the vertices of the polygon.
// and X/Y min/max are just ints
Xmin = Xmax = m_aptVertices[0].X;
Ymin = Ymax = m_aptVertices[0].Y;
foreach(Point pt in m_aptVertices)
{
if(Xmin > pt.X)
Xmin = pt.X;
if(Xmax < pt.X)
Xmax = pt.X;
if(Ymin > pt.Y)
Ymin = pt.Y;
if(Ymax < pt.Y)
Ymax = pt.Y;
}
}
public bool Contains(Point pt)
{
bool bContains = true; //obviously wrong at the moment :) …Run Code Online (Sandbox Code Playgroud) 我正在寻找在.NET中实现空间查询而不使用SQL2008.第一个要求是能够创建(BTree样式)空间索引并能够查询它.
尽管SQL 2008附带了针对类型的.NET库,但您需要将SQL用于空间索引.
是否有人使用任何.NET库来处理空间数据(操作系统或商业)?我正在看NetTopologySuite,但它看起来很安静,我不想要一个死库.