我有將要被轉換成一組折線點的文件。一些線是多部分,我想將它們轉換爲單部分。 處理點並將多段線添加到臨時要素類(用於備份目的)。如果一行是多部分,則它將作爲多部分添加到此臨時要素類中。 然後讀取臨時要素類,並將其複製到基本要素類中。這適用於單部件特徵,但在將多部件轉換爲單部件時,我始終得到'不支持此幾何類型'的錯誤。問題是,要從一組點創建多部分功能,我必須將一個段集合用作Path。我試着把它設置成多段線,但是向它添加線段會導致錯誤(錯誤的幾何類型)。IGeometryCollection折線的返回路徑
當我到多的功能添加到臨時要素類的幾何形狀折線。當我稍後檢索它們(通過將形狀放入新的GeometryCollection中)時,幾何集合是Polyline,但各個幾何體是Paths(?)。
的代碼是:
1. Add points to interim featureclass by putting them in a pointcollection.
pPtColl = (IPointCollection4)new Polyline();
pGeomColl = (IGeometryCollection)new Polyline();
// Fill point collection
.......
// Create a path made up of segments from the point collection
ISegment pSegment;
ISegmentCollection pSegColl = (ISegmentCollection)new ESRI.ArcGIS.Geometry.Path(); // Fails if changed to new Polyline()
// M and Z aware
if (bHasZ == true)
{
pZAware = (IZAware)pSegColl;
pZAware.ZAware = true;
}
if (bHasM == true)
{
pMAware = (IMAware)pSegColl;
pMAware.MAware = true;
}
for (int n = 1; n < pPtColl.PointCount; n++)
{
pSegment = (ISegment)new Line();
pSegment.SpatialReference = pSpRef;
pSegment.FromPoint = pPtColl.Point[n - 1];
pSegment.ToPoint = pPtColl.Point[n];
pSegColl.AddSegment(pSegment, oMissing, oMissing);
}
pGeomColl.AddGeometry(pSegColl as IGeometry, oMissing, oMissing);
pGeom = (IGeometry)pGeomColl; // pGeom has geometry type = Polyline
pGeom.SpatialReference = pSpRef;
pFeat.Shape = pGeom;
代碼一切工作正常的這一部分。 處理臨時要素類中的這些要素以將它們添加到基礎要素類時,我收到一個錯誤,因爲幾何集合中的幾何類型是'路徑'而不是'折線'。
// Read the geometry from the interim feature into a geometry collection
pGeomColl = (IGeometryCollection)new Polyline();
pGeomColl = (IGeometryCollection)pFromFeature.ShapeCopy;
for (int j = 0; j < pGeomColl.GeometryCount; j++)
{
// Create a new (Polyline) feature pToFeat and populate its attributes
pToFeat = pToFC.CreateFeature();
....
// pGeomColl has geometry type = Polyline
pGeom = pGeomColl.Geometry[j]; // pGeom has geometry type = Path
pToFeat.Shape = pGeom; // Fails. pToFeat is a Polyline.
}
如何確保幾何集合包含帶多段線而不是路徑的幾何?
感謝,
JM