Пример #1
0
        public string GetNatureAreasBySearchFilter([FromBody] SearchFilterRequest searchFilterRequest)
        {
            var natureAreas = SqlServer.GetNatureAreasBySearchFilter(searchFilterRequest);
            var r           = GeoJsonConverter.NatureAreasToGeoJson(natureAreas, !searchFilterRequest.CenterPoints);

            return(r);
        }
Пример #2
0
        private T AssertRoundtrip <T>(string json) where T : GeoObject
        {
            var element  = JsonDocument.Parse(json).RootElement;
            var geometry = GeoJsonConverter.Read(element);

            var memoryStreamOutput = new MemoryStream();

            using (Utf8JsonWriter writer = new Utf8JsonWriter(memoryStreamOutput))
            {
                GeoJsonConverter.Write(writer, geometry);
            }

            var element2  = JsonDocument.Parse(memoryStreamOutput.ToArray()).RootElement;
            var geometry2 = GeoJsonConverter.Read(element2);

            var options = new JsonSerializerOptions()
            {
                Converters = { new GeoJsonConverter() }
            };

            // Serialize and deserialize as a base class
            var bytes     = JsonSerializer.SerializeToUtf8Bytes(geometry2, typeof(GeoObject), options);
            var geometry3 = JsonSerializer.Deserialize <GeoObject>(bytes, options);

            // Serialize and deserialize as a concrete class
            var bytes2    = JsonSerializer.SerializeToUtf8Bytes(geometry3, options);
            var geometry4 = JsonSerializer.Deserialize <T>(bytes2, options);

            return(geometry4);
        }
Пример #3
0
        /// <summary>
        /// Produce an output that records ways that got kept.
        /// </summary>
        public void OutputGraph(Graph <Node> graph, DirectedEdgeMetadata <Node, Way> wayMap, string filename)
        {
            var fullPath = Path.Combine(_outputLocation, filename);

            var converter = new GeoJsonConverter();
            var ways      = new Dictionary <Way, int>();

            foreach (var neighbor1 in graph.Neighbors)
            {
                foreach (var neighbor2 in neighbor1.Value.Where(x => x.PrimaryCopy))
                {
                    var way = wayMap[neighbor1.Key, neighbor2.Vertex];
                    if (ways.ContainsKey(way))
                    {
                        ways[way]++;
                    }
                    else
                    {
                        ways.Add(way, 1);
                    }
                }
            }

            var polygonOut = converter.Convert(ways.Keys);
            var serialized = JsonConvert.SerializeObject(polygonOut);

            File.WriteAllLines(fullPath, new[] { serialized });
        }
Пример #4
0
        /// <summary>
        /// Produce an output that records ways that got kept.
        /// </summary>
        public void OutputGraph(LinkedList <WeightedAdjacencyNode <Node> > route, DirectedEdgeMetadata <Node, Way> wayMap,
                                string filename)
        {
            var fullPath  = Path.Combine(_outputLocation, filename);
            var converter = new GeoJsonConverter();

//            var prevIt = route.First;
//            for (var it = prevIt.Next; it != null;)
//            {
//                if (prevIt.Value.Vertex != it.Value.Vertex)
//                {
//                    if (wayMap.ContainsKey(prevIt.Value.Vertex, it.Value.Vertex))
//                    {
//                        var way = wayMap[prevIt.Value.Vertex, it.Value.Vertex];
//                        Console.WriteLine(way.Tags["name"]);
//                    }
//                    else
//                    {
//                        Console.WriteLine("Missing");
//                    }
//                }
//
//                it = it.Next;
//            }

            var polygonOut = converter.Convert(route.Select(x => x.Vertex));
            var serialized = JsonConvert.SerializeObject(polygonOut);

            File.WriteAllLines(fullPath, new[] { serialized });
        }
Пример #5
0
        public void Grid500KmToGeoJsonTest()
        {
            new GridImportTest().StoreSsb500KmTest();

            var grid     = SqlServer.GetGrid(RutenettType.SSB500KM, new Collection <int>(), new Collection <int>(), "", "", 3857, 0);
            var gridJson = GeoJsonConverter.GridToGeoJson(grid, false);

            Assert.True(gridJson.Length > 10000); // 10479
        }
