static WknGeometryCollection ParseGeometryCollection(byte[] wkb, ref int pos) { if (wkb[pos] != 1) { throw new Exception("Sorry, only Little Endian format is supported"); } var type = BitConverter.ToUInt32(wkb, pos + 1); if (type != (uint)WknGeometryType.WknGeometryCollection) { throw new Exception("Invalid object type"); } var nbShapes = BitConverter.ToUInt32(wkb, pos + 5); pos += 9; var shapes = new WknShape[nbShapes]; for (var r = 0; r < nbShapes; ++r) { shapes[r] = ParseShape(wkb, ref pos); } return(new WknGeometryCollection(shapes)); }
static public byte[] ConvertToBinary(WknShape shape) { using (var mem = new MemoryStream()) { using (var wrt = new BinaryWriter(mem)) { AppendShape(wrt, shape); } return(mem.ToArray()); } }
static public void AppendShape(BinaryWriter wrt, WknShape shape) { switch (shape.Type) { case WknGeometryType.WknPoint: AppendPoint(wrt, (WknPoint)shape); break; case WknGeometryType.WknLineString: AppendLineString(wrt, (WknLineString)shape); break; case WknGeometryType.WknPolygon: AppendPolygon(wrt, (WknPolygon)shape); break; case WknGeometryType.WknMultiPoint: AppendMultiPoint(wrt, (WknMultiPoint)shape); break; case WknGeometryType.WknMultiLineString: AppendMultiLineString(wrt, (WknMultiLineString)shape); break; case WknGeometryType.WknMultiPolygon: AppendMultiPolygon(wrt, (WknMultiPolygon)shape); break; case WknGeometryType.WknGeometryCollection: AppendGeometryCollection(wrt, (WknGeometryCollection)shape); break; default: throw new NotImplementedException(); } }
static public string ConvertToText(WknShape shape) { return(shape.ToString()); }