コード例 #1
0
ファイル: Extensions.cs プロジェクト: mshakurov/OpenLR
        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);
        }
コード例 #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);
     }
 }
コード例 #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);
     }
 }
コード例 #4
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);
        }
コード例 #5
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);
        }