private static void Write(CoordinateSequence sequence, Ordinates ordinates, BinaryWriter writer, bool justOne) { if (sequence == null || sequence.Count == 0) { return; } int length = 1; if (!justOne) { length = sequence.Count; writer.Write(length); } bool writeZ = ordinates.HasFlag(Ordinates.Z); bool writeM = ordinates.HasFlag(Ordinates.M); for (int i = 0; i < length; i++) { writer.Write(sequence.GetX(i)); writer.Write(sequence.GetY(i)); if (writeZ) { writer.Write(sequence.GetZ(i)); } if (writeM) { writer.Write(sequence.GetM(i)); } } }
/// <inheritdoc /> public void Filter(CoordinateSequence seq) { for (int i = 0; i < seq.Count; i++) { if (_checkOrdinateFlags.HasFlag(Ordinates.Z) && !_outputOrdinates.HasFlag(Ordinates.Z)) { if (!double.IsNaN(seq.GetZ(i))) { _outputOrdinates |= Ordinates.Z; } } if (_checkOrdinateFlags.HasFlag(Ordinates.M) && !_outputOrdinates.HasFlag(Ordinates.M)) { if (!double.IsNaN(seq.GetM(i))) { _outputOrdinates |= Ordinates.M; if (_alwaysEmitZWithM) { _outputOrdinates |= Ordinates.Z; } } } } }
/// <summary> /// Write the <paramref name="ordinates"/> of the <paramref name="sequence"/> using the provided <paramref name="writer"/> /// </summary> /// <param name="sequence">The sequence</param> /// <param name="writer">The writer</param> /// <param name="ordinates">The ordinates, <see cref="Ordinates.X"/> and <see cref="Ordinates.Y"/> are written in any case.</param> protected void WriteCoordinates(CoordinateSequence sequence, BinaryWriter writer, Ordinates ordinates) { for (int i = 0; i < sequence.Count; i++) { writer.Write(sequence.GetX(i)); writer.Write(sequence.GetY(i)); } if ((ordinates & Ordinates.Z) == Ordinates.Z) { WriteInterval(sequence, Ordinate.Z, writer); for (int i = 0, cnt = sequence.Count; i < cnt; i++) { writer.Write(sequence.GetZ(i)); } } if ((ordinates & Ordinates.M) == Ordinates.M) { WriteInterval(sequence, Ordinate.M, writer); for (int i = 0, cnt = sequence.Count; i < cnt; i++) { double val = sequence.GetM(i); if (double.IsNaN(val)) { val = ShapeFileConstants.NoDataValue; } writer.Write(val); } } }
///<summary> /// Copies a coordinate of a <see cref="CoordinateSequence"/> to another <see cref="CoordinateSequence"/>. /// The sequences may contain different <see cref="Ordinates"/>; in this case only the common ordinates 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> protected static void CopyCoord(CoordinateSequence src, int srcPos, CoordinateSequence dest, int destPos) { dest.SetX(destPos, src.GetX(srcPos)); dest.SetY(destPos, src.GetY(srcPos)); if (src.HasZ && dest.HasZ) { dest.SetZ(destPos, src.GetZ(srcPos)); } if (src.HasM && dest.HasM) { dest.SetM(destPos, src.GetM(srcPos)); } }
protected bool IsAllCoordsEqual(CoordinateSequence 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, 0)) { return(false); } if (coord.Y != seq.GetOrdinate(i, 1)) { return(false); } if (seq.HasZ) { if (coord.Z != seq.GetZ(i)) { return(false); } } if (seq.HasM) { if (coord.M != seq.GetM(i)) { return(false); } } if (seq.Dimension > 2) { if (coord[2] != seq.GetOrdinate(i, 2)) { return(false); } } if (seq.Dimension > 3) { if (coord[3] != seq.GetOrdinate(i, 3)) { return(false); } } } return(true); }
/// <summary> /// Creates a sequence based on the given coordinate sequence. /// </summary> /// <param name="coordSeq">The coordinate sequence.</param> /// <param name="ordinates">The ordinates to copy</param> public DotSpatialAffineCoordinateSequence(CoordinateSequence coordSeq, Ordinates ordinates) : base(coordSeq?.Count ?? 0, OrdinatesUtility.OrdinatesToDimension(ordinates & Ordinates.XYZM), OrdinatesUtility.OrdinatesToMeasures(ordinates & Ordinates.XYZM)) { if (coordSeq is DotSpatialAffineCoordinateSequence dsCoordSeq) { _xy = (double[])dsCoordSeq._xy.Clone(); if (HasZ) { _z = ((double[])dsCoordSeq._z?.Clone()) ?? NullOrdinateArray(Count); } if (HasM) { _m = ((double[])dsCoordSeq._m?.Clone()) ?? NullOrdinateArray(Count); } } else { _xy = new double[2 * Count]; if (HasZ) { _z = new double[Count]; } if (HasM) { _m = new double[Count]; } var xy = MemoryMarshal.Cast <double, XYStruct>(_xy); for (int i = 0; i < xy.Length; i++) { xy[i].X = coordSeq.GetX(i); xy[i].Y = coordSeq.GetY(i); if (_z != null) { _z[i] = coordSeq.GetZ(i); } if (_m != null) { _m[i] = coordSeq.GetM(i); } } } }
protected static void WriteCoords(CoordinateSequence points, BinaryWriter file, List <double> zList, List <double> mList) { for (int i = 0; i < points.Count; i++) { file.Write(points.GetX(i)); file.Write(points.GetY(i)); zList?.Add(points.HasZ ? points.GetZ(i) : 0); if (!(mList is null)) { double m = points.GetM(i); if (m.Equals(Coordinate.NullOrdinate)) { m = NoDataValue; } mList.Add(m); } } }
/// <summary> /// Write a <see cref="CoordinateSequence"/>. /// </summary> /// <param name="sequence">The coordinate sequence to write</param> /// <param name="emitSize">A flag indicating if the size of <paramref name="sequence"/> should be written, too.</param> /// <param name="writer">The writer.</param> protected void Write(CoordinateSequence sequence, bool emitSize, BinaryWriter writer) { if (emitSize) { writer.Write(sequence.Count); } // zm-values if not provided by sequence double ordinateZ = Coordinate.NullOrdinate; double ordinateM = Coordinate.NullOrdinate; // test if zm-values are provided by sequence bool getZ = sequence.HasZ; bool getM = sequence.HasM; // test if zm-values should be emitted bool writeZ = (HandleOrdinates & Ordinates.Z) == Ordinates.Z; bool writeM = (HandleOrdinates & Ordinates.M) == Ordinates.M; for (int index = 0; index < sequence.Count; index++) { writer.Write(sequence.GetOrdinate(index, 0)); writer.Write(sequence.GetOrdinate(index, 1)); if (writeZ) { if (getZ) { ordinateZ = sequence.GetZ(index); } writer.Write(ordinateZ); } if (writeM) { if (getM) { ordinateM = sequence.GetM(index); } writer.Write(ordinateM); } } }
private static Ordinates CheckOrdinates(CoordinateSequence sequence) { if (sequence == null || sequence.Count == 0) { return(Ordinates.None); } var result = Ordinates.XY; if (sequence.HasZ && !double.IsNaN(sequence.GetZ(0))) { result |= Ordinates.Z; } if (sequence.HasM && !double.IsNaN(sequence.GetM(0))) { result |= Ordinates.M; } return(result); }
/// <summary> /// Tests for equality using all supported accessors, /// to provides test coverage for them. /// </summary> /// <param name="seq"></param> /// <param name="coords"></param> /// <returns></returns> protected bool IsEqual(CoordinateSequence seq, Coordinate[] coords) { if (seq.Count != coords.Length) { return(false); } // carefully get coordinate of the same type as the sequence var p = seq.CreateCoordinate(); for (int i = 0; i < seq.Count; i++) { if (!coords[i].Equals(seq.GetCoordinate(i))) { return(false); } // Ordinate named getters if (!coords[i].X.Equals(seq.GetX(i))) { return(false); } if (!coords[i].Y.Equals(seq.GetY(i))) { return(false); } if (seq.HasZ) { if (!coords[i].Z.Equals(seq.GetZ(i))) { return(false); } } if (seq.HasM) { if (!coords[i].M.Equals(seq.GetM(i))) { return(false); } } // Ordinate indexed getters if (!coords[i].X.Equals(seq.GetOrdinate(i, 0))) { return(false); } if (!coords[i].Y.Equals(seq.GetOrdinate(i, 1))) { return(false); } if (seq.Dimension > 2) { if (!coords[i][2].Equals(seq.GetOrdinate(i, 2))) { return(false); } } if (seq.Dimension > 3) { if (!coords[i][3].Equals(seq.GetOrdinate(i, 3))) { return(false); } } // Coordinate getter seq.GetCoordinate(i, p); if (!coords[i].X.Equals(p.X)) { return(false); } if (!coords[i].Y.Equals(p.Y)) { return(false); } if (seq.HasZ) { if (!coords[i].Z.Equals(p.Z)) { return(false); } } if (seq.HasM) { if (!coords[i].M.Equals(p.M)) { return(false); } } } return(true); }