我正在使用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