public StCoordinate(decimal val, StCoordType type) { Value = val; Bytes = StCoordinatesSystemHelper.GetBytesFromValue(Value, StParameters.CoordinatesSystem, type); }
private void CalculateBytes() { if (HasM) { throw new NotSupportedException("M not managed yet : Code is written, but not tested"); } var allBytes = new List <byte>(); var allZBytes = new List <byte>(); var allMBytes = new List <byte>(); // The first point will be set normaly List <List <byte> > previousBytesList = StGeometryHelper.GetEncodedValues(StGeometryHelper.RemoveHeader(Points[0].Bytes)); allBytes.AddRange(previousBytesList[0]); // X allBytes.AddRange(previousBytesList[1]); // Y if (HasZ) { allZBytes.AddRange(previousBytesList[2]); } if (HasM) { allMBytes.AddRange(previousBytesList[3]); } // The next point are set with the difference between the current coordinate and the previous one for (int i = 1; i < Points.Count; ++i) { List <List <byte> > bytesList = StGeometryHelper.GetEncodedValues(StGeometryHelper.RemoveHeader(Points[i].Bytes)); byte[] xBytes = StCoordinatesSystemHelper.GetDifferenceFromBytes(bytesList[0].ToArray(), previousBytesList[0].ToArray(), StParameters.CoordinatesSystem, StCoordType.X); allBytes.AddRange(xBytes); byte[] yBytes = StCoordinatesSystemHelper.GetDifferenceFromBytes(bytesList[1].ToArray(), previousBytesList[1].ToArray(), StParameters.CoordinatesSystem, StCoordType.Y); allBytes.AddRange(yBytes); if (HasZ && HasM) { byte[] zBytes = StCoordinatesSystemHelper.GetDifferenceFromBytes(bytesList[2].ToArray(), previousBytesList[2].ToArray(), StParameters.CoordinatesSystem, StCoordType.Z); allZBytes.AddRange(zBytes); byte[] mBytes = StCoordinatesSystemHelper.GetDifferenceFromBytes(bytesList[3].ToArray(), previousBytesList[3].ToArray(), StParameters.CoordinatesSystem, StCoordType.M); allMBytes.AddRange(mBytes); } else if (HasZ) { byte[] zBytes = StCoordinatesSystemHelper.GetDifferenceFromBytes(bytesList[2].ToArray(), previousBytesList[2].ToArray(), StParameters.CoordinatesSystem, StCoordType.Z); allZBytes.AddRange(zBytes); } else if (HasM) { byte[] mBytes = StCoordinatesSystemHelper.GetDifferenceFromBytes(bytesList[2].ToArray(), previousBytesList[3].ToArray(), StParameters.CoordinatesSystem, StCoordType.M); allMBytes.AddRange(mBytes); } previousBytesList = bytesList; } // Add Z et M Bytes to XY ones if (HasZ) { allBytes.AddRange(allZBytes); } if (HasM) { allBytes.AddRange(allMBytes); } // Add reserved bytes List <byte> header = StGeometryHelper.GenerateHeader(this, allBytes); allBytes.InsertRange(0, header); Bytes = allBytes.ToArray(); }
public StCoordinate(byte[] points, StCoordType type) { Bytes = points; Value = StCoordinatesSystemHelper.GetValueFromBytes(Bytes, StParameters.CoordinatesSystem, type); }
private void SetGeometry(List <List <byte> > bytesList) { // Bytes are NOT stored in an intuitive way : X1 Y1 Z1 X2 Y2 Z2 X3 Y3 Z3 // But in a other way : X1 Y1 X2 Y2 X3 Y3 Z1 Z2 Z3 // Ex : LINESTRING Z (0 0 0, 1 1 1) : {128 168 198 186 141 17} {128 239 136 224 159 19} {144 156 1} {144 156 1} {128 168 214 185 7} {144 156 1} if (HasM) { throw new NotSupportedException("M not managed yet : Code is written, but not tested"); } Points = new List <StPoint>(); int zIndex = 0; int mIndex = 0; int count = bytesList.Count; if (HasZ && HasM) { zIndex = bytesList.Count / 4 * 2; mIndex = bytesList.Count / 4 * 3; count = bytesList.Count / 2; } else if (HasZ || HasM) { zIndex = bytesList.Count / 3 * 2; mIndex = bytesList.Count / 3 * 2; count = bytesList.Count / 3 * 2; } // The first point will be set normaly StPoint point; if (HasZ && HasM) { point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray(), bytesList[zIndex].ToArray(), bytesList[mIndex].ToArray()); } else if (HasZ) { point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray(), bytesList[zIndex].ToArray()); } else if (HasM) { point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray(), null, bytesList[mIndex].ToArray()); } else { point = new StPoint(bytesList[0].ToArray(), bytesList[1].ToArray()); } Points.Add(point); // The next point are set with the difference between the current coordinate and the previous one StPoint previousPoint = point; for (int i = 2; i < count; i += 2) { byte[] xBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[i].ToArray(), previousPoint.X.Bytes, StParameters.CoordinatesSystem, StCoordType.X); byte[] yBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[i + 1].ToArray(), previousPoint.Y.Bytes, StParameters.CoordinatesSystem, StCoordType.Y); if (HasZ && HasM) { byte[] zBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[zIndex + i / 2].ToArray(), previousPoint.Z.Bytes, StParameters.CoordinatesSystem, StCoordType.Z); byte[] mBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[mIndex + i / 2].ToArray(), previousPoint.M.Bytes, StParameters.CoordinatesSystem, StCoordType.M); point = new StPoint(xBytes, yBytes, zBytes, mBytes); } else if (HasZ) { byte[] zBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[zIndex + i / 2].ToArray(), previousPoint.Z.Bytes, StParameters.CoordinatesSystem, StCoordType.Z); point = new StPoint(xBytes, yBytes, zBytes); } else if (HasM) { byte[] mBytes = StCoordinatesSystemHelper.GetBytesFromDifference(bytesList[mIndex + i / 2].ToArray(), previousPoint.M.Bytes, StParameters.CoordinatesSystem, StCoordType.M); point = new StPoint(xBytes, yBytes, null, mBytes); } else { point = new StPoint(xBytes, yBytes); } Points.Add(point); previousPoint = point; } }