从MIF文件直接读取道路数据

string  file =   @" C:\Inetpub\wwwroot\SSWeb\node\Road.MIF " ; // 载入数据,使用绝对路径(单独制作的综合节点图层)
            StreamReader sr  =   new  StreamReader(file);
            
string  nextLine, sTmp;
            
long  nTmp, mTmp;
            nTmp 
=  mTmp  =   0 ;
            TNode fNode, cNode;
            fNode 
=  cNode  =   null ;
            
while  ((nextLine  =  sr.ReadLine())  !=   null )
            
{
                sTmp 
= nextLine.Trim();
                
if (sTmp.Length > 14 && sTmp.Substring(0,14).CompareTo("Pline Multiple"== 0)
                
{
                    nTmp 
= 0;
                    nTmp 
= Convert.ToInt32(sTmp.Substring(14));
                    
for (long i=0; i < nTmp; i++)
                    
{
                        
if ((nextLine = sr.ReadLine()) == null)
                            
break;

                        fNode 
= cNode = null;
                        mTmp 
= 0;
                        sTmp 
= nextLine.Trim();
                        mTmp 
= Convert.ToInt32(sTmp);
                        
for (long n=0; n < mTmp; n++)
                        
{
                            
if ((nextLine = sr.ReadLine()) == null)
                                
break;

                            sTmp 
= nextLine.Trim();
                            
string delimStr = " ";
                            
char [] delimiter = delimStr.ToCharArray();
                            
string [] aTmp = sTmp.Split(delimiter,2);

                            fNode 
= cNode;
                            cNode 
= new TNode();
                            cNode.Sx 
= Convert.ToDouble(aTmp[0]);
                            cNode.Sy 
= Convert.ToDouble(aTmp[1]);
                            cNode.AddChild(fNode);
                            
if (fNode != null)
                                fNode.AddChild(cNode);
                            
                            mDataList.Add(fNode);
                            mDataList.Add(cNode);
                        }

                    }

                }

                
else if (sTmp.Length > 4 && sTmp.Substring(0,5).CompareTo("Pline"== 0)
                
{
                    fNode 
= cNode = null;
                    nTmp 
= 0;
                    nTmp 
= Convert.ToInt32(sTmp.Substring(5));
                    
for (long i=0; i < nTmp; i++)
                    
{
                        
if ((nextLine = sr.ReadLine()) == null)
                            
break;

                        sTmp 
= nextLine.Trim();
                        
string delimStr = " ";
                        
char [] delimiter = delimStr.ToCharArray();
                        
string [] aTmp = sTmp.Split(delimiter,2);

                        fNode 
= cNode;
                        cNode 
= new TNode();
                        cNode.Sx 
= Convert.ToDouble(aTmp[0]);
                        cNode.Sy 
= Convert.ToDouble(aTmp[1]);
                        cNode.AddChild(fNode);
                        
if (fNode != null)
                            fNode.AddChild(cNode);

                        mDataList.Add(fNode);
                        mDataList.Add(cNode);
                    }

                }

            }

            sr.Close();

你可能感兴趣的:(文件)