public bool TryWriteGeometry(JsonWriter writer, object value, JsonSerializer serializer) { ObjectType geomType = _shapeConverter.GetObjectType(value); if (!_shapeConverter.CanConvert(geomType)) { return(false); } switch (geomType) { case ObjectType.Point: case ObjectType.LineString: case ObjectType.Polygon: case ObjectType.MultiPoint: case ObjectType.MultiLineString: case ObjectType.MultiPolygon: break; default: return(false); } writer.WriteStartObject(); writer.WritePropertyName("type"); writer.WriteValue(Enum.GetName(typeof(ObjectType), geomType)); writer.WritePropertyName("coordinates"); switch (geomType) { case ObjectType.Point: WriteJsonCoordinate(writer, _shapeConverter.FromPoint(value)); break; case ObjectType.LineString: WriteJsonCoordinates(writer, _shapeConverter.FromLineString(value)); break; case ObjectType.MultiPoint: WriteJsonCoordinates(writer, _shapeConverter.FromMultiPoint(value)); break; case ObjectType.Polygon: WriteJsonCoordinatesEnumerable(writer, _shapeConverter.FromPolygon(value)); break; case ObjectType.MultiLineString: WriteJsonCoordinatesEnumerable(writer, _shapeConverter.FromMultiLineString(value)); break; case ObjectType.MultiPolygon: WriteJsonCoordinatesEnumerable2(writer, _shapeConverter.FromMultiPolygon(value)); break; } writer.WriteEndObject(); return(true); }
private void AppendMultiLineString(StringBuilder builder, object multiLineString) { var geometries = _shapeConverter.FromMultiLineString(multiLineString); builder.Append("MULTILINESTRING"); if (geometries.Length == 0) { builder.Append(" EMPTY"); return; } AppendDimensions(builder, GetDimensions(geometries)); builder.Append(" ("); for (var i = 0; i < geometries.Length; i++) { if (i > 0) { builder.Append(", "); } AppendLineStringInner(builder, geometries[i]); } builder.Append(")"); }