protected static ICoordinateSequence AddCoordinateToSequence(ICoordinateSequence sequence, ICoordinateSequenceFactory factory, double x, double y, double?z, double?m) { // Create a new sequence var newSequence = factory.Create(sequence.Count + 1, sequence.Ordinates); // Copy old values 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)); } } // new coordinate newSequence.SetOrdinate(sequence.Count, Ordinate.X, x); newSequence.SetOrdinate(sequence.Count, Ordinate.Y, y); if (z.HasValue) { newSequence.SetOrdinate(sequence.Count, Ordinate.Z, z.Value); } if (m.HasValue) { newSequence.SetOrdinate(sequence.Count, Ordinate.M, m.Value); } return(newSequence); }
private static IGeometry CreatePoint(Ordinates ordinates, bool empty) { if (empty) { return(Factory.CreatePoint((ICoordinateSequence)null)); } var seq = CsFactory.Create(1, ordinates); foreach (var o in OrdinatesUtility.ToOrdinateArray(ordinates)) { seq.SetOrdinate(0, o, RandomOrdinate(o, Factory.PrecisionModel)); } return(Factory.CreatePoint(seq)); }
/// <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); }
private static IGeometry CreateMultiPoint(Ordinates ordinates, bool empty) { if (empty) { return(Factory.CreateMultiPoint((ICoordinateSequence)null)); } int numPoints = Rnd.Next(75, 101); var seq = CsFactory.Create(numPoints, ordinates); for (int i = 0; i < numPoints; i++) { foreach (var o in OrdinatesUtility.ToOrdinateArray(ordinates)) { seq.SetOrdinate(i, o, RandomOrdinate(o, Factory.PrecisionModel)); } } return(Factory.CreateMultiPoint(seq)); }
/// <summary> /// Transforms a <see cref="MultiPoint" /> object. /// </summary> /// <param name="factory"></param> /// <param name="points"></param> /// <param name="transform"></param> /// <returns></returns> public static IMultiPoint TransformMultiPoint(IGeometryFactory factory, IMultiPoint points, IMathTransform transform) { //We assume the first point holds all the ordinates var ordinateFlags = ((IPoint)points.GetGeometryN(0)).CoordinateSequence.Ordinates; var ordinates = OrdinatesUtility.ToOrdinateArray(ordinateFlags); var coordSequence = factory.CoordinateSequenceFactory.Create(points.NumPoints, ordinateFlags); for (var i = 0; i < points.NumGeometries; i++) { var seq = ((IPoint)points.GetGeometryN(i)).CoordinateSequence; foreach (var ordinate in ordinates) { coordSequence.SetOrdinate(i, ordinate, seq.GetOrdinate(i, ordinate)); } } var transPoints = transform.Transform(coordSequence); return(factory.CreateMultiPoint(transPoints)); }
private static void TestCoordinateSequences(ICoordinateSequence orig, ICoordinateSequence trans) { Assert.AreNotSame(orig, trans, "Seqences are same"); Assert.AreEqual(orig.Count, trans.Count, "Sequences have different lengths"); Assert.AreEqual(orig.Ordinates, trans.Ordinates, "Sequences provide different ordinates"); var ordinates = OrdinatesUtility.ToOrdinateArray(orig.Ordinates); for (var i = 0; i < orig.Count; i++) { foreach (var ordinate in ordinates) { var v1 = orig.GetOrdinate(i, ordinate); var v2 = trans.GetOrdinate(i, ordinate); if (double.IsNaN(v1)) { Assert.IsTrue(double.IsNaN(v2)); continue; } if (double.IsPositiveInfinity(v1)) { Assert.IsTrue(double.IsPositiveInfinity(v2)); continue; } if (double.IsNegativeInfinity(v1)) { Assert.IsTrue(double.IsNegativeInfinity(v2)); continue; } Assert.AreNotEqual(v1, v2, "Sequences provide equal value for '{0}'", ordinate); } } }
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); int j = forward.Count; for (int 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"); } }