private static ICoordinateSequence ReadXYZM(byte[] buffer, ref int offset, int number, GaiaImport import, ICoordinateSequenceFactory factory, IPrecisionModel precisionModel) { var ordinateValues = import.GetDoubles(buffer, ref offset, number * 4); var ret = factory.Create(number, import.HandleOrdinates); var handleZ = (ret.Ordinates & Ordinates.Z) == Ordinates.Z; var handleM = (ret.Ordinates & Ordinates.M) == Ordinates.M; var j = 0; for (var i = 0; i < number; i++) { ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(ordinateValues[j++])); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(ordinateValues[j++])); if (handleZ) { ret.SetOrdinate(i, Ordinate.Z, precisionModel.MakePrecise(ordinateValues[j])); } j++; if (handleM) { ret.SetOrdinate(i, Ordinate.M, precisionModel.MakePrecise(ordinateValues[j])); } j++; } return(ret); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="totalRecordLength">Total length of the record we are about to read</param> /// <param name="factory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory) { int totalRead = 0; ShapeGeometryType type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead); //type = (ShapeGeometryType) EnumUtility.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) return factory.CreatePoint((Coordinate)null); if (type != ShapeType) throw new ShapefileException(string.Format("Encountered a '{0}' instead of a '{1}'", type, ShapeType)); CoordinateBuffer buffer = new CoordinateBuffer(1, NoDataBorderValue, true); IPrecisionModel precisionModel = factory.PrecisionModel; double x = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); double y = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); double? z = null, m = null; // Trond Benum: Let's read optional Z and M values if (HasZValue() && totalRead < totalRecordLength) z = ReadDouble(file, totalRecordLength, ref totalRead); if ((HasMValue() || HasZValue()) && (totalRead < totalRecordLength)) m = ReadDouble(file, totalRecordLength, ref totalRead); buffer.AddCoordinate(x, y, z, m); return factory.CreatePoint(buffer.ToSequence(factory.CoordinateSequenceFactory)); }
private static ICoordinateSequence ReadXY(byte[] buffer, ref int offset, int number, GaiaImport import, ICoordinateSequenceFactory factory, IPrecisionModel precisionModel) { var ordinateValues = import.GetDoubles(buffer, ref offset, number * 2); var ret = factory.Create(number, Ordinates.XY); var j = 0; for (var i = 0; i < number; i++) { ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(ordinateValues[j++])); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(ordinateValues[j++])); } return(ret); }
/// <summary> /// Get Envelope in external coordinates. /// </summary> /// <param name="precisionModel">The precision model to use</param> /// <param name="envelope">The envelope to get</param> /// <returns></returns> public static Envelope GetEnvelopeExternal(IPrecisionModel precisionModel, Envelope envelope) { // Get envelope in external coordinates var min = new Coordinate(envelope.MinX, envelope.MinY); precisionModel.MakePrecise(min); var max = new Coordinate(envelope.MaxX, envelope.MaxY); precisionModel.MakePrecise(max); var bounds = new Envelope(min.X, max.X, min.Y, max.Y); return(bounds); //return GetEnvelopeExternal(envelope); }
private double GetRandOrdinate() { double randNum = GetRand(); double ord = _precisionModel.MakePrecise(randNum * GridWidth); return(ord); }
/// <summary> /// /// </summary> /// <param name="tokens"></param> /// <param name="skipExtraParenthesis"></param> /// <returns></returns> private Coordinate GetPreciseCoordinate(IEnumerator <Token> tokens, Boolean skipExtraParenthesis) { var coord = new Coordinate(); var extraParenthesisFound = false; if (skipExtraParenthesis) { extraParenthesisFound = IsStringValueNext(tokens, "("); if (extraParenthesisFound) { tokens.MoveNext(); //_index++; } } coord.X = GetNextNumber(tokens); coord.Y = GetNextNumber(tokens); if (IsNumberNext(tokens)) { coord.Z = GetNextNumber(tokens); } if (skipExtraParenthesis && extraParenthesisFound && IsStringValueNext(tokens, ")")) { tokens.MoveNext(); //_index++; } _precisionModel.MakePrecise(coord); return(coord); }
/// <summary> /// /// </summary> /// <param name="tokens"></param> /// <returns></returns> private ICoordinate GetPreciseCoordinate(IList tokens, Boolean skipExtraParenthesis) { ICoordinate coord = new Coordinate(); Boolean extraParenthesisFound = false; if (skipExtraParenthesis) { extraParenthesisFound = IsStringValueNext(tokens, "("); if (extraParenthesisFound) { index++; } } coord.X = GetNextNumber(tokens); coord.Y = GetNextNumber(tokens); if (IsNumberNext(tokens)) { coord.Z = GetNextNumber(tokens); } if (skipExtraParenthesis && extraParenthesisFound && IsStringValueNext(tokens, ")")) { index++; } precisionModel.MakePrecise(coord); return(coord); }
/// <summary> /// Densifies a coordinate sequence. /// </summary> /// <param name="pts">The coordinate sequence to densify</param> /// <param name="distanceTolerance">The distance tolerance (<see cref="DistanceTolerance"/>)</param> /// <param name="precModel">The precision model to apply on the new coordinates</param> /// <returns>The densified coordinate sequence</returns> private static Coordinate[] DensifyPoints(Coordinate[] pts, double distanceTolerance, IPrecisionModel precModel) { var seg = new LineSegment(); var coordList = new CoordinateList(); for (int i = 0; i < pts.Length - 1; i++) { seg.P0 = pts[i]; seg.P1 = pts[i + 1]; coordList.Add(seg.P0, false); double len = seg.Length; int densifiedSegCount = (int)(len / distanceTolerance) + 1; if (densifiedSegCount > 1) { double densifiedSegLen = len / densifiedSegCount; for (int j = 1; j < densifiedSegCount; j++) { double segFract = (j * densifiedSegLen) / len; var p = seg.PointAlong(segFract); precModel.MakePrecise(p); coordList.Add(p, false); } } } coordList.Add(pts[pts.Length - 1], false); return(coordList.ToCoordinateArray()); }
/// <summary> /// Densifies a coordinate sequence. /// </summary> /// <param name="pts">The coordinate sequence to densify</param> /// <param name="distanceTolerance">The distance tolerance (<see cref="DistanceTolerance"/>)</param> /// <param name="precModel">The precision model to apply on the new coordinates</param> /// <returns>The densified coordinate sequence</returns> private static Coordinate[] DensifyPoints(Coordinate[] pts, double distanceTolerance, IPrecisionModel precModel) { var seg = new LineSegment(); var coordList = new CoordinateList(); for (int i = 0; i < pts.Length - 1; i++) { seg.P0 = pts[i]; seg.P1 = pts[i + 1]; coordList.Add(seg.P0, false); double len = seg.Length; int densifiedSegCount = (int) (len/distanceTolerance) + 1; if (densifiedSegCount > 1) { double densifiedSegLen = len/densifiedSegCount; for (int j = 1; j < densifiedSegCount; j++) { double segFract = (j*densifiedSegLen)/len; var p = seg.PointAlong(segFract); precModel.MakePrecise(p); coordList.Add(p, false); } } } coordList.Add(pts[pts.Length - 1], false); return coordList.ToCoordinateArray(); }
/// <summary> /// Writes a single coordinate to JSON /// </summary> /// <param name="writer">The writer</param> /// <param name="coordinate">The coordinate</param> /// <param name="serializer">The serializer</param> protected void WriteJsonCoordinate(JsonWriter writer, Coordinate coordinate, JsonSerializer serializer) { writer.WriteStartArray(); double value = _precisionModel.MakePrecise(coordinate.X); writer.WriteValue(value); value = _precisionModel.MakePrecise(coordinate.Y); writer.WriteValue(value); if (_dimension > 2 && !double.IsNaN(coordinate.Z)) { writer.WriteValue(coordinate.Z); } writer.WriteEndArray(); }
public IGeometry ToGeometry(IGeometryFactory geomFactory) { if (IsNull) { return(geomFactory.CreatePoint((ICoordinateSequence)null)); } Coordinate px00 = new Coordinate(_minX, _minA - _minX); Coordinate px01 = new Coordinate(_minX, _minX - _minB); Coordinate px10 = new Coordinate(_maxX, _maxX - _maxB); Coordinate px11 = new Coordinate(_maxX, _maxA - _maxX); Coordinate py00 = new Coordinate(_minA - _minY, _minY); Coordinate py01 = new Coordinate(_minY + _maxB, _minY); Coordinate py10 = new Coordinate(_maxY + _minB, _maxY); Coordinate py11 = new Coordinate(_maxA - _maxY, _maxY); IPrecisionModel pm = geomFactory.PrecisionModel; pm.MakePrecise(px00); pm.MakePrecise(px01); pm.MakePrecise(px10); pm.MakePrecise(px11); pm.MakePrecise(py00); pm.MakePrecise(py01); pm.MakePrecise(py10); pm.MakePrecise(py11); CoordinateList coordList = new CoordinateList(); coordList.Add(px00, false); coordList.Add(px01, false); coordList.Add(py10, false); coordList.Add(py11, false); coordList.Add(px11, false); coordList.Add(px10, false); coordList.Add(py01, false); coordList.Add(py00, false); if (coordList.Count == 1) { return(geomFactory.CreatePoint(px00)); } Coordinate[] pts; if (coordList.Count == 2) { pts = coordList.ToCoordinateArray(); return(geomFactory.CreateLineString(pts)); } // must be a polygon, so add closing point coordList.Add(px00, false); pts = coordList.ToCoordinateArray(); return(geomFactory.CreatePolygon(geomFactory.CreateLinearRing(pts), null)); }
public override Coordinate[] Edit(Coordinate[] coordinates, IGeometry geom) { if (coordinates.Length == 0) { return(null); } var reducedCoords = new Coordinate[coordinates.Length]; // copy coordinates and reduce for (int i = 0; i < coordinates.Length; i++) { var coord = new Coordinate(coordinates[i]); _targetPrecModel.MakePrecise(coord); reducedCoords[i] = coord; } // remove repeated points, to simplify returned geometry as much as possible var noRepeatedCoordList = new CoordinateList(reducedCoords, false); var noRepeatedCoords = noRepeatedCoordList.ToCoordinateArray(); /** * Check to see if the removal of repeated points collapsed the coordinate * List to an invalid length for the type of the parent geometry. It is not * necessary to check for Point collapses, since the coordinate list can * never collapse to less than one point. If the length is invalid, return * the full-length coordinate array first computed, or null if collapses are * being removed. (This may create an invalid geometry - the client must * handle this.) */ int minLength = 0; if (geom is ILineString) { minLength = 2; } if (geom is ILinearRing) { minLength = LinearRing.MinimumValidSize; } var collapsedCoords = reducedCoords; if (_removeCollapsed) { collapsedCoords = null; } // return null or orginal length coordinate array if (noRepeatedCoords.Length < minLength) { return(collapsedCoords); } // ok to return shorter coordinate array return(noRepeatedCoords); }
private static void PreciseCoordinateTester(IPrecisionModel pm, double x1, double y1, double x2, double y2) { var p = new Coordinate(x1, y1); pm.MakePrecise(p); var pPrecise = new Coordinate(x2, y2); Assert.IsTrue(p.Equals2D(pPrecise), "Expected {0}, but got {1}", pPrecise, p); }
private static double RandomOrdinate(Ordinate o, IPrecisionModel pm) { switch (o) { case Ordinate.X: return(pm.MakePrecise(-180 + 360 * Rnd.NextDouble())); case Ordinate.Y: return(pm.MakePrecise(-90 + 180 * Rnd.NextDouble())); case Ordinate.Z: return(200 * Rnd.NextDouble()); case Ordinate.M: return(200 + 200 * Rnd.NextDouble()); default: throw new NotSupportedException(); } }
private static ICoordinateSequence ReadCompressedXY(byte[] buffer, ref int offset, int number, GaiaImport import, ICoordinateSequenceFactory factory, IPrecisionModel precisionModel) { var startOrdinateValues = import.GetDoubles(buffer, ref offset, 2); var ret = factory.Create(number, import.HandleOrdinates); var x = startOrdinateValues[0]; var y = startOrdinateValues[1]; ret.SetOrdinate(0, Ordinate.X, precisionModel.MakePrecise(x)); ret.SetOrdinate(0, Ordinate.Y, precisionModel.MakePrecise(y)); if (number == 1) { return(ret); } var ordinateValues = import.GetSingles(buffer, ref offset, (number - 2) * 2); var j = 0; int i; for (i = 1; i < number - 1; i++) { x = x + ordinateValues[j++]; y = y + ordinateValues[j++]; ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(x)); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(y)); } startOrdinateValues = import.GetDoubles(buffer, ref offset, 2); ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(startOrdinateValues[0])); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(startOrdinateValues[1])); return(ret); }
/// <summary> /// Function to add a point /// </summary> /// <remarks> /// The point is only added if <see cref="IsDuplicate(Coordinate)"/> evaluates to false. /// </remarks> /// <param name="pt">The point to add.</param> public void AddPt(Coordinate pt) { var bufPt = new Coordinate(pt); _precisionModel.MakePrecise(bufPt); // don't add duplicate (or near-duplicate) points if (IsDuplicate(bufPt)) { return; } _ptList.Add(bufPt); //System.out.println(bufPt); }
/// <summary> /// /// </summary> /// <param name="tokens"></param> /// <returns></returns> private ICoordinate GetPreciseCoordinate(IList tokens) { ICoordinate coord = new Coordinate(); coord.X = GetNextNumber(tokens); coord.Y = GetNextNumber(tokens); if (IsNumberNext(tokens)) { coord.Z = GetNextNumber(tokens); } precisionModel.MakePrecise(coord); return(coord); }
public void AddPt(Coordinate pt) { var bufPt = new Coordinate(pt); _precisionModel.MakePrecise(bufPt); // don't add duplicate (or near-duplicate) points if (IsRedundant(bufPt)) { return; } _ptList.Add(bufPt); //Console.WriteLine(bufPt); }
private static ICoordinateSequence ReadCompressedXYZM(byte[] buffer, ref int offset, int number, GaiaImport import, ICoordinateSequenceFactory factory, IPrecisionModel precisionModel) { var startOrdinateValues = import.GetDoubles(buffer, ref offset, 4); var ret = factory.Create(number, Ordinates.XYM); var handleZ = (ret.Ordinates & Ordinates.Z) == Ordinates.Z; var handleM = (ret.Ordinates & Ordinates.M) == Ordinates.M; var x = startOrdinateValues[0]; ret.SetOrdinate(0, Ordinate.X, precisionModel.MakePrecise(x)); var y = startOrdinateValues[1]; ret.SetOrdinate(0, Ordinate.Y, precisionModel.MakePrecise(y)); var z = handleZ ? startOrdinateValues[2] : Coordinate.NullOrdinate; ret.SetOrdinate(0, Ordinate.Z, z); var m = handleM ? startOrdinateValues[3] : Coordinate.NullOrdinate; ret.SetOrdinate(0, Ordinate.M, m); if (number == 1) { return(ret); } var ordinateValues = import.GetSingles(buffer, ref offset, (number - 2) * 4); var j = 0; int i; for (i = 1; i < number - 1; i++) { x += ordinateValues[j++]; ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(x)); y += ordinateValues[j++]; ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(y)); if (handleZ) { z += ordinateValues[j++]; } ret.SetOrdinate(i, Ordinate.Z, z); if (handleM) { m += ordinateValues[j++]; } ret.SetOrdinate(i, Ordinate.M, m); } startOrdinateValues = import.GetDoubles(buffer, ref offset, 4); ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(startOrdinateValues[0])); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(startOrdinateValues[1])); z = handleZ ? startOrdinateValues[2] : Coordinate.NullOrdinate; ret.SetOrdinate(i, Ordinate.Z, z); m = handleM ? startOrdinateValues[3] : Coordinate.NullOrdinate; ret.SetOrdinate(i, Ordinate.M, m); return(ret); }
/// <summary> /// Reads a <see cref="ICoordinateSequence"/> from the stream /// </summary> /// <param name="reader">The binary reader</param> /// <param name="factory">The geometry factory to use for geometry creation.</param> /// <param name="precisionModel">The precision model used to make x- and y-ordinates precise.</param> /// <param name="numPoints">The number of points in the coordinate sequence.</param> /// <param name="ordinates">The ordinates to read. <see cref="Ordinates.XY"/> are always read.</param> /// <returns>The coordinate sequence</returns> protected ICoordinateSequence ReadCoordinateSequence(BinaryReader reader, ICoordinateSequenceFactory factory, IPrecisionModel precisionModel, int numPoints, Ordinates ordinates) { var sequence = factory.Create(numPoints, HandleOrdinates); var ordinateZ = Coordinate.NullOrdinate; var ordinateM = Coordinate.NullOrdinate; var getZ = (ordinates & Ordinates.Z) == Ordinates.Z; var getM = (ordinates & Ordinates.M) == Ordinates.M; var handleZ = (HandleOrdinates & Ordinates.Z) == Ordinates.Z; var handleM = (HandleOrdinates & Ordinates.M) == Ordinates.M; for (var i = 0; i < numPoints; i++) { sequence.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(reader.ReadDouble())); sequence.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(reader.ReadDouble())); if (getZ) { ordinateZ = reader.ReadDouble(); } if (handleZ) { sequence.SetOrdinate(i, Ordinate.Z, ordinateZ); } if (getM) { ordinateM = reader.ReadDouble(); } if (handleM) { sequence.SetOrdinate(i, Ordinate.M, ordinateM); } } return(sequence); }
/// <summary> /// /// </summary> /// <param name="pt"></param> private void AddPt(ICoordinate pt) { ICoordinate bufPt = new Coordinate(pt); precisionModel.MakePrecise(bufPt); // don't add duplicate points if (ptList.Count >= 1) { var lastPt = (ICoordinate)this.ptList[this.ptList.Count - 1]; if (lastPt != null && (bufPt.Distance(lastPt) < 1e-8)) { // if (lastPt != null && bufPt.Equals(lastPt)) return; } } ptList.Add(bufPt); }
/// <summary> /// /// </summary> /// <param name="pt"></param> private void AddPt(ICoordinate pt) { ICoordinate bufPt = new Coordinate(pt); precisionModel.MakePrecise(bufPt); // don't add duplicate points ICoordinate lastPt = null; if (ptList.Count >= 1) { lastPt = (ICoordinate)ptList[ptList.Count - 1]; } if (lastPt != null && bufPt.Equals(lastPt)) { return; } ptList.Add(bufPt); }
private static Coordinate[] Round(ICoordinateSequence seq, IPrecisionModel pm) { if (seq.Count == 0) { return(new Coordinate[0]); } CoordinateList coordList = new CoordinateList(); // copy coordinates and reduce for (int i = 0; i < seq.Count; i++) { var coord = new Coordinate( seq.GetOrdinate(i, Ordinate.X), seq.GetOrdinate(i, Ordinate.Y)); pm.MakePrecise(coord); coordList.Add(coord, false); } Coordinate[] coords = coordList.ToCoordinateArray(); //TODO: what if seq is too short? return(coords); }
private static double RandomOrdinate(Ordinate o, IPrecisionModel pm) { switch (o) { case Ordinate.X: return pm.MakePrecise(-180 + 360 * Rnd.NextDouble()); case Ordinate.Y: return pm.MakePrecise(-90 + 180 * Rnd.NextDouble()); case Ordinate.Z: return 200 * Rnd.NextDouble(); case Ordinate.M: return 200 + 200 * Rnd.NextDouble(); default: throw new NotSupportedException(); } }
private static ICoordinateSequence ReadXY(byte[] buffer, ref int offset, int number, GaiaImport import, ICoordinateSequenceFactory factory, IPrecisionModel precisionModel) { var ordinateValues = import.GetDoubles(buffer, ref offset, number * 2); var ret = factory.Create(number, Ordinates.XY); var j = 0; for (var i = 0; i < number; i++) { ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(ordinateValues[j++])); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(ordinateValues[j++])); } return ret; }
static Coordinate[] Round(ICoordinateSequence seq, IPrecisionModel pm) { if (seq.Count == 0) return new Coordinate[0]; CoordinateList coordList = new CoordinateList(); // copy coordinates and reduce for (int i = 0; i < seq.Count; i++) { var coord = new Coordinate( seq.GetOrdinate(i, Ordinate.X), seq.GetOrdinate(i, Ordinate.Y)); pm.MakePrecise(coord); coordList.Add(coord, false); } Coordinate[] coords = coordList.ToCoordinateArray(); //TODO: what if seq is too short? return coords; }
/// <summary> /// Function to read a coordinate sequence. /// </summary> /// <param name="reader">The reader</param> /// <param name="size">The number of ordinates</param> /// <param name="cs">The coordinate system</param> /// <returns>The read coordinate sequence.</returns> protected ICoordinateSequence ReadCoordinateSequence(BinaryReader reader, int size, CoordinateSystem cs) { var sequence = _sequenceFactory.Create(size, ToOrdinates(cs)); for (int i = 0; i < size; i++) { double x = reader.ReadDouble(); double y = reader.ReadDouble(); if (_precisionModel != null) { x = _precisionModel.MakePrecise(x); } if (_precisionModel != null) { y = _precisionModel.MakePrecise(y); } sequence.SetOrdinate(i, Ordinate.X, x); sequence.SetOrdinate(i, Ordinate.Y, y); switch (cs) { case CoordinateSystem.XY: continue; case CoordinateSystem.XYZ: double z = reader.ReadDouble(); if (HandleOrdinate(Ordinate.Z)) { sequence.SetOrdinate(i, Ordinate.Z, z); } break; case CoordinateSystem.XYM: double m = reader.ReadDouble(); if (HandleOrdinate(Ordinate.M)) { sequence.SetOrdinate(i, Ordinate.M, m); } break; case CoordinateSystem.XYZM: z = reader.ReadDouble(); if (HandleOrdinate(Ordinate.Z)) { sequence.SetOrdinate(i, Ordinate.Z, z); } m = reader.ReadDouble(); if (HandleOrdinate(Ordinate.M)) { sequence.SetOrdinate(i, Ordinate.M, m); } break; default: throw new ArgumentException(string.Format("Coordinate system not supported: {0}", cs)); } } return(sequence); }
/// <summary> /// Rounds the Coordinates in the sequence to match the PrecisionModel /// </summary> public void Filter(ICoordinateSequence seq, int i) { seq.SetOrdinate(i, Ordinate.X, _precModel.MakePrecise(seq.GetOrdinate(i, Ordinate.X))); seq.SetOrdinate(i, Ordinate.Y, _precModel.MakePrecise(seq.GetOrdinate(i, Ordinate.Y))); }
private static ICoordinateSequence ReadXYZM(byte[] buffer, ref int offset, int number, GaiaImport import, ICoordinateSequenceFactory factory, IPrecisionModel precisionModel) { var ordinateValues = import.GetDoubles(buffer, ref offset, number * 4); var ret = factory.Create(number, import.HandleOrdinates); var handleZ = (ret.Ordinates & Ordinates.Z) == Ordinates.Z; var handleM = (ret.Ordinates & Ordinates.M) == Ordinates.M; var j = 0; for (var i = 0; i < number; i++) { ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(ordinateValues[j++])); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(ordinateValues[j++])); if (handleZ) ret.SetOrdinate(i, Ordinate.Z, precisionModel.MakePrecise(ordinateValues[j])); j++; if (handleM) ret.SetOrdinate(i, Ordinate.M, precisionModel.MakePrecise(ordinateValues[j])); j++; } return ret; }
private static ICoordinateSequence ReadCompressedXY(byte[] buffer, ref int offset, int number, GaiaImport import, ICoordinateSequenceFactory factory, IPrecisionModel precisionModel) { var startOrdinateValues = import.GetDoubles(buffer, ref offset, 2); var ret = factory.Create(number, import.HandleOrdinates); var x = startOrdinateValues[0]; var y = startOrdinateValues[1]; ret.SetOrdinate(0, Ordinate.X, precisionModel.MakePrecise(x)); ret.SetOrdinate(0, Ordinate.Y, precisionModel.MakePrecise(y)); if (number == 1) return ret; var ordinateValues = import.GetSingles(buffer, ref offset, (number - 2) * 2); var j = 0; int i; for (i = 1; i < number - 1; i++) { x = x + ordinateValues[j++]; y = y + ordinateValues[j++]; ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(x)); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(y)); } startOrdinateValues = import.GetDoubles(buffer, ref offset, 2); ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(startOrdinateValues[0])); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(startOrdinateValues[1])); return ret; }
/// <summary> /// Get Envelope in external coordinates. /// </summary> /// <param name="precisionModel">The precision model to use</param> /// <param name="envelope">The envelope to get</param> /// <returns></returns> public static Envelope GetEnvelopeExternal(IPrecisionModel precisionModel, Envelope envelope) { // Get envelope in external coordinates var min = new Coordinate(envelope.MinX, envelope.MinY); precisionModel.MakePrecise(min); var max = new Coordinate(envelope.MaxX, envelope.MaxY); precisionModel.MakePrecise(max); var bounds = new Envelope(min.X, max.X, min.Y, max.Y); return bounds; //return GetEnvelopeExternal(envelope); }
private static ICoordinateSequence ReadCompressedXYZM(byte[] buffer, ref int offset, int number, GaiaImport import, ICoordinateSequenceFactory factory, IPrecisionModel precisionModel) { var startOrdinateValues = import.GetDoubles(buffer, ref offset, 4); var ret = factory.Create(number, Ordinates.XYM); var handleZ = (ret.Ordinates & Ordinates.Z) == Ordinates.Z; var handleM = (ret.Ordinates & Ordinates.M) == Ordinates.M; var x = startOrdinateValues[0]; ret.SetOrdinate(0, Ordinate.X, precisionModel.MakePrecise(x)); var y = startOrdinateValues[1]; ret.SetOrdinate(0, Ordinate.Y, precisionModel.MakePrecise(y)); var z = handleZ ? startOrdinateValues[2] : Coordinate.NullOrdinate; ret.SetOrdinate(0, Ordinate.Z, z); var m = handleM ? startOrdinateValues[3] : Coordinate.NullOrdinate; ret.SetOrdinate(0, Ordinate.M, m); if (number == 1) return ret; var ordinateValues = import.GetSingles(buffer, ref offset, (number - 2) * 4); var j = 0; int i; for (i = 1; i < number - 1; i++) { x += ordinateValues[j++]; ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(x)); y += ordinateValues[j++]; ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(y)); if (handleZ) z += ordinateValues[j++]; ret.SetOrdinate(i, Ordinate.Z, z); if (handleM) m += ordinateValues[j++]; ret.SetOrdinate(i, Ordinate.M, m); } startOrdinateValues = import.GetDoubles(buffer, ref offset, 4); ret.SetOrdinate(i, Ordinate.X, precisionModel.MakePrecise(startOrdinateValues[0])); ret.SetOrdinate(i, Ordinate.Y, precisionModel.MakePrecise(startOrdinateValues[1])); z = handleZ ? startOrdinateValues[2] : Coordinate.NullOrdinate; ret.SetOrdinate(i, Ordinate.Z, z); m = handleM ? startOrdinateValues[3] : Coordinate.NullOrdinate; ret.SetOrdinate(i, Ordinate.M, m); return ret; }