//*Constructors public EditNodes(string NetPath) : base(NetPath) { FileName = "nodes"; using (StreamReader ReadFile = new StreamReader((NetPath + "\\" + FileName)))// open the paths file { try { string FileLine; N_W_Node temp = new N_W_Node(); while ((FileLine = ReadFile.ReadLine()) != null)//read the file line by line { if (FileLine.Contains("node ")) { string[] splitline = FileLine.Split(new Char[] { ' ' }); // split the line up into an array of strings string NodeNum = splitline[1]; string[] splitline2 = FileLine.Split(new Char[] { 't', 'm', ',' }); // split the line up into an array of strings double X = Convert.ToDouble(splitline2[1]); double Y = Convert.ToDouble(splitline2[3]); double Z = Convert.ToDouble(splitline2[5]); //temp = new N_W_Node(NodeNum,X,Y,Z); NodeList.Add(new N_W_Node(NodeNum, X, Y, Z)); } } } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The pathroutes file could not be read:"); Console.WriteLine(e.Message); } } }
private double NodeDistanceMeasure(N_W_Node Node1, N_W_Node Node2) { double X = Math.Abs(Node1.X - Node2.X); double Y = Math.Abs(Node1.Y - Node2.Y); return(Math.Pow((Math.Pow(X, 2) + Math.Pow(Y, 2)), 0.5)); }
//*Function to read Nodes data from database private void ReadNodesFromGISdb() { List <N_W_Node> LN1 = new List <N_W_Node>(); OdbcCommand C1 = new OdbcCommand("SELECT asText(the_geom), \"TOID\" FROM \"Road_Node_point_Shrunk\";", Connect); Connect.Open(); OdbcDataReader Reader = C1.ExecuteReader(); while (Reader.Read() == true) { String[] SplitLine = Reader.GetString(0).Split(new Char[] { '(', ' ', ')' }); String Sname = Reader.GetString(1); N_W_Node TempNode = new N_W_Node(Sname, Convert.ToDouble(SplitLine[1]), Convert.ToDouble(SplitLine[2]), 0); TempNode.ShrinkName(); LN1.Add(TempNode); } Connect.Close(); NodesList = LN1; }
public double DistToNode(N_W_Node OtherNode) { return(Math.Sqrt(Math.Pow(X - OtherNode.X, 2) + Math.Pow(Y - OtherNode.Y, 2) + Math.Pow(Z - OtherNode.Z, 2))); }
//Function to get additional nodes from link steps and to get the mini links in between. private void SuperProcessLinksData() { OdbcCommand C2 = new OdbcCommand("SELECT \"START_NODE\",\"END_NODE\",\"LEGEND\",astext(the_geom),\"TOID\" FROM \"Road_Link_polyline_Shrunk\";", Connect); Connect.Open(); OdbcDataReader R2 = C2.ExecuteReader(); while (R2.Read() == true) { //Check for membership of One way table************************** String LinkTOID = R2.GetString(4); OdbcCommand C3 = new OdbcCommand("SELECT \"DIR_LINK\" FROM \"Road_Route_Info_polyline\" WHERE \"DIR_LINK\" LIKE '%" + LinkTOID + "' AND \"LEGEND\" LIKE 'One way%';", Connect); OdbcDataReader R3 = C3.ExecuteReader(); int CountCheck = 0; String OneWayLine = null; try { while (R3.Read() == true) { OneWayLine = R3.GetString(0); CountCheck++; } if (CountCheck > 1) { throw new Exception("Multiple correlations were found between the links table and the one way table"); } } catch (Exception e) { Console.WriteLine(e); } //*************************************************************** //Set up road catagory******************************************* String Legend = R2.GetString(2); int Catagory = 1; bool OneWay = false; bool Reverse = false; if (Legend.Contains("dual")) { Catagory = 2; } if (OneWayLine != null) { OneWay = true; if (OneWayLine.Contains("-")) { Reverse = true; } } //*************************************************************** //Set up start and end Nodes************************************* //Char[] Csnode = R2.GetString(0).ToCharArray(9, 7); String FirstNode = R2.GetString(0); //Char[] Cenode = R2.GetString(1).ToCharArray(9, 7); String SecondNode = R2.GetString(1); String GeoSt = R2.GetString(3); List <String[]> NodeCoordinates = GeometryToPoints(GeoSt); int NumberOfNodes = NodeCoordinates.Count; int FinalIndex = NumberOfNodes - 1; String Ssnode, Senode; if (Reverse == true) { NodeCoordinates.Reverse(); Ssnode = SecondNode; Senode = FirstNode; } else { Ssnode = FirstNode; Senode = SecondNode; } N_W_Node StartNode = new N_W_Node(Ssnode, Convert.ToDouble(NodeCoordinates[0][0]), Convert.ToDouble(NodeCoordinates[0][1]), 0); N_W_Node EndNode = new N_W_Node(Senode, Convert.ToDouble(NodeCoordinates[FinalIndex][0]), Convert.ToDouble(NodeCoordinates[FinalIndex][1]), 0); StartNode.ShrinkName(); EndNode.ShrinkName(); N_W_Node LastNode = StartNode; String ANodeName = ""; //****************************************************************** for (int i = 1; i < FinalIndex; i++) { ANodeName = ("A" + AnodeCounter.ToString("00000")); N_W_Node NewNode = new N_W_Node(ANodeName, Convert.ToDouble(NodeCoordinates[i][0]), Convert.ToDouble(NodeCoordinates[i][1]), 0); double NodeDistS = NodeDistanceMeasure(NewNode, StartNode); double NodeDistE = NodeDistanceMeasure(NewNode, EndNode); double NodeDistL = NodeDistanceMeasure(NewNode, LastNode); if (NodeDistS > 5 && NodeDistE > 5 && NodeDistL > 5) { NodesList.Add(NewNode); N_W_Link NewLink = new N_W_Link(LastNode.NodeNum, NewNode.NodeNum, Catagory, OneWay); LinksList.Add(NewLink); LastNode = NewNode; AnodeCounter++; } } N_W_Link LastLink = new N_W_Link(LastNode.NodeNum, EndNode.NodeNum, Catagory, OneWay); LinksList.Add(LastLink); } Connect.Close(); }