本文整理汇总了C#中ICoordinateSequence.GetOrdinate方法的典型用法代码示例。如果您正苦于以下问题:C# ICoordinateSequence.GetOrdinate方法的具体用法?C# ICoordinateSequence.GetOrdinate怎么用?C# ICoordinateSequence.GetOrdinate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICoordinateSequence
的用法示例。
在下文中一共展示了ICoordinateSequence.GetOrdinate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public WpfPoint[] Transform(ICoordinateSequence modelSequence)
{
var res = new WpfPoint[modelSequence.Count];
for (var i = 0; i < modelSequence.Count; i++)
{
res[i] = Transform(modelSequence.GetOrdinate(i, Ordinate.X),
modelSequence.GetOrdinate(i, Ordinate.Y));
}
return res;
}
示例2: Swap
/// <summary>
/// Swaps two coordinates in a sequence.
/// </summary>
/// <param name="seq"></param>
/// <param name="i"></param>
/// <param name="j"></param>
public static void Swap(ICoordinateSequence seq, int i, int j)
{
if (i == j)
return;
for (int dim = 0; dim < seq.Dimension; dim++)
{
double tmp = seq.GetOrdinate(i, (Ordinates)dim);
seq.SetOrdinate(i, (Ordinates)dim, seq.GetOrdinate(j, (Ordinates)dim));
seq.SetOrdinate(j, (Ordinates)dim, tmp);
}
}
示例3: EnsureValidRing
/// <summary>
/// Ensures that a CoordinateSequence forms a valid ring,
/// returning a new closed sequence of the correct length if required.
/// If the input sequence is already a valid ring, it is returned
/// without modification.
/// If the input sequence is too short or is not closed,
/// it is extended with one or more copies of the start point.
/// </summary>
/// <param name="fact">The CoordinateSequenceFactory to use to create the new sequence</param>
/// <param name="seq">The sequence to test</param>
/// <returns>The original sequence, if it was a valid ring, or a new sequence which is valid.</returns>
public static ICoordinateSequence EnsureValidRing(ICoordinateSequenceFactory fact, ICoordinateSequence seq)
{
var n = seq.Count;
// empty sequence is valid
if (n == 0) return seq;
// too short - make a new one
if (n <= 3)
return CreateClosedRing(fact, seq, 4);
var isClosed = Math.Abs(seq.GetOrdinate(0, Ordinate.X) - seq.GetOrdinate(n - 1, Ordinate.X)) < double.Epsilon &&
Math.Abs(seq.GetOrdinate(0, Ordinate.Y) - seq.GetOrdinate(n - 1, Ordinate.Y)) < double.Epsilon;
if (isClosed) return seq;
// make a new closed ring
return CreateClosedRing(fact, seq, n + 1);
}
示例4: CopyCoord
///<summary>
/// Copies a coordinate of a <see cref="ICoordinateSequence"/> to another <see cref="ICoordinateSequence"/>.
/// The sequences may have different dimensions;
/// in this case only the common dimensions are copied.
///</summary>
/// <param name="src">The sequence to copy coordinate from</param>
/// <param name="srcPos">The index of the coordinate to copy</param>
/// <param name="dest">The sequence to which the coordinate should be copied to</param>
/// <param name="destPos">The index of the coordinate in <see paramref="dest"/></param>
public static void CopyCoord(ICoordinateSequence src, int srcPos, ICoordinateSequence dest, int destPos)
{
int minDim = Math.Min(src.Dimension, dest.Dimension);
for (int dim = 0; dim < minDim; dim++)
{
Ordinate ordinate = (Ordinate)dim;
double value = src.GetOrdinate(srcPos, ordinate);
dest.SetOrdinate(destPos, ordinate, value);
}
}
示例5: DoTest
private static void DoTest(ICoordinateSequence forward, ICoordinateSequence reversed)
{
const double eps = 1e-12;
Assert.AreEqual(forward.Count, reversed.Count, "Coordinate sequences don't have same size");
Assert.AreEqual(forward.Ordinates, reversed.Ordinates, "Coordinate sequences don't serve same ordinate values");
var ordinates = OrdinatesUtility.ToOrdinateArray(forward.Ordinates);
var j = forward.Count;
for (var i = 0; i < forward.Count; i++)
{
j--;
foreach(var ordinate in ordinates)
Assert.AreEqual(forward.GetOrdinate(i, ordinate), reversed.GetOrdinate(j, ordinate), eps, string.Format("{0} values are not within tolerance", ordinate));
var cf = forward.GetCoordinate(i);
var cr = reversed.GetCoordinate(j);
Assert.IsFalse(ReferenceEquals(cf, cr), "Coordinate sequences deliver same coordinate instances");
Assert.IsTrue(cf.Equals(cr), "Coordinate sequences do not provide equal coordinates");
}
}
示例6: WriteSequence
private static void WriteSequence(ICoordinateSequence sequence, PostGis2GeometryHeader pgh, BinaryWriter writer, int numPoints)
{
if (numPoints == -1)
{
numPoints = sequence.Count;
writer.Write(numPoints);
}
var ordinateIndices = pgh.OrdinateIndices;
for (var i = 0; i < numPoints; i++)
{
foreach (var ordinateIndex in ordinateIndices)
writer.Write(sequence.GetOrdinate(i, ordinateIndex));
}
}
示例7: SetDimension
private static ICoordinateSequence SetDimension(ICoordinateSequenceFactory fact, ICoordinateSequence seq,
int dimension)
{
if (seq.Dimension == dimension)
return seq;
var res = fact.Create(seq.Count, dimension);
dimension = Math.Min(dimension, seq.Dimension);
for (var i = 0; i < seq.Count; i++)
{
for (var j = 0; j < dimension; j++)
res.SetOrdinate(i, (Ordinate)j, seq.GetOrdinate(i, (Ordinate)j));
}
return res;
}
示例8: IsAllCoordsEqual
bool IsAllCoordsEqual(ICoordinateSequence seq, Coordinate coord)
{
for (int i = 0; i < seq.Count; i++)
{
if (!coord.Equals(seq.GetCoordinate(i)))
return false;
if (coord.X != seq.GetOrdinate(i, Ordinate.X))
return false;
if (coord.Y != seq.GetOrdinate(i, Ordinate.Y))
return false;
if (coord.Z != seq.GetOrdinate(i, Ordinate.Z))
return false;
}
return true;
}
示例9: EnsureClosedSequence
/// <summary>
/// Function to return a coordinate sequence that is ensured to be closed.
/// </summary>
/// <param name="sequence">The base sequence</param>
/// <param name="factory">The factory to use in case we need to create a new sequence</param>
/// <returns>A closed coordinate sequence</returns>
private static ICoordinateSequence EnsureClosedSequence(ICoordinateSequence sequence,
ICoordinateSequenceFactory factory)
{
//This sequence won't serve a valid linear ring
if (sequence.Count < 3)
return null;
//The sequence is closed
var start = sequence.GetCoordinate(0);
var lastIndex = sequence.Count - 1;
var end = sequence.GetCoordinate(lastIndex);
if (start.Equals2D(end))
return sequence;
// The sequence is not closed
// 1. Test for a little offset, in that case simply correct x- and y- ordinate values
const double eps = 1E-7;
if (start.Distance(end) < eps)
{
sequence.SetOrdinate(lastIndex, Ordinate.X, start.X);
sequence.SetOrdinate(lastIndex, Ordinate.Y, start.Y);
return sequence;
}
// 2. Close the sequence by adding a new point, this is heavier
var newSequence = factory.Create(sequence.Count + 1, sequence.Ordinates);
var ordinates = OrdinatesUtility.ToOrdinateArray(sequence.Ordinates);
for (var i = 0; i < sequence.Count; i++)
{
foreach (var ordinate in ordinates)
newSequence.SetOrdinate(i, ordinate, sequence.GetOrdinate(i, ordinate));
}
foreach (var ordinate in ordinates)
newSequence.SetOrdinate(sequence.Count, ordinate, sequence.GetOrdinate(0, ordinate));
return newSequence;
}
示例10: ToDoubleArray
private static double[] ToDoubleArray(ICoordinateSequence sequence, out double[] z)
{
var res = new double[sequence.Count*2];
z = ((sequence.Ordinates & Ordinates.Z) == Ordinates.Z) ? new double[sequence.Count] : null;
var j = 0;
for (var i = 0; i < sequence.Count; i++)
{
res[j++] = sequence.GetOrdinate(i, Ordinate.X);
res[j++] = sequence.GetOrdinate(i, Ordinate.Y);
if (z != null)
z[i] = sequence.GetOrdinate(i, Ordinate.Z);
}
return res;
}
示例11: IsEqual
/// <summary>
/// Tests whether two <see cref="ICoordinateSequence"/>s are equal.
/// To be equal, the sequences must be the same length.
/// They do not need to be of the same dimension,
/// but the ordinate values for the smallest dimension of the two
/// must be equal.
/// Two <c>NaN</c> ordinates values are considered to be equal.
/// </summary>
/// <param name="cs1">a CoordinateSequence</param>
/// <param name="cs2">a CoordinateSequence</param>
/// <returns><c>true</c> if the sequences are equal in the common dimensions</returns>
public static bool IsEqual(ICoordinateSequence cs1, ICoordinateSequence cs2)
{
int cs1Size = cs1.Count;
int cs2Size = cs2.Count;
if (cs1Size != cs2Size)
return false;
int dim = Math.Min(cs1.Dimension, cs2.Dimension);
for (int i = 0; i < cs1Size; i++)
{
for (int d = 0; d < dim; d++)
{
Ordinate ordinate = (Ordinate)d;
double v1 = cs1.GetOrdinate(i, ordinate);
double v2 = cs2.GetOrdinate(i, ordinate);
if (cs1.GetOrdinate(i, ordinate) == cs2.GetOrdinate(i, ordinate))
continue;
// special check for NaNs
if (Double.IsNaN(v1) && Double.IsNaN(v2))
continue;
return false;
}
}
return true;
}
示例12: AveragePoint
/**
* Computes a point which is the average of all coordinates
* in a sequence.
* If the sequence lies in a single plane,
* the computed point also lies in the plane.
*
* @param seq a coordinate sequence
* @return a Coordinate with averaged ordinates
*/
private static Coordinate AveragePoint(ICoordinateSequence seq)
{
var a = new Coordinate(0, 0, 0);
var n = seq.Count;
for (var i = 0; i < n; i++)
{
a.X += seq.GetOrdinate(i, Ordinate.X);
a.Y += seq.GetOrdinate(i, Ordinate.Y);
a.Z += seq.GetOrdinate(i, Ordinate.Z);
}
a.X /= n;
a.Y /= n;
a.Z /= n;
return a;
}
示例13: CheckOrdinates
private static Ordinates CheckOrdinates(ICoordinateSequence sequence)
{
if (sequence == null || sequence.Count == 0)
return Ordinates.None;
var result = Ordinates.XY;
if ((sequence.Ordinates & Ordinates.Z) != 0)
{
if (!Double.IsNaN(sequence.GetOrdinate(0, Ordinate.Z)))
result |= Ordinates.Z;
}
if ((sequence.Ordinates & Ordinates.M) != 0)
{
if (!Double.IsNaN(sequence.GetOrdinate(0, Ordinate.M)))
result |= Ordinates.Z;
}
return result;
}
示例14: Write
private static void Write(ICoordinateSequence sequence, Ordinates ordinates, BinaryWriter writer, bool justOne)
{
if (sequence == null || sequence.Count == 0)
return;
var length = (justOne ? 1 : sequence.Count);
if (!justOne)
writer.Write(length);
for (var i = 0; i < length; i++)
{
writer.Write(sequence.GetOrdinate(i, Ordinate.X));
writer.Write(sequence.GetOrdinate(i, Ordinate.Y));
if ((ordinates & Ordinates.Z) != 0)
{
var z = sequence.GetOrdinate(i, Ordinate.Z);
if (double.IsNaN(z)) z = 0d;
writer.Write(z);
}
if ((ordinates & Ordinates.M) != 0)
{
var m = sequence.GetOrdinate(i, Ordinate.M);
if (double.IsNaN(m)) m = 0d;
writer.Write(m);
}
}
}
示例15: IsRing
/// <summary>
/// Tests whether a <see cref="ICoordinateSequence"/> forms a valid <see cref="ILinearRing"/>,
/// by checking the sequence length and closure
/// (whether the first and last points are identical in 2D).
/// Self-intersection is not checked.
/// </summary>
/// <param name="seq">The sequence to test</param>
/// <returns>True if the sequence is a ring</returns>
/// <seealso cref="ILinearRing"/>
public static bool IsRing(ICoordinateSequence seq)
{
int n = seq.Count;
if (n == 0) return true;
// too few points
if (n <= 3)
return false;
// test if closed
return seq.GetOrdinate(0, Ordinate.X) == seq.GetOrdinate(n - 1, Ordinate.X)
&& seq.GetOrdinate(0, Ordinate.Y) == seq.GetOrdinate(n - 1, Ordinate.Y);
}