我正在使用NetTopologySuite進行一些簡化行。將Point3D列表轉換爲座標數組
我面臨的問題是我有我自己的類,Point3D(System.Windows.Media) 的商店列表和NetTopology有它自己的座標類,幾乎具有相同的屬性和功能。
要轉換的三維點列表coorinate陣列我使用這個功能:
public static GeoApiInterfaces.ICoordinate[] ToCoordinateArray(this IEnumerable<Point3D> listToClone,
bool isClosed = false)
{
// if geometry is to be closed the size of array will be one more than the
// current point count
var coordinateList = new GeoApiInterfaces.ICoordinate[isClosed ?
listToClone.Count() + 1
: listToClone.Count()];
// loop through all the point in the list to create the array
int elementIndex = 0;
foreach (var point in listToClone)
{
var coordinate = new GeoApiGeometries.Coordinate(point.X,
point.Y,
point.Z);
coordinateList[elementIndex] = coordinate;
elementIndex++;
} // foreach
// if geometry is closed the add the first point to the last
if (isClosed)
{
var coordinate = new GeoApiGeometries.Coordinate(listToClone.ElementAt(0).X,
listToClone.ElementAt(0).Y,
listToClone.ElementAt(0).Z);
coordinateList[elementIndex] = coordinate;
} // if isClosed
return coordinateList;
}
一切工作正常,但是當我異形我的代碼幾乎95%的時間採取的是此功能。我想知道,有沒有其他方法將System.Windows.Media.Point3D的列表轉換爲座標[]。
從一個類到另一個類的轉換同樣如此。
在這個函數中大部分時間花在哪裏?創建「座標」對象?還有別的嗎? – Oded 2012-01-28 11:45:23
我假設您要求更高性能的選項? – Oded 2012-01-28 11:45:55
@Oded是的,我正在尋找更好的性能 – Mohit 2012-01-28 11:52:03