是的,这是默认实现中缺少的错误ICoordinateSequence
功能。看起来他们已经开始进行更改以支持 M 值,但这些更改并没有在所有地方进行。以下是代码中不支持 M 值的至少一个区域,这最终导致了您所看到的问题。
引用 p3.M 时,它使用这些 get 和 set 方法。
public double M
{
get
{
if (CoordinateSequence == null)
throw new ArgumentOutOfRangeException("M called on empty Point");
return CoordinateSequence.GetOrdinate(0, Ordinate.M);
}
set => CoordinateSequence.SetOrdinate(0, Ordinate.M, value);
}
然后依次调用GetOrdinate
和SetOrdinate
CoordinateArraySequence
/// <summary>
/// Returns the ordinate of a coordinate in this sequence.
/// Ordinate indices 0 and 1 are assumed to be X and Y.
/// Ordinate indices greater than 1 have user-defined semantics
/// (for instance, they may contain other dimensions or measure values).
/// </summary>
/// <param name="index">The coordinate index in the sequence.</param>
/// <param name="ordinate">The ordinate index in the coordinate (in range [0, dimension-1]).</param>
/// <returns></returns>
public double GetOrdinate(int index, Ordinate ordinate)
{
switch (ordinate)
{
case Ordinate.X:
return Coordinates[index].X;
case Ordinate.Y:
return Coordinates[index].Y;
case Ordinate.Z:
return Coordinates[index].Z;
default:
return double.NaN;
}
}
/// <summary>
/// Sets the value for a given ordinate of a coordinate in this sequence.
/// </summary>
/// <param name="index">The coordinate index in the sequence.</param>
/// <param name="ordinate">The ordinate index in the coordinate (in range [0, dimension-1]).</param>
/// <param name="value">The new ordinate value.</param>
public void SetOrdinate(int index, Ordinate ordinate, double value)
{
switch (ordinate)
{
case Ordinate.X:
Coordinates[index].X = value;
break;
case Ordinate.Y:
Coordinates[index].Y = value;
break;
case Ordinate.Z:
Coordinates[index].Z = value;
break;
//default:
// //throw new ArgumentException("invalid ordinate index: " + ordinate);
}
}
正如您所看到的,当您调用SetOrdinate
时Ordinate.M
没有真正设置,并且调用GetOrdinate
时Ordinate.M
将始终返回 NaN。
如果你真的想使用 NetTopologySuite,你可以从这里分叉回购https://github.com/NetTopologySuite/NetTopologySuite并进行默认情况下支持M
值所需的更新,但我想有很多事情需要做改变了。如果您确实更新它,我相信维护 NetTopologySuite GitHub 存储库的人会很感激任何更改的拉取请求。