/// <summary>
/// 点是否在多边形内
/// </summary>
/// <param name="pt">点</param>
/// <param name="py">面</param>
/// <returns></returns>
public static bool isPointInPolygon(MapPoint pt,Polygon py)
{
int nCross = 0;
PointCollection pc = py.Rings[0];
for (int i = 0; i < pc.Count; i++)
{
MapPoint p1 = pc[i];
MapPoint p2 = pc[(i + 1) % pc.Count];
// 求解 y=p.y 与 p1p2 的交点
if (p1.Y == p2.Y) // p1p2 与 y=p0.y平行
continue;
if (pt.Y <Math.Min(p1.Y, p2.Y)) // 交点在p1p2延长线上
continue;
if (pt.Y >= Math.Max(p1.Y, p2.Y)) // 交点在p1p2延长线上
continue;
// 求交点的 X 坐标 --------------------------------------------------------------
double x = (double)(pt.Y - p1.Y) * (double)(p2.X - p1.X) / (double)(p2.Y - p1.Y) + p1.X;
if (x > pt.X)
nCross++; // 只统计单边交点
}
// 单边交点为偶数,点在多边形之外 ---
return (nCross % 2 == 1);
}