Пример #6
0
        public void OutputWays(IEnumerable <Way> ways, string filename)
        {
            var fullPath   = Path.Combine(_path, filename);
            var converter  = new GeoJsonConverter();
            var polygonOut = converter.Convert(ways);
            var serialized = JsonConvert.SerializeObject(polygonOut);

            File.WriteAllLines(fullPath, new[] { serialized });
        }
Пример #7
0
        public static void DebugOut(List <Way> ways, string filename)
        {
            var fullPath   = Path.Combine(outputLocation, filename);
            var converter  = new GeoJsonConverter();
            var polygonOut = converter.Convert(ways);
            var serialized = JsonConvert.SerializeObject(polygonOut);

            File.WriteAllLines(fullPath, new[] { serialized });
        }
Пример #8
0
        public string GetNatureAreasBySearchFilterV2([FromBody] SearchFilterRequest searchFilterRequest)
        {
            var search = new SearchV2(Config.Settings.ConnectionString);

            var list = search.GetNatureAreasBySearchFilter(searchFilterRequest);

            var geoJson = GeoJsonConverter.NatureAreasToGeoJson(list, !searchFilterRequest.CenterPoints);

            return(geoJson);
        }
Пример #9
0
 public OsmStreamFilterPoly(LineairRing poly)
 {
     if (poly == null)
     {
         throw new ArgumentNullException("poly");
     }
     this._poly = poly;
     this._box  = new GeoCoordinateBox((IList <GeoCoordinate>)poly.Coordinates);
     this.Meta.Add("poly", GeoJsonConverter.ToGeoJson(this._poly));
 }
Пример #10
0
        public void Grid1KmToGeoJsonTest()
        {
            new GridImportTest().StoreSsb001KmTest();

            var grid     = SqlServer.GetGrid(RutenettType.SSB001KM, new Collection <int>(), new Collection <int>(), "", "", 3857, 0);
            var gridJson = GeoJsonConverter.GridToGeoJson(grid, false);

            Assert.IsNotEmpty(gridJson);
            Assert.AreEqual(152909657, gridJson.Length);
        }
Пример #11
0
        public void RunFiles()
        {
            var basePath = AppDomain.CurrentDomain.BaseDirectory;

            foreach (var filename in testFileList)
            {
                var filePath = Path.Combine(basePath, "Resources", "Kml", filename);

                var xml = File.ReadAllText(filePath);

                var json = GeoJsonConverter.FromKml(xml);
            }
        }
        private MongoDbBusinessObjectSource(GeoJsonConverter <TCoordinate> converter)
        {
            base.Title = typeof(T).Name;

            Converter = converter;
            if (!BsonClassMap.IsClassMapRegistered(typeof(T)))
            {
                BsonClassMap.RegisterClassMap <T>(cm =>
                {
                    cm.AutoMap();
                    //cm.GetMemberMap("BsonGeometry").SetSerializer(new GeoJson2DCoordinatesSerializer());
                }
                                                  );
            }
        }
Пример #13
0
        private void BuildGraph(LinkedList <WayStep> waySteps)
        {
            var fullPath  = Path.Combine(_outputLocation, _graphFilename);
            var converter = new GeoJsonConverter();

            var ways = waySteps.GroupBy(x => x.Path).ToDictionary(x => x.Key, x => x.Count());

            foreach (var way in ways)
            {
                way.Key.Tags.Add("EdgeWeight", way.Value.ToString());
            }
            var polygonOut = converter.Convert(ways.Keys);
            var serialized = JsonConvert.SerializeObject(polygonOut);

            File.WriteAllLines(fullPath, new[] { serialized });
        }
        public bool ToGeoJson(string xml, out string json)
        {
            json = null;

            try
            {
                json = GeoJsonConverter.FromKml(xml);

                return(true);
            }
            catch (Exception e)
            {
                logger.LogError(e, "Failed to convert Kml to GeoJson");

                return(false);
            }
        }
 public PoIRepository(GeoJsonConverter <GeoJson2DCoordinates> converter, string connectionString, string database, string collection)
     : base(converter, connectionString, database, collection)
 {
 }
 public PoIRepository(GeoJsonConverter <GeoJson2DCoordinates> converter, MongoClientSettings settings, string database, string collection)
     : base(converter, settings, database, collection)
 {
 }
