复杂多边形中Simplify化
在st_GEMETRY函数中,需要构造Geometry对象时,必须是简单闭合的几何对象,在一些空间查询或者叠加分析或者绘图中会涉及到复杂多边形的问题,包括有环中有岛等情况,既然多边形比较复杂,通过AO做些处理,也就是simpify化
先根据坐标构造一个Polygon,然后通过ITopologicalOperator3 维护Polygon的拓扑关系,进行simpify化,这样就可以用st_GEMETRY进行复杂的多边形计算了
#region 复杂多边形Simplify化
/// <summary>
/// 复杂多边形Simplify化
/// </summary>
/// <param name="queryExtent"></param>
/// <returns></returns>
public static string GetSimplifyString(string queryExtent)
{
string s_queryExtent = "";
queryExtent=TransferQueryString(queryExtent);
int sIndex = queryExtent.IndexOf('(')+2;
int eIndex = queryExtent.IndexOf(')');
int lenght = eIndex - sIndex;
string Wkt = queryExtent.Substring(sIndex, lenght);
Wkt = Wkt.Trim();
string[] points = Wkt.Split(',');
IPointCollection pointCollection = null;
object mis1 = System.Type.Missing;
object mis2 = System.Type.Missing;
IPolygon2 mypolylin = new PolygonClass();
pointCollection = mypolylin as IPointCollection;
for (int nID = 0; nID < points.Length; nID++)
{
string[] location = points[nID].Split('|');
double x;
double y;
double.TryParse(location[0], out x);
double.TryParse(location[1], out y);
IPoint pPoint = new PointClass();
pPoint.PutCoords(x, y);
pointCollection.AddPoint(pPoint, ref mis1, ref mis2);
}
IPolygon3 pPolygon2 = pointCollection as IPolygon3;
//重新维护topo关系,复杂多边形simplify化
ITopologicalOperator3 topo = pPolygon2 as ITopologicalOperator3;
if (!topo.IsKnownSimple)
{
if (!topo.IsSimple)
topo.Simplify();
}
IPolygon pPolygon = pPolygon2 as IPolygon;
s_queryExtent = AoPolygonToWkt(pPolygon, false, 0);
return s_queryExtent;
}
#endregion
浙公网安备 33010602011771号