private bool TryReadCircle(string value, out object result) { if (!_shapeConverter.CanConvert(ObjectType.Circle)) { result = null; return(false); } var match = Regex.Match(value, @"Circle \s* \( \s* ([+-]?(?:\d+\.?\d*|\d*\.?\d+)) \s+ ([+-]?(?:\d+\.?\d*|\d*\.?\d+)) \s+ d=([+-]?(?:\d+\.?\d*|\d*\.?\d+)) \s* \)", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase); if (match.Success) { result = _shapeConverter.ToCircle(new double[] { double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture) }); return(true); } result = null; return(false); }
private bool TryWriteCircle(object shape, out string result) { if (_shapeConverter.CanConvert(ObjectType.Circle) && _shapeConverter.GetObjectType(shape) == ObjectType.Circle) { var circle = _shapeConverter.FromCircle(shape); result = string.Format(CultureInfo.InvariantCulture, "CIRCLE({0:F9} {1:F9} d={2:F9})", circle[0], circle[1], circle[2]); return(true); } result = default(string); return(false); }
public bool TryWriteFeature(JsonWriter writer, object value, JsonSerializer serializer) { if (!_shapeConverter.CanConvert(ObjectType.Feature)) { return(false); } ObjectType geomType = _shapeConverter.GetObjectType(value); if (geomType != ObjectType.Feature) { return(false); } writer.WriteStartObject(); writer.WritePropertyName("type"); writer.WriteValue(Enum.GetName(typeof(ObjectType), ObjectType.Feature)); object id; Dictionary <string, object> props; var geometry = _shapeConverter.FromFeature(value, out id, out props); if (id != null) { writer.WritePropertyName("id"); serializer.Serialize(writer, id); } if (props != null && props.Count > 0) { writer.WritePropertyName("properties"); serializer.Serialize(writer, props); } writer.WritePropertyName("geometry"); serializer.Serialize(writer, geometry); writer.WriteEndObject(); return(true); }