public void GeometryCollection() { var reader = new GeoJsonReader(); var geo = new GeometryCollection(new Point(0, 0), new Point(1, 0)); Assert.AreEqual( @"{""type"":""GeometryCollection"",""geometries"":[{""type"":""Point"",""coordinates"":[0,0]},{""type"":""Point"",""coordinates"":[0,1]}]}", geo.ToGeoJson()); Assert.AreEqual(geo, reader.Read(geo.ToGeoJson())); }
private bool TryParseGeometryCollection(JsonObject obj, out object result) { result = null; var geometries = obj["geometries"] as JsonArray; if (geometries != null) { var temp =new object[geometries.Count]; for (var index = 0; index < geometries.Count; index++) { var geometry = geometries[index]; if (!TryParseGeometry((JsonObject)geometry, out temp[index])) return false; } result = new GeometryCollection(temp.Cast<IGeometry>()); return true; } return false; }
private void AppendGeometryCollection(StringBuilder builder, GeometryCollection geometryCollection) { builder.Append("GEOMETRYCOLLECTION"); if (geometryCollection.IsEmpty) { builder.Append(" EMPTY"); return; } AppendDimensions(builder, geometryCollection); builder.Append(" ("); for (var i = 0; i < geometryCollection.Geometries.Count; i++) { if (i > 0) builder.Append(", "); AppendGeometry(builder, geometryCollection.Geometries[i]); } builder.Append(")"); }
private void WriteGeometryCollection(GeometryCollection collection, WkbBinaryWriter writer) { WriteEncoding(writer, _settings.Encoding); WriteGeometryType(collection, WkbGeometryType.GeometryCollection, writer); var geometries = collection.Geometries.Where(x => !(x is Point) || !x.IsEmpty).ToList(); writer.Write((uint)geometries.Count); foreach (var geometry in geometries) Write(geometry, writer); }
private Dictionary<string, object> WriteGeometryCollection(GeometryCollection geometryCollection) { return new Dictionary<string, object> { { "type", "GeometryCollection" }, { "geometries", geometryCollection.Geometries.Select(WriteGeometry).ToArray() } }; }