static void ImportRouteSegments(IMediator CommandBus, Wgs84GraphBuilder graphBuilder)
        {
            // Import node objects to database
            var segmentJsonText = File.ReadAllText(_builderDataPath + "RouteSegments.geojson");

            var segmentsJson = JsonConvert.DeserializeObject(segmentJsonText) as JObject;

            var features = segmentsJson["features"];

            foreach (var feature in features)
            {
                var properties = feature["properties"] as JObject;

                var geometry = feature["geometry"];

                var geometryType = geometry["type"].ToString();
                var geometryCoordinates = geometry["coordinates"].ToString().Replace("\r\n", "").Replace(" ", "");

                var segmentId = _segmentIdPrefix + properties["Id"].ToString().PadLeft(6, '0');
                var segmentKind = properties["RouteSegmentKind"].ToString();
                var assetStatus = properties["Status"].ToString();

                if (properties["BuildTestData"].ToString() != "")
                {
                    var buildCodes = properties["BuildTestData"].ToString().Split(';');
                    _segmentBuildCodes.Add(segmentId, buildCodes);
                }

                // Add link to graph
                var coordinates = geometry["coordinates"] as JArray;
                var startX = coordinates.First[0];
                var startY = coordinates.First[1];

                var endX = coordinates.Last[0];
                var endY = coordinates.Last[1];

                graphBuilder.AddLinkToGraph(segmentId, (double)startX, (double)startY, (double)endX, (double)endY);

                // Derive node and function kind
                var segmentKindCode = RouteSegmentKindEnum.Unknown;

                if (segmentKind == "buried")
                {
                    segmentKindCode = RouteSegmentKindEnum.Underground;
                }

                var link = _routeGraph.Links[segmentId];

                var addSegmentCmd = new AddSegmentCommand()
                {
                    Id = Guid.Parse(segmentId),
                    FromNodeId = Guid.Parse(link.StartNode.Id),
                    ToNodeId = Guid.Parse(link.EndNode.Id),
                    SegmentKind = segmentKindCode,
                    Geometry = new Geometry(geometryType, geometryCoordinates)
                };

                CommandBus.Send(addSegmentCmd).Wait();
            }
        }
Beispiel #2
0
        static void ImportRouteSegments(MigrationBuilder migrationBuilder, Wgs84GraphBuilder graphBuilder)
        {
            // Import node objects to database
            var segmentJsonText = File.ReadAllText(_builderDataPath + "Builder/RouteSegments.geojson");

            var segmentsJson = JsonConvert.DeserializeObject(segmentJsonText) as JObject;

            var features = segmentsJson["features"];

            foreach (var feature in features)
            {
                var properties = feature["properties"] as JObject;

                var geometry = feature["geometry"];

                var geometryType        = geometry["type"].ToString();
                var geometryCoordinates = geometry["coordinates"].ToString().Replace("\r\n", "").Replace(" ", "");

                var segmentId   = _segmentIdPrefix + properties["Id"].ToString().PadLeft(6, '0');
                var segmentKind = properties["RouteSegmentKind"].ToString();
                var assetStatus = properties["Status"].ToString();

                if (properties["BuildTestData"].ToString() != "")
                {
                    var buildCodes = properties["BuildTestData"].ToString().Split(';');
                    SegmentBuildCodes.Add(segmentId, buildCodes);
                }


                // Add link to graph
                var coordinates = geometry["coordinates"] as JArray;
                var startX      = coordinates.First[0];
                var startY      = coordinates.First[1];

                var endX = coordinates.Last[0];
                var endY = coordinates.Last[1];

                graphBuilder.AddLinkToGraph(segmentId, (double)startX, (double)startY, (double)endX, (double)endY);


                // Derive node and function kind
                int segmentKindCode = (int)RouteSegmentKindEnum.Unknown;

                if (segmentKind == "buried")
                {
                    segmentKindCode = (int)RouteSegmentKindEnum.Underground;
                }

                migrationBuilder.InsertData(
                    table: "RouteSegments",
                    columns: new[] { "Id", "SegmentKind", "GeoJsonType", "GeoJsonCoordinates", "AssetStatus" },
                    values: new object[] {
                    segmentId,
                    segmentKindCode,
                    geometryType,
                    geometryCoordinates,
                    Int32.Parse(assetStatus)
                });
            }
        }