Пример #17
0
        public object GetAreas(int areatype, int number)
        {
            var areas = SqlServer.GetAreas((AreaType)areatype, 0, number);

            return(GeoJsonConverter.AreasToGeoJson(areas, false));
        }
Пример #18
0
 public static string ToGeoJson(this IList <Instruction> instructions, Route route)
 {
     return(GeoJsonConverter.ToGeoJson(instructions.ToFeatureCollection(route)));
 }
Пример #19
0
        public object GetGrid([FromBody] GridFilterRequest gridFilterRequest)
        {
            var gridType    = RutenettType.Undefined;
            var areaType    = AreaType.Undefined;
            var areaRequest = false;

            if (gridFilterRequest == null)
            {
                throw new Exception("Type rutenett er ikke spesifisert.");
            }

            switch (gridFilterRequest.GridType)
            {
            case "Undefined":
                gridType = RutenettType.Undefined;
                break;

            case "SSB0250M":
                gridType = RutenettType.SSB0250M;
                break;

            case "SSB0500M":
                gridType = RutenettType.SSB0500M;
                break;

            case "SSB001KM":
                gridType = RutenettType.SSB001KM;
                break;

            case "SSB002KM":
                gridType = RutenettType.SSB002KM;
                break;

            case "SSB005KM":
                gridType = RutenettType.SSB005KM;
                break;

            case "SSB010KM":
                gridType = RutenettType.SSB010KM;
                break;

            case "SSB025KM":
                gridType = RutenettType.SSB025KM;
                break;

            case "SSB050KM":
                gridType = RutenettType.SSB050KM;
                break;

            case "SSB100KM":
                gridType = RutenettType.SSB100KM;
                break;

            case "SSB250KM":
                gridType = RutenettType.SSB250KM;
                break;

            case "SSB500KM":
                gridType = RutenettType.SSB500KM;
                break;

            case "Kommune":
                areaType    = AreaType.Kommune;
                areaRequest = true;
                break;

            case "Fylke":
                areaType    = AreaType.Fylke;
                areaRequest = true;
                break;

            default:
                throw new Exception("Ukjent rutenett '" + gridFilterRequest.GridType + "'.");
            }

            if (areaRequest)
            {
                var areaGrid = SqlServer.GetAreas(areaType, gridFilterRequest.GridLayerTypeId);
                return(GeoJsonConverter.AreasToGeoJson(areaGrid, gridFilterRequest.GridLayerTypeId != 0));
            }

            var grid = SqlServer.GetGrid(
                gridType,
                gridFilterRequest.Municipalities,
                gridFilterRequest.Counties,
                gridFilterRequest.Geometry,
                gridFilterRequest.BoundingBox,
                gridFilterRequest.EpsgCode,
                gridFilterRequest.GridLayerTypeId
                );

            return(GeoJsonConverter.GridToGeoJson(grid, gridFilterRequest.GridLayerTypeId != 0));
        }
 private MongoDbBusinessObjectSource(GeoJsonConverter <TCoordinate> converter, MongoClient mongoClient, string database, string collection)
     : this(converter)
 {
     var mongoDatabase = mongoClient.GetDatabase(database);
     _collection = mongoDatabase.GetCollection <T>(collection);
 }
 protected MongoDbBusinessObjectSource(GeoJsonConverter <TCoordinate> converter, string connectionString, string database, string collection)
     : this(converter, new MongoClient(connectionString), database, collection)
 {
 }
 protected MongoDbBusinessObjectSource(GeoJsonConverter <TCoordinate> converter, MongoClientSettings settings, string database, string collection)
     : this(converter, new MongoClient(settings), database, collection)
 {
 }
Пример #23
0
 public static string ToGeoJson(this Route route)
 {
     return(GeoJsonConverter.ToGeoJson(route.ToFeatureCollection()));
 }