Esempio n. 1
0
        public void ImportGeoJSONObject()
        {
            GeoJSONObject     geoJSONObject     = GeoJSONObject.ImportGeoJSON(File.ReadAllText("locationsAutoGenerated.json"));
            FeatureCollection featureCollection = (FeatureCollection)geoJSONObject;

            Assert.AreEqual(featureCollection.Features.ToArray().Length, 3);
        }
Esempio n. 2
0
        /// <summary>
        /// Imports GeoJSON and adds the new features to the feature list
        /// </summary>
        /// <param name="contents">A serialised GeoJSON object</param>
        /// <returns>Number of features successfully imported</returns>
        public async Task <int> ImportRawContents(string contents)
        {
            GeoJSONObject importedGeoJSON = GeoJSONObject.ImportGeoJSON(contents);

            if (importedGeoJSON == null)
            {
                throw new ArgumentException("Import data does not contain valid GeoJSON");
            }

            return(importedGeoJSON.Type switch
            {
                GeoJSONType.Point => await ImportItem(new Feature((Models.Point)importedGeoJSON)) ? 1 : 0,
                GeoJSONType.LineString => await ImportItem(new Feature((LineString)importedGeoJSON)) ? 1 : 0,
                GeoJSONType.Polygon => await ImportItem(new Feature((Polygon)importedGeoJSON)) ? 1 : 0,
                GeoJSONType.Feature => await ImportItem((Feature)importedGeoJSON) ? 1 : 0,
                GeoJSONType.FeatureCollection => await ImportItems(((FeatureCollection)importedGeoJSON).Features),
                _ => throw new ArgumentException("Import data does not contain a supported GeoJSON type."),
            });
Esempio n. 3
0
        public async Task ImportFeatureList()
        {
            try
            {
                FeatureCollection featureCollection = (FeatureCollection)GeoJSONObject.ImportGeoJSON(Constants.FeaturesFileContents);
                _ = await FeatureStore.ImportItems(featureCollection.Features);
            }
            catch
            {
                bool result = await NavigationService.ShowAlert("Feature List Error", "Groundsman was unable to load your saved features. Would you like to export the corrupted features?", true);

                if (result)
                {
                    await Share.RequestAsync(new ShareFileRequest
                    {
                        Title = "Groundsman Feature List (Corrupted)",
                        File  = new ShareFile(Constants.FEATURES_FILE, "application/json"),
                    });
                }
                await FeatureStore.ResetItems();
            }
        }