Example #1
0
        public static FeatureCollection FromGeoJson(string geoJson)
        {
            var jsonSerializer = new NetTopologySuite.IO.GeoJsonSerializer();
            var jsonStream     = new StringReader(geoJson);

            return(jsonSerializer.Deserialize <FeatureCollection>(new JsonTextReader(jsonStream)) as FeatureCollection);
        }
Example #2
0
 /// <summary>
 /// Loads the test polygon.
 /// </summary>
 /// <returns></returns>
 internal static IPolygon LoadPolygon()
 {
     using (var stream = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Sample.GeoFilter.polygon.geojson")))
     {
         var jsonSerializer = new NetTopologySuite.IO.GeoJsonSerializer();
         var features       = jsonSerializer.Deserialize <FeatureCollection>(new JsonTextReader(stream));
         return(features.Features[0].Geometry as IPolygon);
     }
 }
Example #3
0
 /// <summary>
 /// Gets a feature collection from an embedded geojson.
 /// </summary>
 public static FeatureCollection GetFeatureCollection(string embeddedResourceId)
 {
     using (var stream = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedResourceId)))
     {
         var jsonReader        = new JsonTextReader(stream);
         var geoJsonSerializer = new NetTopologySuite.IO.GeoJsonSerializer();
         return(geoJsonSerializer.Deserialize <FeatureCollection>(jsonReader) as FeatureCollection);
     }
 }
Example #4
0
        private static string ToJson(FeatureCollection featureCollection)
        {
            var jsonSerializer = new NetTopologySuite.IO.GeoJsonSerializer();
            var jsonStream     = new StringWriter();

            jsonSerializer.Serialize(jsonStream, featureCollection);
            var json = jsonStream.ToInvariantString();

            return(json);
        }
Example #5
0
        private static bool TestGeoJsonDeserialize <T>(string json) where T : class
        {
            var jr = new JsonTextReader(new StringReader(json));
            var s  = new NetTopologySuite.IO.GeoJsonSerializer();
            var f  = default(T);

            Assert.DoesNotThrow(() => f = s.Deserialize <T>(jr));
            Assert.IsNotNull(f);

            return(true);
        }
Example #6
0
        /// <summary>
        /// Tests resolving all points in the given feature collection.
        /// </summary>
        public static void TestResolve(Router router, string embeddedResourceId,
                                       Func <Router, GeoAPI.Geometries.Coordinate, Result <RouterPoint> > resolve)
        {
            FeatureCollection featureCollection;

            using (var stream = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedResourceId)))
            {
                var jsonReader        = new JsonTextReader(stream);
                var geoJsonSerializer = new NetTopologySuite.IO.GeoJsonSerializer();
                featureCollection = geoJsonSerializer.Deserialize(jsonReader) as FeatureCollection;
            }
            TestResolve(router, featureCollection, resolve);
        }