// 将面Geometry拆分,逐个点进行坐标转换,再组装成面Geometry
public static bool GetPolygon(IGeometry pGeometry, out IGeometry pOutGeometry, out Exception error)
{
error = null;
pOutGeometry = null;
try
{
IPolygon4 pPolygon = pGeometry as IPolygon4;
IGeometryCollection pAllGeometryCollection = new Polygon() as IGeometryCollection;
if (pPolygon != null)
{
//获取多边形的所有外环
IGeometryBag bag = pPolygon.ExteriorRingBag;
IEnumGeometry geo = bag as IEnumGeometry;
geo.Reset();
IRing exRing = geo.Next() as IRing;
while (exRing != null)
{
IGeometryCollection pNewInCollectio = new Polygon() as IGeometryCollection;
// 获取当前外环所包含的内环++
IGeometryBag bags = pPolygon.get_InteriorRingBag(exRing);
IEnumGeometry geos = bags as IEnumGeometry;
geos.Reset();
IRing inRing = geos.Next() as IRing;
while (inRing != null)
{
IGeometry pNewInRing = null;
if (!ReBuild(url, inRing, out pNewInRing, out error))
{
return false;
}
pNewInCollectio.AddGeometry(pNewInRing);
inRing = geos.Next() as IRing;
}
IGeometry pNewExRing = null;
if (!ReBuild(url, exRing, out pNewExRing, out error))
{
return false;
}
pAllGeometryCollection.AddGeometry(pNewExRing);
pAllGeometryCollection.AddGeometryCollection(pNewInCollectio);
exRing = geo.Next() as IRing;
}
pOutGeometry = pAllGeometryCollection as IGeometry;
return true;
}
else
{
error = new Exception("图形为空");
return false;
}
}
catch (Exception ex)
{
error = ex;
return false;
}
}
// 处理线性环
public static bool ReBuild( IGeometry pGeometry, out IGeometry pOutGeometry, out Exception error)
{
error = null;
pOutGeometry = null;
try
{
ISegmentCollection segmentCollection = pGeometry as ISegmentCollection;
ISegmentCollection pNewSegmentCollection = new RingClass();
Dictionary<string, string> dicXYAndAfterXY = new Dictionary<string, string>();
// 这是不可能的,除非是具有圆弧的线
if (segmentCollection.SegmentCount == 1)
{
error = new Exception("segmentCollection.SegmentCount == 1");
return false;
}
else
{
double x = 0;
double y = 0;
for (int i = 0; i < segmentCollection.SegmentCount; i++)
{
ISegment segment = segmentCollection.Segment[i];
// 线段起点
IPoint pStartPoint = segment.FromPoint;
x = pStartPoint.X;
y = pStartPoint.Y;
pStartPoint.X = x - 300000;
pStartPoint.Y = y - 300000;
// 线段终点
IPoint pToPoint = segment.ToPoint;
x = pToPoint.X;
y = pToPoint.Y;
pToPoint.X = x - 300000;
pToPoint.Y = y - 300000;
ISegment pNewSegment = new LineClass();
pNewSegment.FromPoint = pStartPoint;
pNewSegment.ToPoint = pToPoint;
pNewSegmentCollection.AddSegment(pNewSegment);
}
}
pOutGeometry = pNewSegmentCollection as IRing;
return true;
}
catch (Exception ex)
{
error = ex;
return false;
}
}
05-31
10-29
4088
04-26
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交