/// <summary> /// Method to read the coordinates block /// </summary> /// <param name="reader">The reader</param> /// <param name="numPoints">The total number of points to read</param> /// <param name="markers">The markers</param> /// <param name="ordinates">The ordinates to read</param> /// <param name="buffer">The buffer to add the coordinates to.</param> private static void ReadCoordinates(BinaryReader reader, int numPoints, int[] markers, Ordinates ordinates, CoordinateBuffer buffer) { var offset = buffer.Count; var j = 0; // Add x- and y-ordinates for (var i = 0; i < numPoints; i++) { //Read x- and y- ordinates buffer.AddCoordinate(reader.ReadDouble(), reader.ReadDouble()); //Check if we have reached a marker if (i != markers[j]) { continue; } //Add a marker buffer.AddMarker(); j++; } // are there any z-ordinates if ((ordinates & Ordinates.Z) == Ordinates.Z) { //Read zInterval /*var zInterval = */ ReadInterval(reader); //Set the z-values for (var i = 0; i < numPoints; i++) { buffer.SetZ(offset + i, reader.ReadDouble()); } } if ((ordinates & Ordinates.M) == Ordinates.M) { //Read m-interval /*var mInterval = */ ReadInterval(reader); //Set the m-values for (var i = 0; i < numPoints; i++) { buffer.SetZ(offset + i, reader.ReadDouble()); } } }
/* * protected static double[] ReadDoubles(BigEndianBinaryReader reader, int count) * { * var result = new double[count]; * for (var i = 0; i < count; i++) * result[i] = reader.ReadDouble(); * return result; * } */ /// <summary> /// Get the z values and populate each one of them in Coordinate.Z /// If there are M values, return an array with those. /// </summary> /// <param name="file">The reader</param> /// <param name="totalRecordLength">Total number of bytes in this record</param> /// <param name="currentlyReadBytes">How many bytes are read from this record</param> /// <param name="buffer">The coordinate buffer</param> /// <param name="skippedList">A list of indices which have not been added to the buffer</param> protected void GetZMValues(BigEndianBinaryReader file, int totalRecordLength, ref int currentlyReadBytes, CoordinateBuffer buffer, HashSet <int> skippedList = null) { int numPoints = buffer.Capacity; if (HasZValue()) { boundingBox[boundingBoxIndex++] = ReadDouble(file, totalRecordLength, ref currentlyReadBytes); boundingBox[boundingBoxIndex++] = ReadDouble(file, totalRecordLength, ref currentlyReadBytes); int numSkipped = 0; for (int i = 0; i < numPoints; i++) { double z = ReadDouble(file, totalRecordLength, ref currentlyReadBytes); if (skippedList?.Contains(i) != true) { buffer.SetZ(i - numSkipped, z); } else { numSkipped++; } } } // Trond: Note that M value is always optional per the shapefile spec. So we need to test total read record bytes // v.s. read bytes to see if we have them or not // Also: If we have Z we might have M. Per shapefile defn. if ((HasMValue() || HasZValue()) && currentlyReadBytes < totalRecordLength) { boundingBox[boundingBoxIndex++] = ReadDouble(file, totalRecordLength, ref currentlyReadBytes); boundingBox[boundingBoxIndex++] = ReadDouble(file, totalRecordLength, ref currentlyReadBytes); int numSkipped = 0; for (int i = 0; i < numPoints; i++) { double m = ReadDouble(file, totalRecordLength, ref currentlyReadBytes); if (skippedList?.Contains(i) != true) { buffer.SetM(i - numSkipped, m); } else { numSkipped++; } } } if (currentlyReadBytes < totalRecordLength) { int remaining = totalRecordLength - currentlyReadBytes; file.ReadBytes(remaining * 2); } }
/// <summary> /// Method to read the coordinates block /// </summary> /// <param name="reader">The reader</param> /// <param name="numPoints">The total number of points to read</param> /// <param name="markers">The markers</param> /// <param name="ordinates">The ordinates to read</param> /// <param name="buffer">The buffer to add the coordinates to.</param> private static void ReadCoordinates(BinaryReader reader, int numPoints, int[] markers, Ordinates ordinates, CoordinateBuffer buffer) { var offset = buffer.Count; var j = 0; // Add x- and y-ordinates for (var i = 0; i < numPoints; i++) { //Read x- and y- ordinates buffer.AddCoordinate(reader.ReadDouble(), reader.ReadDouble()); //Check if we have reached a marker if (i != markers[j]) continue; //Add a marker buffer.AddMarker(); j++; } // are there any z-ordinates if ((ordinates & Ordinates.Z) == Ordinates.Z) { //Read zInterval /*var zInterval = */ ReadInterval(reader); //Set the z-values for (var i = 0; i < numPoints; i++) buffer.SetZ(offset + i, reader.ReadDouble()); } if ((ordinates & Ordinates.M) == Ordinates.M) { //Read m-interval /*var mInterval = */ ReadInterval(reader); //Set the m-values for (var i = 0; i < numPoints; i++) buffer.SetZ(offset + i, reader.ReadDouble()); } }