public bool TryWriteGeometryCollection(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!_shapeConverter.CanConvert(ObjectType.GeometryCollection))
            {
                return(false);
            }

            ObjectType geomType = _shapeConverter.GetObjectType(value);

            if (geomType != ObjectType.GeometryCollection)
            {
                return(false);
            }

            writer.WriteStartObject();
            writer.WritePropertyName("type");
            writer.WriteValue(Enum.GetName(typeof(ObjectType), geomType));

            writer.WritePropertyName("geometries");
            writer.WriteStartArray();
            foreach (var geometry in _shapeConverter.FromGeometryCollection(value))
            {
                serializer.Serialize(writer, geometry);
            }
            writer.WriteEndArray();

            writer.WriteEndObject();
            return(true);
        }
Ejemplo n.º 2
0
        private void AppendGeometryCollection(StringBuilder builder, object geometryCollection)
        {
            var geometries = _shapeConverter.FromGeometryCollection(geometryCollection);

            builder.Append("GEOMETRYCOLLECTION");
            if (geometries.Length == 0)
            {
                builder.Append(" EMPTY");
                return;
            }

            //AppendDimensions(builder, geometryCollection);
            builder.Append(" (");

            for (var i = 0; i < geometries.Length; i++)
            {
                if (i > 0)
                {
                    builder.Append(", ");
                }
                AppendGeometry(builder, geometries[i]);
            }
            builder.Append(")");
        }