public void Filter(CoordinateSequence seq, int i) { var(x, y, z) = _mathTransform.Transform(seq.GetX(i), seq.GetY(i), seq.GetZ(i)); seq.SetX(i, x); seq.SetY(i, y); seq.SetZ(i, z); }
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)); } } }
/// <summary> /// Generates the WKT for a N-point <c>LineString</c> specified by a <see cref="CoordinateSequence"/>. /// </summary> /// <param name="seq">The sequence to write.</param> /// <returns>The WKT</returns> public static string ToLineString(CoordinateSequence seq) { // legacy note: JTS's version never checks Z or M, so the things that call this aren't // expecting to see them. the "actual" code to write lines handles Z / M just fine. var buf = new StringBuilder(); buf.Append("LINESTRING"); if (seq.Count == 0) { buf.Append(" EMPTY"); } else { buf.Append("("); for (int i = 0; i < seq.Count; i++) { if (i > 0) { buf.Append(", "); } buf.Append(Format(seq.GetX(i), seq.GetY(i))); } buf.Append(")"); } return(buf.ToString()); }
/// <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); } } }
public void Filter(CoordinateSequence sequence) { for (int i = 0; i < sequence.Count; i++) { UpdateScaleMax(sequence.GetX(i)); UpdateScaleMax(sequence.GetY(i)); } }
public void Filter(CoordinateSequence seq, int i) { var x = seq.GetX(i); var y = seq.GetY(i); var z = seq.GetZ(i); _transform.Transform(ref x, ref y, ref z); seq.SetX(i, x); seq.SetY(i, y); seq.SetZ(i, z); }
public static int GetHashCode(this CoordinateSequence sequence, int baseValue, Func <int, int> operation) { if (sequence != null && sequence.Count > 0) { for (int i = 0; i < sequence.Count; i++) { baseValue = operation(baseValue) + sequence.GetX(i).GetHashCode(); } } return(baseValue); }
///<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)); } }
private void WriteCoordinateSequence(Utf8JsonWriter writer, CoordinateSequence sequence, JsonSerializerOptions options, bool multiple = true, OrientationIndex orientation = OrientationIndex.None) { //writer.WritePropertyName("coordinates"); if (sequence == null) { writer.WriteNullValue(); return; } if (multiple) { writer.WriteStartArray(); if (orientation == OrientationIndex.Clockwise && Orientation.IsCCW(sequence) || orientation == OrientationIndex.CounterClockwise && !Orientation.IsCCW(sequence)) { CoordinateSequences.Reverse(sequence); } } bool hasZ = sequence.HasZ; for (int i = 0; i < sequence.Count; i++) { writer.WriteStartArray(); writer.WriteNumberValue(sequence.GetX(i)); writer.WriteNumberValue(sequence.GetY(i)); if (hasZ) { double z = sequence.GetZ(i); if (!double.IsNaN(z)) { writer.WriteNumberValue(sequence.GetZ(i)); } } writer.WriteEndArray(); if (!multiple) { break; } } if (multiple) { writer.WriteEndArray(); } }
/// <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); } } } }
/// <summary> /// /// </summary> /// <param name="coordinates"></param> /// <param name="writer"></param> protected void WriteCoordinates(CoordinateSequence coordinates, XmlWriter writer) { writer.WriteStartElement(GMLElements.gmlPrefix, _gmlVersion == GMLVersion.Two ? "coordinates" : "posList", GMLElements.gmlNS); var sb = new StringBuilder(); string coordsFormatter = _gmlVersion == GMLVersion.Two ? "{0},{1} " : "{0} {1} "; for (int i = 0, cnt = coordinates.Count; i < cnt; i++) { sb.AppendFormat(NumberFormatter, coordsFormatter, coordinates.GetX(i), coordinates.GetY(i)); } // remove the trailing space. if (sb.Length > 0) { --sb.Length; } writer.WriteString($"{sb}"); writer.WriteEndElement(); }
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); } } }
private void WriteRing(StringBuilder sb, LineString component) { if (component is ICurvedGeometry <LineString> curved) { sb.Append(curved.ToCurvedText()); } else { sb.Append("("); CoordinateSequence cs = component.CoordinateSequence; for (int i = 0; i < cs.Count; ++i) { sb.Append(cs.GetX(i) + " " + cs.GetY(i)); //TODO: ZM? if (i < cs.Count - 1) { sb.Append(", "); } } sb.Append(")"); } }
public void Filter(CoordinateSequence seq, int i) { seq.SetZ(i, _XYToElevation(seq.GetX(i), seq.GetY(i))); }
/// <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); }