예제 #1
0
 private void RestoreIsTraversed(ref List <CPoint> cptlt, ref SCG.LinkedList <int> intAllLLt)
 {
     foreach (int i in intAllLLt)
     {
         cptlt[i - 1].isTraversed = false;
     }
 }
예제 #2
0
        private void LookingForNeighboursInGridItself(ref List <CPoint> cptlt, SCG.LinkedList <int> intLLtGridContent, double dblThreshold, ref int intOutPut)
        {
            if (intLLtGridContent.Count == 0)
            {
                return;
            }
            int intCountI = 0;

            foreach (int intI  in intLLtGridContent)
            {
                int intCountJ = 0;
                foreach (int intJ in intLLtGridContent)
                {
                    if (intCountJ > intCountI)
                    {
                        double dblXDiff = Math.Abs(cptlt[intI].X - cptlt[intJ].X);
                        double dblYDiff = Math.Abs(cptlt[intI].Y - cptlt[intJ].Y);
                        if (dblXDiff <= dblThreshold && dblYDiff <= dblThreshold)
                        {
                            //cptlt[intI].intTS.Add(intJ);
                            //cptlt[intJ].intTS.Add(intI);

                            intOutPut++;
                        }
                    }
                    else
                    {
                        intCountJ++;
                    }
                }
                intCountI++;
            }
        }
예제 #3
0
 private void Initialize()
 {
     requestDataList  = new SCG.LinkedList <object[]>();
     manualResetEvent = new ST.ManualResetEvent(false);
     taskThread       = new ST.Thread(new ST.ThreadStart(ProcessRequests));
     taskThread.Start();
 }
        /// <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);
        }
예제 #5
0
        private void LookingForNeighboursInGrids(ref List <CPoint> cptlt, SCG.LinkedList <int> intLLtGridContent1, SCG.LinkedList <int> intLLtGridContent2, double dblThreshold, ref int intOutPut)
        {
            if (intLLtGridContent1.Count == 0 || intLLtGridContent1.Count == 0)
            {
                return;
            }

            foreach (int intGID1 in intLLtGridContent1)
            {
                foreach (int intGID2 in intLLtGridContent2)
                {
                    double dblXDiff = Math.Abs(cptlt[intGID1].X - cptlt[intGID2].X);
                    double dblYDiff = Math.Abs(cptlt[intGID1].Y - cptlt[intGID2].Y);
                    if (dblXDiff <= dblThreshold && dblYDiff <= dblThreshold)
                    {
                        //cptlt[intGID1].intTS.Add(intGID2);
                        //cptlt[intGID2].intTS.Add(intGID1);

                        intOutPut++;
                    }
                }
            }
        }
예제 #6
0
        //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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        private void Grids(ref List <CPoint> cptlt, double dblThreshold, double dblGridSize, ref long lngTime, ref long lngMemory, ref int intOutPut)
        {
            lngTime = System.Environment.TickCount;
            CEnvelope pEnvelope = CGeoFunc.GetEnvelope(cptlt);

            dblGridSize = Math.Max(dblGridSize, dblThreshold);
            int intRow = Convert.ToInt32(Math.Truncate(pEnvelope.Height / dblGridSize)) + 1;  //+1, so that the bordered point can be covered
            int intCol = Convert.ToInt32(Math.Truncate(pEnvelope.Width / dblGridSize)) + 1;   //+1, so that the bordered point can be covered

            long lngTime2 = System.Environment.TickCount;

            SCG.LinkedList <int>[,] aintLLtGridContent = new SCG.LinkedList <int> [intRow, intCol];
            for (int i = 0; i < intRow; i++)
            {
                for (int j = 0; j < intCol; j++)
                {
                    aintLLtGridContent[i, j] = new SCG.LinkedList <int>();
                }
            }
            lngTime2 = System.Environment.TickCount - lngTime2;

            long lngTime3 = System.Environment.TickCount;

            foreach (CPoint cpt in cptlt)
            {
                int rownum = Convert.ToInt32(Math.Truncate((cpt.Y - pEnvelope.YMin) / dblGridSize));
                int colnum = Convert.ToInt32(Math.Truncate((cpt.X - pEnvelope.XMin) / dblGridSize));
                aintLLtGridContent[rownum, colnum].AddLast(cpt.GID);
            }

            for (int i = 0; i < intRow; i++)
            {
                for (int j = 0; j < intCol; j++)
                {
                    LookingForNeighboursInGridItself(ref cptlt, aintLLtGridContent[i, j], dblThreshold, ref intOutPut);

                    if (j + 1 < intCol)  //Right
                    {
                        LookingForNeighboursInGrids(ref cptlt, aintLLtGridContent[i, j], aintLLtGridContent[i, j + 1], dblThreshold, ref intOutPut);
                    }

                    if (i + 1 < intRow) //Upper
                    {
                        if (j - 1 >= 0) //UpperLeft
                        {
                            LookingForNeighboursInGrids(ref cptlt, aintLLtGridContent[i, j], aintLLtGridContent[i + 1, j - 1], dblThreshold, ref intOutPut);
                        }
                        //UpperMiddle
                        LookingForNeighboursInGrids(ref cptlt, aintLLtGridContent[i, j], aintLLtGridContent[i + 1, j], dblThreshold, ref intOutPut);

                        if (j + 1 < intCol)  //UpperRight
                        {
                            LookingForNeighboursInGrids(ref cptlt, aintLLtGridContent[i, j], aintLLtGridContent[i + 1, j + 1], dblThreshold, ref intOutPut);
                        }
                    }
                }
            }
            lngTime3  = System.Environment.TickCount - lngTime3;
            lngTime   = System.Environment.TickCount - lngTime;
            lngMemory = GC.GetTotalMemory(true) - lngMemory;
            ////Dispose
            //for (int i = 0; i < intRow; i++)
            //{
            //    for (int j = 0; j < intCol; j++)
            //    {
            //        aintLLtGridContent[i, j].Dispose();
            //    }

            //}
        }