private bool TryParseMultiPolygon(JsonObject obj, out object result) { var coordinates = obj["coordinates"] as JsonArray; Coordinate[][][] co; if (coordinates != null && TryParseCoordinateArrayArrayArray(coordinates, out co)) { result = new MultiPolygon(co.Select(x => new Polygon(new LinearRing(x.First()), x.Skip(1).Select(c => new LinearRing(c))) )); return true; } result = null; return false; }
private void AppendMultiPolygon(StringBuilder builder, MultiPolygon multiPolygon) { builder.Append("MULTIPOLYGON"); if (multiPolygon.IsEmpty) { builder.Append(" EMPTY"); return; } AppendDimensions(builder, multiPolygon); builder.Append(" ("); for (var i = 0; i < multiPolygon.Geometries.Count; i++) { if (i > 0) builder.Append(", "); AppendPolygonInner(builder, (Polygon)multiPolygon.Geometries[i]); } builder.Append(")"); }
private void WriteMultiPolygon(MultiPolygon multiPolygon, WkbBinaryWriter writer) { WriteEncoding(writer, _settings.Encoding); WriteGeometryType(multiPolygon, WkbGeometryType.MultiPolygon, writer); writer.Write((uint)multiPolygon.Geometries.Count); foreach (var polygon in multiPolygon.Geometries.Cast<Polygon>()) Write(polygon, writer); }
private void WriteMultiPolygon(MultiPolygon multiPolygon, WkbBinaryWriter writer) { WriteGeometryType(multiPolygon, WkbGeometryType.MultiPolygon, writer); writer.Write((uint)multiPolygon.Geometries.Count); foreach (var polygon in multiPolygon.Geometries.Cast<Polygon>()) WritePolygonInner(polygon, writer); }
private Dictionary<string, object> WriteMultiPolygon(MultiPolygon multiPolygon) { return new Dictionary<string, object> { { "type", "MultiPolygon" }, { "coordinates", multiPolygon.Geometries.Cast<Polygon>().Select(WriteCoordinates).ToArray() } }; }
public void MultiPolygon() { var reader = new GeoJsonReader(); var geo = new MultiPolygon( new Polygon(new LinearRing(new Coordinate(0, 0), new Coordinate(1, 1), new Coordinate(2, 0), new Coordinate(0, 0)))); Assert.AreEqual(@"{""type"":""MultiPolygon"",""coordinates"":[[[[0,0],[1,1],[0,2],[0,0]]]]}", geo.ToGeoJson()); Assert.AreEqual(geo, reader.Read(geo.ToGeoJson())); }