protected virtual void ConvertFolder(KmlFolder folder, GeoJsonFeatureCollection collection, KmlFeature feature, IStyleProvider provider)
        {
            switch (feature)
            {
            case KmlPlacemark placemark:

                collection.Add(ConvertPlacemark(placemark, provider));

                break;

            case KmlDocument document:
            // Why would you have a document in a folder? (although it seems legal according to the specification)

            case KmlFolder childFolder:
            // Why would you have folder in another folder? (although it seems legal according to the specification)

            default:
                throw new KmlException("Unsupported feature " + feature.GetType());
            }
        }
        protected virtual GeoJsonFeatureCollection[] ConvertDocument(KmlDocument document, IStyleProvider provider)
        {
            // Use the style provider of the document if not explicitly specified
            provider = provider ?? document.StyleSelectors;

            // Initialize a new list of collections
            List <GeoJsonFeatureCollection> collections = new List <GeoJsonFeatureCollection>();

            if (document.Features.Any(x => x is KmlFolder))
            {
                GeoJsonFeatureCollection defaultCollection = null;

                foreach (KmlFeature feature in document.Features)
                {
                    switch (feature)
                    {
                    case KmlDocument _:
                        throw new KmlException("Weird place for a <Document>, huh?");

                    case KmlFolder folder:
                        collections.Add(ConvertFolder(folder, provider));
                        break;

                    case KmlPlacemark placemark:

                        // Make sure the default feature collection is initialized
                        if (defaultCollection == null)
                        {
                            collections.Add(defaultCollection = new GeoJsonFeatureCollection());
                        }

                        // As the placemark isn't located inside a folder, we should append it to a "default" feature collection"
                        defaultCollection.Add(ConvertPlacemark(placemark, provider));

                        break;

                    default:
                        throw new KmlException("Unsupported feature " + feature.GetType());
                    }
                }
            }
            else
            {
                GeoJsonFeatureCollection features = new GeoJsonFeatureCollection();

                foreach (KmlFeature feature in document.Features)
                {
                    switch (feature)
                    {
                    case KmlDocument _:
                        throw new KmlException("Weird place for a <Document>, huh?");

                    case KmlPlacemark placemark:
                        features.Add(ConvertPlacemark(placemark, provider));
                        break;

                    default:
                        throw new KmlException("Unsupported feature " + feature.GetType());
                    }
                }

                collections.Add(features);
            }

            return(collections.ToArray());
        }