Ejemplo n.º 1
0
        //*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;
        }
Ejemplo n.º 2
0
        //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();
        }