static void ImportRouteNodes(IMediator CommandBus, Wgs84GraphBuilder graphBuilder) { // Import node objects to database var nodesJsonText = File.ReadAllText(_builderDataPath + "RouteNodes.geojson"); var nodesJson = JsonConvert.DeserializeObject(nodesJsonText) as JObject; var features = nodesJson["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 nodeId = _nodeIdPrefix + properties["Id"].ToString().PadLeft(6, '0'); var nodeType = properties["NodeType"].ToString(); var nodeName = properties["NodeName"].ToString(); var assetStatus = properties["Status"].ToString(); if (properties["BuildTestData"].ToString() != "") { var buildCodes = properties["BuildTestData"].ToString().Split(';'); _nodeBuildCodes.Add(nodeId, buildCodes); } // Add node to graph var x = ((JArray)geometry["coordinates"])[0]; var y = ((JArray)geometry["coordinates"])[1]; graphBuilder.AddNodeToGraph(nodeId, (double)x, (double)y); // Derive node and function kind var nodeKind = RouteNodeKindEnum.Unknown; var nodeFunctionKind =RouteNodeFunctionKindEnum.Unknown; if (nodeType == "CO") { nodeKind = RouteNodeKindEnum.CentralOfficeSmall; nodeFunctionKind = RouteNodeFunctionKindEnum.SecondaryNode; } else if (nodeType == "HH") { nodeKind = RouteNodeKindEnum.HandHole; nodeFunctionKind = RouteNodeFunctionKindEnum.OpenConduitPoint; } else if (nodeType == "CC") { nodeKind = RouteNodeKindEnum.ConduitClosure; nodeFunctionKind = RouteNodeFunctionKindEnum.BurriedConduitPont; } else if (nodeType == "CE") { nodeKind = RouteNodeKindEnum.ConduitEnd; nodeFunctionKind = RouteNodeFunctionKindEnum.BurriedConduitPont; } else if (nodeType == "SJ") { nodeKind = RouteNodeKindEnum.ConduitSimpleJunction; nodeFunctionKind = RouteNodeFunctionKindEnum.BurriedConduitPont; } else if (nodeType == "FP") { nodeKind = RouteNodeKindEnum.CabinetBig; nodeFunctionKind = RouteNodeFunctionKindEnum.FlexPoint; } else if (nodeType == "SP") { nodeKind = RouteNodeKindEnum.CabinetSmall; nodeFunctionKind = RouteNodeFunctionKindEnum.SplicePoint; } else if (nodeType == "A") { nodeKind = RouteNodeKindEnum.BuildingAccessPoint; nodeFunctionKind = RouteNodeFunctionKindEnum.SplicePoint; } else if (nodeType == "MDU") { nodeKind = RouteNodeKindEnum.MultiDwellingUnit; nodeFunctionKind = RouteNodeFunctionKindEnum.ServiceDeliveryPoint; } else if (nodeType == "SDU") { nodeKind = RouteNodeKindEnum.SingleDwellingUnit; nodeFunctionKind = RouteNodeFunctionKindEnum.ServiceDeliveryPoint; } // location info var locationInfo = new LocationInfo(); locationInfo.Id = Guid.NewGuid(); locationInfo.AccessAddress = new AccessAddressInfo() { MunicipalCode = "0630", MunicipalRoadCode = "1521", StreetName = properties["StreetName"].ToString(), HouseNumber = properties["HouseNumber"].ToString(), PostalCode = "7120", PostalName = "Vejle Ø" }; var addNodeCmd = new AddNodeCommand() { Id = Guid.Parse(nodeId), Name = nodeName, NodeKind = nodeKind, NodeFunctionKind = nodeFunctionKind, LocationInfo = locationInfo, Geometry = new Geometry(geometryType, geometryCoordinates) }; CommandBus.Send(addNodeCmd).Wait(); } }
private void ImportRouteNodes(Wgs84GraphBuilder graphBuilder) { // Import node objects to database var nodesJsonText = File.ReadAllText(_routeNodeFilename); var nodesJson = JsonConvert.DeserializeObject(nodesJsonText) as JObject; var features = nodesJson["features"]; bool firstNode = true; 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 nodeId = Guid.Parse(_nodeIdPrefix + properties["Id"].ToString().PadLeft(6, '0')); var nodeType = properties["NodeType"].ToString(); var nodeName = properties["NodeName"].ToString(); var assetStatus = properties["Status"].ToString(); if (properties["BuildTestData"].ToString() != "") { var buildCodes = properties["BuildTestData"].ToString().Split(';'); _nodeBuildCodes.Add(nodeId, buildCodes); } // Add node to graph var x = ((JArray)geometry["coordinates"])[0]; var y = ((JArray)geometry["coordinates"])[1]; // Derive node and function kind RouteNodeKindEnum? nodeKind = null; RouteNodeFunctionEnum?nodeFunctionKind = null; if (nodeType == "CO") { nodeKind = RouteNodeKindEnum.CentralOfficeSmall; nodeFunctionKind = RouteNodeFunctionEnum.SecondaryNode; } else if (nodeType == "HH") { nodeKind = RouteNodeKindEnum.HandHole; nodeFunctionKind = RouteNodeFunctionEnum.AccessibleConduitClosure; } else if (nodeType == "CC") { nodeKind = RouteNodeKindEnum.ConduitClosure; nodeFunctionKind = RouteNodeFunctionEnum.NonAccessibleConduitClosure; } else if (nodeType == "CE") { nodeKind = RouteNodeKindEnum.ConduitEnd; nodeFunctionKind = RouteNodeFunctionEnum.NonAccessibleConduitClosure; } else if (nodeType == "SJ") { nodeKind = RouteNodeKindEnum.ConduitSimpleJunction; nodeFunctionKind = RouteNodeFunctionEnum.NonAccessibleConduitClosure; } else if (nodeType == "FP") { nodeKind = RouteNodeKindEnum.CabinetBig; nodeFunctionKind = RouteNodeFunctionEnum.FlexPoint; } else if (nodeType == "SP") { nodeKind = RouteNodeKindEnum.CabinetSmall; nodeFunctionKind = RouteNodeFunctionEnum.SplicePoint; } else if (nodeType == "A") { nodeKind = RouteNodeKindEnum.BuildingAccessPoint; nodeFunctionKind = RouteNodeFunctionEnum.SplicePoint; } else if (nodeType == "MDU") { nodeKind = RouteNodeKindEnum.MultiDwellingUnit; nodeFunctionKind = RouteNodeFunctionEnum.CustomerPremisesPoint; } else if (nodeType == "SDU") { nodeKind = RouteNodeKindEnum.SingleDwellingUnit; nodeFunctionKind = RouteNodeFunctionEnum.CustomerPremisesPoint; } // On the first node, we set the start marker into applicaion info, and insert data into all the other propeties as well to test if every information is captured into the generated events if (firstNode) { RouteNodeRecord routeNode = new RouteNodeRecord() { Id = nodeId, WorkTaskMrid = _startMarker, ApplicationName = _applicationName, ApplicationInfo = _applicationName, DeleteMe = false, MarkAsDeleted = false, Username = _userName, Geometry = GeographicToProjectedCoordinateConverter.ConvertPoint(GeoJsonConversionHelper.ConvertFromPointGeoJson(geometryCoordinates)), RouteNodeInfo = new RouteNodeInfo(nodeKind, nodeFunctionKind), LifecycleInfo = new LifecycleInfo(DeploymentStateEnum.InService, DateTime.Now, DateTime.Now), MappingInfo = new MappingInfo(MappingMethodEnum.LandSurveying, "10 cm", "20 cm", DateTime.Now, "Surveyed with GPS"), NamingInfo = new NamingInfo(nodeName, "Route node"), SafetyInfo = new SafetyInfo("no danger", "might contain rats"), IsAutoCreated = false }; graphBuilder.AddNodeToGraph(routeNode, (double)x, (double)y); _routeNetworkDatestore.InsertRouteNode(routeNode); } else { RouteNodeRecord routeNode = new RouteNodeRecord() { Id = nodeId, ApplicationName = _applicationName, ApplicationInfo = _applicationName, DeleteMe = false, MarkAsDeleted = false, Username = _userName, Geometry = GeographicToProjectedCoordinateConverter.ConvertPoint(GeoJsonConversionHelper.ConvertFromPointGeoJson(geometryCoordinates)), RouteNodeInfo = new RouteNodeInfo(nodeKind, nodeFunctionKind), NamingInfo = new NamingInfo(nodeName, "Route node"), IsAutoCreated = false }; graphBuilder.AddNodeToGraph(routeNode, (double)x, (double)y); _routeNetworkDatestore.InsertRouteNode(routeNode); } firstNode = false; } }
static void ImportRouteNodes(MigrationBuilder migrationBuilder, Wgs84GraphBuilder graphBuilder) { // Import node objects to database var nodesJsonText = File.ReadAllText(_builderDataPath + "Builder/RouteNodes.geojson"); var nodesJson = JsonConvert.DeserializeObject(nodesJsonText) as JObject; var features = nodesJson["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 nodeId = _nodeIdPrefix + properties["Id"].ToString().PadLeft(6, '0'); var nodeType = properties["NodeType"].ToString(); var nodeName = properties["NodeName"].ToString(); var assetStatus = properties["Status"].ToString(); if (properties["BuildTestData"].ToString() != "") { var buildCodes = properties["BuildTestData"].ToString().Split(';'); NodeBuildCodes.Add(nodeId, buildCodes); } // Add node to graph var x = ((JArray)geometry["coordinates"])[0]; var y = ((JArray)geometry["coordinates"])[1]; graphBuilder.AddNodeToGraph(nodeId, (double)x, (double)y); // Derive node and function kind int nodeKind = (int)RouteNodeKindEnum.Unknown; int nodeFunctionKind = (int)RouteNodeFunctionKindEnum.Unknown; if (nodeType == "CO") { nodeKind = (int)RouteNodeKindEnum.CentralOfficeSmall; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.SecondaryNode; } else if (nodeType == "HH") { nodeKind = (int)RouteNodeKindEnum.HandHole; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.OpenConduitPoint; } else if (nodeType == "CC") { nodeKind = (int)RouteNodeKindEnum.ConduitClosure; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.BurriedConduitPont; } else if (nodeType == "CE") { nodeKind = (int)RouteNodeKindEnum.ConduitEnd; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.BurriedConduitPont; } else if (nodeType == "SJ") { nodeKind = (int)RouteNodeKindEnum.ConduitSimpleJunction; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.BurriedConduitPont; } else if (nodeType == "FP") { nodeKind = (int)RouteNodeKindEnum.CabinetBig; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.FlexPoint; } else if (nodeType == "SP") { nodeKind = (int)RouteNodeKindEnum.CabinetSmall; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.SplicePoint; } else if (nodeType == "A") { nodeKind = (int)RouteNodeKindEnum.BuildingAccessPoint; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.SplicePoint; } else if (nodeType == "MDU") { nodeKind = (int)RouteNodeKindEnum.MultiDwellingUnit; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.ServiceDeliveryPoint; } else if (nodeType == "SDU") { nodeKind = (int)RouteNodeKindEnum.SingleDwellingUnit; nodeFunctionKind = (int)RouteNodeFunctionKindEnum.ServiceDeliveryPoint; } migrationBuilder.InsertData( table: "RouteNodes", columns: new[] { "Id", "Name", "NodeKind", "NodeFunctionKind", "GeoJsonType", "GeoJsonCoordinates", "AssetStatus" }, values: new object[] { nodeId, nodeName, nodeKind, nodeFunctionKind, geometryType, geometryCoordinates, Int32.Parse(assetStatus) }); } }