private void ReadPolygonM(Byte[] dataStream, int streamPosition) { var pg = new PolygonM(); pg.BoundingBox = new Double[4]; pg.BoundingBox[0] = ReadDoubleLittleEndian(dataStream, streamPosition); pg.BoundingBox[1] = ReadDoubleLittleEndian(dataStream, streamPosition + 8); pg.BoundingBox[2] = ReadDoubleLittleEndian(dataStream, streamPosition + 16); pg.BoundingBox[3] = ReadDoubleLittleEndian(dataStream, streamPosition + 24); var numberOfParts = ReadIntLittleEndian(dataStream, streamPosition + 32); var numberOfPoints = ReadIntLittleEndian(dataStream, streamPosition + 36); pg.Rings = new RingM[numberOfParts]; var parts = new int[numberOfParts]; var pos = streamPosition + 40; // Convert starting indices to ending indices for the geometry. Skip first record. for (var i = 1; i < numberOfParts; i++) { parts[i - 1] = ReadIntLittleEndian(dataStream, pos + (i * 4)) - 1; } // Add the final record as the end of last "part". parts[numberOfParts - 1] = numberOfPoints - 1; pos = pos + 4 * numberOfParts; var z = 0; int lineEndsAt; var rng = new RingM(); var pts = new List<PointM>(); for (var i = 0; i < numberOfPoints; i++) { lineEndsAt = parts[z]; if (i == lineEndsAt) { // End of polygon. Add the last point and wrap up. var p = new PointM(); p.X = ReadDoubleLittleEndian(dataStream, pos + (i * 16)); p.Y = ReadDoubleLittleEndian(dataStream, pos + (i * 16) + 8); pts.Add(p); rng.Points = pts.ToArray(); pts.Clear(); pg.Rings[z] = rng; rng = new RingM(); if (z < numberOfParts - 1) z++; } else { var p = new PointM(); p.X = ReadDoubleLittleEndian(dataStream, pos + (i * 16)); p.Y = ReadDoubleLittleEndian(dataStream, pos + (i * 16) + 8); pts.Add(p); } } pos = pos + numberOfPoints * 16; pg.MMin = ReadDoubleLittleEndian(dataStream, pos); pg.MMax = ReadDoubleLittleEndian(dataStream, pos + 8); var pointIndex = 0; for (var i = 0; i < pg.Rings.Length; i++) { for (var k = 0; k < pg.Rings[i].Points.Length; k++) { pg.Rings[i].Points[k].M = ReadDoubleLittleEndian(dataStream, pos + 16 + (pointIndex * 8)); pointIndex++; } } Shapes.Add(pg); }
private void ReadPolyLineM(Byte[] dataStream, int streamPosition) { var pl = new PolyLineM(); pl.BoundingBox = new Double[4]; pl.BoundingBox[0] = ReadDoubleLittleEndian(dataStream, streamPosition); pl.BoundingBox[1] = ReadDoubleLittleEndian(dataStream, streamPosition + 8); pl.BoundingBox[2] = ReadDoubleLittleEndian(dataStream, streamPosition + 16); pl.BoundingBox[3] = ReadDoubleLittleEndian(dataStream, streamPosition + 24); var numberOfParts = ReadIntLittleEndian(dataStream, streamPosition + 32); var numberOfPoints = ReadIntLittleEndian(dataStream, streamPosition + 36); pl.Lines = new LineM[numberOfParts]; var parts = new int[numberOfParts]; var pos = streamPosition + 40; for (var i = 1; i < numberOfParts; i++) { parts[i - 1] = ReadIntLittleEndian(dataStream, pos + (i * 4)) - 1; } parts[numberOfParts - 1] = numberOfPoints - 1; pos = pos + 4 * numberOfParts; var z = 0; int lineEndsAt; var ln = new LineM(); var pts = new List<PointM>(); for (var i = 0; i < numberOfPoints; i++) { lineEndsAt = parts[z]; if (i == lineEndsAt) { // End of line, add the last point and wrap up var p = new PointM(); p.X = ReadDoubleLittleEndian(dataStream, pos + (i * 16)); p.Y = ReadDoubleLittleEndian(dataStream, pos + (i * 16) + 8); pts.Add(p); ln.Points = pts.ToArray(); pts.Clear(); pl.Lines[z] = ln; ln = new LineM(); if (z < numberOfParts - 1) z++; } else { // Keep adding the points var p = new PointM(); p.X = ReadDoubleLittleEndian(dataStream, pos + (i * 16)); p.Y = ReadDoubleLittleEndian(dataStream, pos + (i * 16) + 8); pts.Add(p); } } pos = pos + numberOfPoints * 16; pl.MMin = ReadDoubleLittleEndian(dataStream, pos); pl.MMax = ReadDoubleLittleEndian(dataStream, pos + 8); var pointIndex = 0; for (var i = 0; i < pl.Lines.Length; i++) { for (var k = 0; k < pl.Lines[i].Points.Length; k++) { pl.Lines[i].Points[k].M = ReadDoubleLittleEndian(dataStream, pos + 16 + (pointIndex * 8)); pointIndex++; } } Shapes.Add(pl); }
private void ReadPointM(Byte[] dataStream, int streamPosition) { var p = new PointM(); p.X = ReadDoubleLittleEndian(dataStream, streamPosition); p.Y = ReadDoubleLittleEndian(dataStream, streamPosition + 8); p.M = ReadDoubleLittleEndian(dataStream, streamPosition + 16); Shapes.Add(p); }