Ejemplo n.º 1
0
        /// <summary>
        /// Parse the given JSON as GeoJSON.
        /// </summary>
        /// <param name="GeoJSON">A valid GeoJSON JSON.</param>
        public static PolygonFeature Parse(JObject GeoJSON)
        {
            if (GeoJSON == null)
            {
                throw new ArgumentNullException(nameof(GeoJSON), "The given JSON must not be null!");
            }

            #region Parse geometry...

            var polygons = new List <List <GeoCoordinate> >();

            if (GeoJSON     ["geometry"]    is JObject geometryJSON &&
                geometryJSON["coordinates"] is JArray coordinatesJSON)
            {
                foreach (var outer in coordinatesJSON)
                {
                    if (outer is JArray)
                    {
                        polygons.Add(outer.Select(coordinates => GeoCoordinate.Parse(coordinates[1].Value <Double>(),
                                                                                     coordinates[0].Value <Double>())).ToList());
                    }
                }
            }

            #endregion

            return(new PolygonFeature(GeoJSON["id"]?.Value <String>(),
                                      Aegir.GeoJSON.ParseProperties(GeoJSON["properties"] as JObject),
                                      polygons));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse the given JSON as GeoJSON.
        /// </summary>
        /// <param name="GeoJSON">A valid GeoJSON JSON.</param>
        public static LineStringFeature Parse(JObject GeoJSON)
        {
            if (GeoJSON == null)
            {
                throw new ArgumentNullException(nameof(GeoJSON), "The given JSON must not be null!");
            }

            #region Parse geometry...

            // {
            //
            //    "type":  "Feature",
            //    "id":    "node/265616096",
            //
            //    "properties": {
            //      "@id":               "node/265616096",
            //      "amenity":           "post_box",
            //      "brand":             "Deutsche Post",
            //      "collection_times":  "Mo-Fr 14:30,16:30; Sa 12:45",
            //      "operator":          "Deutsche Post",
            //      "ref":               "Löbdergraben, 07743 Jena"
            //    },
            //
            //    "geometry": {
            //      "type": "Point",
            //      "coordinates": [
            //        11.587241,
            //        50.9268133
            //      ]
            //    }
            //
            // }

            var points = new List <GeoCoordinate>();

            if (GeoJSON     ["geometry"]    is JObject geometryJSON &&
                geometryJSON["coordinates"] is JArray coordinatesJSON)
            {
                foreach (var coordinates in coordinatesJSON)
                {
                    if (coordinates is JArray)
                    {
                        points.Add(GeoCoordinate.Parse(coordinates[1].Value <Double>(),
                                                       coordinates[0].Value <Double>()));
                    }
                }
            }

            #endregion

            return(new LineStringFeature(GeoJSON["id"]?.Value <String>(),
                                         Aegir.GeoJSON.ParseProperties(GeoJSON["properties"] as JObject),
                                         points));
        }