//外环和内环?面的构造比较复杂,在AO中我们可以获取内环和外环,如果注意过在客户端API中的Rings数组,似乎看不出,所以这里我没采用外环和内环的构造方式,但是代码在后面附上。
IGeometryCollection pGeoetryCollection1 = pPolygon as IGeometryCollection;
if (pGeoetryCollection1.GeometryCount >=1)
{
sb.Append(@"""rings"":[");
for (int i = 0; i < pGeoetryCollection1.GeometryCount; i++)
{
if (pGeoetryCollection1.get_Geometry(i) is IRing)
{
sb.Append("[");
pPoints = pGeoetryCollection1.get_Geometry(i) as IPointCollection;
for (int j = 0; j < pPoints.PointCount;j++ )
{
pPoint = pPoints.get_Point(j);
pPoint.QueryCoords(out x, out y);
sb.Append("[" + x + "," + y + "],");
}
sb.Remove(sb.Length - 1, 1);
sb.Append("]");
}
}
sb.Append("]" + @",""spatialReference"":" + @"{""wkid"":" + wkid + "}");
}
break;
#endregion
}
sb.Append("}");
//添加Geometry
sb.Append("}");
return sb.ToString();
}
下面是获取面的内环和外环的坐标
public void PolygonToString(IPolygon4 polygon)
{
IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag;
IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection;
Trace.WriteLine("polygon.ExteriorRingCount = "+ exteriorRingGeometryCollection.GeometryCount);
for(int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
{
Trace.WriteLine("polygon.ExteriorRing["+ i +"]");
IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);
IPointCollection exteriorRingPointCollection = exteriorRingGeometry as IPointCollection;
for(int j = 0; j < exteriorRingPointCollection.PointCount; j++)
{
Trace.WriteLine("Point["+ j +"] = "+ PointToString(exteriorRingPointCollection.get_Point(j)));
}
IGeometryBag interiorRingGeometryBag = polygon.get_InteriorRingBag(exteriorRingGeometry as IRing);
IGeometryCollection interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection;
Trace.WriteLine("polygon.InteriorRingCount[exteriorRing"+ i +"] = "+ interiorRingGeometryCollection.GeometryCount);
for(int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++)
{
Trace.WriteLine("polygon.InteriorRing["+ k +"]");
IGeometry interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k);
IPointCollection interiorRingPointCollection = interiorRingGeometry as IPointCollection;
for(int m = 0; m < interiorRingPointCollection.PointCount; m++)
{
Trace.WriteLine("Point["+ m +"] = "+ PointToString(interiorRingPointCollection.get_Point(m)));
}
}
}
}
private string PointToString(IPoint point)
{
return(point.X +", "+ point.Y +", "+ point.Z);
}