/// <summary> /// 提取对应线段 /// </summary> /// <param name="frcpl">大比例尺线状要素</param> /// <param name="tocpl">小比例尺线状要素</param> /// <param name="pCorrespondBendLt">对应弯曲列表</param> /// <returns>对应线段</returns> /// <remarks></remarks> public static SCG.LinkedList <CCorrSegment> DetectCorrespondSegment(CPolyline frcpl, CPolyline tocpl, List <CCorrespondBend> pCorrespondBendLt) { //提取对应弯曲的首尾点为对应特征点 SortedList <double, CCorrCpts> pCorrespondingCptSlt = new SortedList <double, CCorrCpts>(new CCmpDbl()); CCorrCpts pStartCorrespondingCpt0 = new CCorrCpts(frcpl.CptLt[0], tocpl.CptLt[0]); //第一对对应特征点 CCorrCpts pEndCorrespondingCpt0 = new CCorrCpts(frcpl.CptLt[frcpl.CptLt.Count - 1], tocpl.CptLt[tocpl.CptLt.Count - 1]); //第二对对应特征点 pCorrespondingCptSlt.Add(0, pStartCorrespondingCpt0); pCorrespondingCptSlt.Add(1, pEndCorrespondingCpt0); //其它对应特征点 for (int i = 0; i < pCorrespondBendLt.Count; i++) { CCorrCpts pStartCorrespondingCpt = new CCorrCpts(pCorrespondBendLt[i].CFromBend.CptLt[0], pCorrespondBendLt[i].CToBend.CptLt[0]); CCorrCpts pEndCorrespondingCpt = new CCorrCpts( pCorrespondBendLt[i].CFromBend.CptLt[pCorrespondBendLt[i].CFromBend.CptLt.Count - 1], pCorrespondBendLt[i].CToBend.CptLt[pCorrespondBendLt[i].CToBend.CptLt.Count - 1]); pCorrespondingCptSlt.Add(pCorrespondBendLt[i].CFromBend.dblStartRL, pStartCorrespondingCpt); pCorrespondingCptSlt.Add(pCorrespondBendLt[i].CFromBend.dblEndRL, pEndCorrespondingCpt); } //查找并删除重复对应特征点 for (int i = pCorrespondingCptSlt.Count - 1; i > 0; i--) { CPoint frcpt2 = pCorrespondingCptSlt.Values[i].FrCpt; CPoint tocpt2 = pCorrespondingCptSlt.Values[i].ToCpt; CPoint frcpt1 = pCorrespondingCptSlt.Values[i - 1].FrCpt; CPoint tocpt1 = pCorrespondingCptSlt.Values[i - 1].ToCpt; if (frcpt1.Equals2D(frcpt2) && tocpt1.Equals2D(tocpt2)) { pCorrespondingCptSlt.RemoveAt(i); } } //以对应特征点为断点分割原始线段,得到对应线段 SCG.LinkedList <CCorrSegment> pCorrespondSegmentLk = new SCG.LinkedList <CCorrSegment>(); //中间的对应线段 for (int i = 0; i < pCorrespondingCptSlt.Count - 1; i++) { CPolyline frSegment = frcpl.GetSubPolyline(pCorrespondingCptSlt.Values[i].FrCpt, pCorrespondingCptSlt.Values[i + 1].FrCpt); CPolyline toSegment = tocpl.GetSubPolyline(pCorrespondingCptSlt.Values[i].ToCpt, pCorrespondingCptSlt.Values[i + 1].ToCpt); pCorrespondSegmentLk.AddLast(new CCorrSegment(frSegment, toSegment)); } return(pCorrespondSegmentLk); }
//Breadth First Search private SCG.LinkedList <int> BSF(CPoint Originalcpt, ref List <CPoint> cptlt, ref SCG.LinkedList <int> intTargetLLt, ref SCG.LinkedList <int> intAllLLt, double dblThreshold, ref int intOutPut) { SCG.LinkedList <int> intnewLLt = new SCG.LinkedList <int>(); //double dblThresholdDT = (1 + Math.Sqrt(2)) / 2 * dblThreshold; //double dblThresholdDT = Math.Sqrt(2) * dblThreshold; double dblThresholdDT = ((Math.Sqrt(7) + 1) / 2) * dblThreshold; foreach (int i in intTargetLLt) { //CPoint cpt = cptlt[i - 1]; //double dblXDiff = Math.Abs(cpt.pTinNode.X - Originalcpt.pTinNode.X); //double dblYDiff = Math.Abs(cpt.pTinNode.Y - Originalcpt.pTinNode.Y); //if (dblXDiff <= dblThreshold && dblYDiff <= dblThreshold) //{ // intOutPut++; // //Originalcpt.intTS.Add(cpt.pTinNode.Index); //Note that if one element is already in "intTS", a new element with the same value will not be added and no exception will be thrown // //cpt.intTS.Add(Originalcpt.pTinNode.Index); //Note that if one element is already in "intTS", a new element with the same value will not be added and no exception will be thrown // ITinNodeArray pTinNodeArray = cpt.pTinNode.GetAdjacentNodes(); // for (int j = 0; j < pTinNodeArray.Count; j++) // { // ITinNode pAdjacentNode = pTinNodeArray.get_Element(j); // if (cptlt[pAdjacentNode.Index - 1].isTraversed == false) // { // cptlt[pAdjacentNode.Index - 1].isTraversed = true; // intnewLLt.Add(pAdjacentNode.Index); // } // } //} CPoint cpt = cptlt[i - 1]; double dblXDiff = Math.Abs(cpt.pTinNode.X - Originalcpt.pTinNode.X); double dblYDiff = Math.Abs(cpt.pTinNode.Y - Originalcpt.pTinNode.Y); if (dblXDiff <= dblThreshold && dblYDiff <= dblThreshold) { intOutPut++; //Originalcpt.intTS.Add(cpt.pTinNode.Index); //Note that if one element is already in "intTS", a new element with the same value will not be added and no exception will be thrown //cpt.intTS.Add(Originalcpt.pTinNode.Index); //Note that if one element is already in "intTS", a new element with the same value will not be added and no exception will be thrown } if (dblXDiff <= dblThresholdDT && dblYDiff <= dblThresholdDT) { ITinNodeArray pTinNodeArray = cpt.pTinNode.GetAdjacentNodes(); for (int j = 0; j < pTinNodeArray.Count; j++) { ITinNode pAdjacentNode = pTinNodeArray.get_Element(j); if (cptlt[pAdjacentNode.Index - 1].isTraversed == false) { cptlt[pAdjacentNode.Index - 1].isTraversed = true; intnewLLt.AddLast(pAdjacentNode.Index); intAllLLt.AddLast(pAdjacentNode.Index); } } } } //intTargetLLt.Dispose(); return(intnewLLt); }
private List <CPoint> LookingForNeighboursDT(IFeatureLayer pFeatureLayer, double dblThreshold, int intPtNumLast, ref long lngTimeForSearching, ref long lngTimeForDT, ref long lngMemory, ref long lngMemoryDT, ref long lngMemoryDTProcess, ref int intOutPut, string strTINPath) { lngMemory = GC.GetTotalMemory(true); //lngMemoryDT = GC.GetTotalMemory(true); //lngMemoryDTProcess = Process.GetProcessesByName("ContinuousGeneralizer.vshost")[0].WorkingSet64; long lngStartTime = System.Environment.TickCount; //record the start time //lngMemoryDT = Process.GetProcessesByName("ContinuousGeneralizer.vshost")[0].WorkingSet64; //Process .GetProcessesByName("ContinuousGeneralizer.vshost")[0]. //create TIN IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IGeoDataset pGDS = (IGeoDataset)pFeatureClass; IEnvelope pEnv = (IEnvelope)pGDS.Extent; pEnv.SpatialReference = pGDS.SpatialReference; IFields pFields = pFeatureClass.Fields; IField pHeightFiled = new FieldClass(); try { pHeightFiled = pFields.get_Field(pFields.FindField("Id")); } catch (Exception) { pHeightFiled = pFields.get_Field(pFields.FindField("ID")); throw; } //ITinWorkspace ITinEdit pTinEdit = new TinClass(); pTinEdit.InitNew(pEnv); object Missing = Type.Missing; pTinEdit.AddFromFeatureClass(pFeatureClass, null, pHeightFiled, null, esriTinSurfaceType.esriTinHardLine, ref Missing); lngTimeForDT = System.Environment.TickCount - lngStartTime; //Time for constructing DT //long lngMemoryafterTinEdit = GC.GetTotalMemory(false) - lngMemoryDT; //GC.Collect(); //lngMemoryDT = GC.GetTotalMemory(true) - lngMemoryDT; //lngMemoryDTProcess = Process.GetProcessesByName("ContinuousGeneralizer.vshost")[0].WorkingSet64 - lngMemoryDTProcess; //C5.LinkedList<int> intLLt = new C5.LinkedList<int>(); ITinNodeCollection pTinNodeCollection = (ITinNodeCollection)pTinEdit; List <CPoint> CptLt = new List <CPoint>(pTinNodeCollection.NodeCount); for (int i = 1; i <= pTinNodeCollection.NodeCount; i++) //i=1-4: super node { ITinNode pNode = pTinNodeCollection.GetNode(i); CPoint cpt = new CPoint(pNode); //cpt.intTS = new C5.TreeSet<int>(); CptLt.Add(cpt); } //long lngMemoryafterfetching = GC.GetTotalMemory(true); //lngMemoryDT = GC.GetTotalMemory(true) - lngMemoryDT; //Looking for neighbours based on Breadth First Search if (intPtNumLast != -1) { dblThreshold = dblThreshold * Math.Pow(Convert.ToDouble(intPtNumLast) / Convert.ToDouble(CptLt.Count - 4), 0.5); //---------------dblThreshold------------------------------------------------// //Math.Pow(1.8 / Convert.ToDouble(CptLt.Count - 4), 0.5);//---------------dblThreshold------------------------------------------------// } //double dblThresholdDT = (1 + Math.Sqrt(2)) / 2 * dblThreshold; lngTimeForSearching = System.Environment.TickCount; //the start time SCG.LinkedList <int> intTargetLLt = new SCG.LinkedList <int>(); SCG.LinkedList <int> intAllLLt = new SCG.LinkedList <int>(); for (int i = 0; i < CptLt.Count; i++) { CptLt[i].isTraversed = true; intTargetLLt = new SCG.LinkedList <int>(); intTargetLLt.AddLast(CptLt[i].pTinNode.Index); intAllLLt = new SCG.LinkedList <int>(); intAllLLt.AddLast(CptLt[i].pTinNode.Index); while (intTargetLLt.Count > 0) { intTargetLLt = BSF(CptLt[i], ref CptLt, ref intTargetLLt, ref intAllLLt, dblThreshold, ref intOutPut); } intOutPut--; //the point will take itself as a close point, so we have to minus 1 //CptLt[i].intTS.Remove(CptLt[i].pTinNode.Index); RestoreIsTraversed(ref CptLt, ref intAllLLt); //intAllLLt.Dispose(); } //long lngMemoryaftersearch = GC.GetTotalMemory(true); lngTimeForSearching = System.Environment.TickCount - lngTimeForSearching; //the result time lngMemory = GC.GetTotalMemory(true) - lngMemory; pTinEdit.SaveAs(strTINPath + "\\" + pFeatureLayer.Name, true); long lngFileSize = CHelpFunc.GetDirectoryLength(strTINPath + "\\" + pFeatureLayer.Name); lngMemory += lngFileSize; lngMemoryDT = lngFileSize; return(CptLt); }