Example #1
0
        /// <summary>
        /// 创建Tin文件
        /// </summary>
        /// <param name="pFeatureClass">要素类</param>
        private void CreateTinFromFeature(IFeatureClass pFeatureClass)
        {
            try
            {
                IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
                ESRI.ArcGIS.Geometry.IEnvelope pExtent = pGeoDataset.Extent;
                pExtent.SpatialReference = pGeoDataset.SpatialReference;

                //获得高程值
                IFields pFields = pFeatureClass.Fields;
                IField  pHeightField;
                pHeightField = pFields.get_Field(3);

                ITinEdit pTinEdit = new TinClass();
                pTinEdit.InitNew(pExtent);
                object Missing     = Type.Missing;
                object pbUseShapeZ = Missing;
                object pOverWrite  = Missing;

                pTinEdit.AddFromFeatureClass(pFeatureClass, null, pHeightField, null, esriTinSurfaceType.esriTinMassPoint, ref pbUseShapeZ);

                pTinEdit.SaveAs(Application.StartupPath + "\\Convert\\TemTIN\\" + this.Random, ref pOverWrite);
                pTinEdit.StopEditing(false);
                CreateContourData(Application.StartupPath + "\\Convert\\TemTIN");
            }
            catch (Exception)
            {
            }
        }
Example #2
0
        /// <summary>
        /// 根据生成的featureclass动态生成tin
        /// </summary>
        /// <params name="pFeatureClass"></params>
        /// <params name="pField"></params>
        /// <params name="pPath"></params>
        /// <returns></returns>
        private ITin CreateTin(IFeatureClass pFeatureClass, IField pField, string pPath)
        {
            IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
            ITinEdit    pTinEdit    = new TinClass();

            pTinEdit.InitNew(pGeoDataset.Extent);
            object pObj = Type.Missing;

            pTinEdit.AddFromFeatureClass(pFeatureClass, null, pField, null, esriTinSurfaceType.esriTinMassPoint, ref pObj);
            pTinEdit.SaveAs(pPath, ref pObj);
            pTinEdit.Refresh();
            return(pTinEdit as ITin);
        }
Example #3
0
        /// <summary>
        /// 高程点生成TIN
        /// </summary>
        /// <param name="featureClass">点要素</param>
        /// <param name="path">保存路径</param>
        /// <returns>TIN数据</returns>
        public static ITin CreateTIN(IFeatureClass featureClass, string path)
        {
            string      folder     = System.IO.Path.GetDirectoryName(path);
            IGeoDataset geoDataset = featureClass as IGeoDataset;
            IField      zField     = featureClass.Fields.get_Field(4);//高程字段
            ITinEdit    tinEdit    = new TinClass();

            tinEdit.InitNew(geoDataset.Extent);
            tinEdit.AddFromFeatureClass(featureClass, null, zField, null, esriTinSurfaceType.esriTinMassPoint);
            if (System.IO.Directory.Exists(folder + "\\tin"))
            {
                (new System.IO.DirectoryInfo(folder + "\\tin")).Delete(true);
            }
            tinEdit.SaveAs(folder + "\\tin");
            tinEdit.Refresh();
            tinEdit.StopEditing(true);
            return(tinEdit as ITin);
        }
Example #4
0
        protected override void OnClick()
        {
            try
            {
                string shpFilePath = string.Format(@"C:\temp\contour datas");
                string shpFileName = "contour2.shp"; // height data

                IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
                IWorkspace workspace = workspaceFactory.OpenFromFile(shpFilePath, 0);
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                IFeatureClass pFeatureClass = featureWorkspace.OpenFeatureClass(shpFileName);
                IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pFeatureClass;
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.WhereClause = "";

                IEnvelope pEnv = pFeatureLayer.AreaOfInterest;
                IGeoDataset pGDS = (IGeoDataset)pFeatureLayer.FeatureClass;
                ISpatialReference pSR = pGDS.SpatialReference;
                IGeometry pGeom = pEnv;
                pGeom.Project(pSR);
                ITinEdit pTinEdit = new TinClass();
                pTinEdit.InitNew(pEnv);
                IFields pFields = pFeatureClass.Fields;
                IField pFiled = pFields.get_Field(pFields.FindField("HSL"));
                object Missing = Type.Missing;
                esriTinSurfaceType pTinSurface = esriTinSurfaceType.esriTinHardLine;
                pTinEdit.AddFromFeatureClass(pFeatureClass, pQueryFilter, pFiled, pFiled, pTinSurface, ref Missing);
                string outputFolderPath = @"C:\temp\Output\";
                string tinFolderName = "tin_data";
                pTinEdit.SaveAs(outputFolderPath + tinFolderName, ref Missing);
                MessageBox.Show("end");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            ArcMap.Application.CurrentTool = null;
        }
Example #5
0
        protected override void OnClick()
        {
            try
            {
                string shpFilePath = string.Format(@"C:\temp\contour datas");
                string shpFileName = "contour2.shp"; // height data

                IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
                IWorkspace        workspace        = workspaceFactory.OpenFromFile(shpFilePath, 0);
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                IFeatureClass     pFeatureClass    = featureWorkspace.OpenFeatureClass(shpFileName);
                IFeatureLayer     pFeatureLayer    = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pFeatureClass;
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.WhereClause = "";

                IEnvelope         pEnv  = pFeatureLayer.AreaOfInterest;
                IGeoDataset       pGDS  = (IGeoDataset)pFeatureLayer.FeatureClass;
                ISpatialReference pSR   = pGDS.SpatialReference;
                IGeometry         pGeom = pEnv;
                pGeom.Project(pSR);
                ITinEdit pTinEdit = new TinClass();
                pTinEdit.InitNew(pEnv);
                IFields            pFields     = pFeatureClass.Fields;
                IField             pFiled      = pFields.get_Field(pFields.FindField("HSL"));
                object             Missing     = Type.Missing;
                esriTinSurfaceType pTinSurface = esriTinSurfaceType.esriTinHardLine;
                pTinEdit.AddFromFeatureClass(pFeatureClass, pQueryFilter, pFiled, pFiled, pTinSurface, ref Missing);
                string outputFolderPath = @"C:\temp\Output\";
                string tinFolderName    = "tin_data";
                pTinEdit.SaveAs(outputFolderPath + tinFolderName, ref Missing);
                MessageBox.Show("end");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            ArcMap.Application.CurrentTool = null;
        }
Example #6
0
        /// <summary>
        /// 创建Tin文件
        /// </summary>
        /// <param name="pFeatureClass">要素类</param>
        private void CreateTinFromFeature(IFeatureClass pFeatureClass)
        {
            try
            {
                IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
                ESRI.ArcGIS.Geometry.IEnvelope pExtent = pGeoDataset.Extent;
                pExtent.SpatialReference = pGeoDataset.SpatialReference;

                //获得高程值
                IFields pFields = pFeatureClass.Fields;
                IField pHeightField;
                pHeightField = pFields.get_Field(3);

                ITinEdit pTinEdit = new TinClass();
                pTinEdit.InitNew(pExtent);
                object Missing = Type.Missing;
                object pbUseShapeZ = Missing;
                object pOverWrite = Missing;

                pTinEdit.AddFromFeatureClass(pFeatureClass, null, pHeightField, null, esriTinSurfaceType.esriTinMassPoint, ref pbUseShapeZ);

                pTinEdit.SaveAs(Application.StartupPath + "\\Convert\\TemTIN\\" + this.Random, ref pOverWrite);
                pTinEdit.StopEditing(false);
                CreateContourData(Application.StartupPath + "\\Convert\\TemTIN");
            }
            catch (Exception)
            {

            }
        }
Example #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);
        }
Example #8
0
        public void DEMToTIN(IRaster iRaster, string tinFileName)
        {
            try
            {
                //***************生成TIN模型*********************************************
                IGeoDataset           pGeoData   = iRaster as IGeoDataset;
                IEnvelope             pExtent    = pGeoData.Extent;
                IRasterBandCollection pRasBC     = iRaster as IRasterBandCollection;
                IRasterBand           pRasBand   = pRasBC.Item(0);
                IRawPixels            pRawPixels = pRasBand as IRawPixels;
                IRasterProps          pProps     = pRawPixels as IRasterProps;
                int    iWid       = pProps.Width;
                int    iHei       = pProps.Height;
                double w          = iWid / 1000.0f;
                double h          = iHei / 1000.0f;
                IPnt   pBlockSize = new DblPntClass();
                bool   IterationFlag;

                if (w < 1 && h < 1) //横纵都小于1000个像素
                {
                    pBlockSize.X  = iWid;
                    pBlockSize.Y  = iHei;
                    IterationFlag = false;
                }
                else
                {
                    pBlockSize.X  = 1001.0f;
                    pBlockSize.Y  = 1001.0f;
                    IterationFlag = true;
                }
                double cellsize = 0.0f;             //栅格大小

                IPnt pPnt1 = pProps.MeanCellSize(); //栅格平均大小
                cellsize = pPnt1.X;
                ITinEdit pTinEdit = new TinClass() as ITinEdit;
                pTinEdit.InitNew(pExtent);
                ISpatialReference pSpatial = pGeoData.SpatialReference;
                pExtent.SpatialReference = pSpatial;
                IPnt pOrigin           = new DblPntClass();
                IPnt pPixelBlockOrigin = new DblPntClass();
                //栅格左上角像素中心坐标
                double bX = pBlockSize.X;
                double bY = pBlockSize.Y;
                pBlockSize.SetCoords(bX, bY);
                IPixelBlock   pPixelBlock   = pRawPixels.CreatePixelBlock(pBlockSize);
                object        nodata        = pProps.NoDataValue; //无值标记
                ITinAdvanced2 pTinNodeCount = pTinEdit as ITinAdvanced2;
                int           nodeCount     = pTinNodeCount.NodeCount;
                object        vtMissing     = Type.Missing;
                object        vPixels       = null; //格子
                double        m_zTolerance  = 0;
                if (!IterationFlag)                 //当为一个处理单元格子时;(w < 1 && h < 1) //横纵都小于1000个像素
                {
                    pPixelBlockOrigin.SetCoords(0.0f, 0.0f);
                    pRawPixels.Read(pPixelBlockOrigin, pPixelBlock);
                    vPixels = pPixelBlock.get_SafeArray(0);
                    double xMin = pExtent.XMin;
                    double yMax = pExtent.YMax;
                    pOrigin.X = xMin + cellsize / 2;
                    pOrigin.Y = yMax - cellsize / 2;
                    bX        = pOrigin.X;
                    bY        = pOrigin.Y;
                    pTinEdit.AddFromPixelBlock(bX, bY, cellsize, cellsize, nodata, vPixels, m_zTolerance, ref vtMissing, out vtMissing);
                }
                else //当有多个处理单元格时,依次循环处理每个单元格
                {
                    int i = 0, j = 0, count = 0;
                    int FirstGoNodeCount = 0;

                    //while (nodeCount != FirstGoNodeCount)
                    //{
                    count++;
                    nodeCount = pTinNodeCount.NodeCount;
                    int bwidth = 0; int bheight = 0;
                    //依次循环处理
                    for (i = 0; i < (int)h + 1; i++)
                    {
                        if (i < (int)h)
                        {
                            bheight = 1000;
                        }
                        else
                        {
                            bheight = iHei - 1000 * i;
                        }
                        for (j = 0; j < (int)w + 1; j++)
                        {
                            if (j < (int)w)
                            {
                                bwidth = 1000;
                            }
                            else
                            {
                                bwidth = iWid - 1000 * j;
                            }
                            pBlockSize.SetCoords(bwidth, bheight);
                            pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize);


                            double bX1, bY1, xMin1, yMax1;
                            bX1 = pBlockSize.X;
                            bY1 = pBlockSize.Y;
                            pPixelBlockOrigin.SetCoords(j * 1000, i * 1000);

                            pRawPixels.Read(pPixelBlockOrigin, pPixelBlock);
                            vPixels = pPixelBlock.get_SafeArray(0);
                            xMin1   = pExtent.XMin;
                            yMax1   = pExtent.YMax;
                            //bX1 = pBlockSize.X;
                            //bY1 = pBlockSize.Y;
                            pOrigin.X = xMin1 + j * 1000 * cellsize + cellsize / 2.0f;
                            pOrigin.Y = yMax1 - i * 1000 * cellsize - cellsize / 2.0f;
                            bX1       = pOrigin.X;
                            bY1       = pOrigin.Y;
                            pTinEdit.AddFromPixelBlock(bX1, bY1, cellsize, cellsize, nodata, vPixels, m_zTolerance, ref vtMissing, out vtMissing);
                            FirstGoNodeCount = pTinNodeCount.NodeCount;
                        }
                    }
                    //}
                }
                //保存TIN文件
                pTinEdit.SaveAs(tinFileName, ref vtMissing);
                pTinEdit.StopEditing(true);
                m_pTin = pTinEdit as ITin;
                MessageBox.Show("转换成功!");
            }
            catch (SystemException e)
            {
                MessageBox.Show(e.Message);
            }
        }
 /// <summary>
 /// 根据生成的featureclass动态生成tin
 /// </summary>
 /// <params name="pFeatureClass"></params>
 /// <params name="pField"></params>
 /// <params name="pPath"></params>
 /// <returns></returns>
 private ITin CreateTin(IFeatureClass pFeatureClass, IField pField, string pPath)
 {
     IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
     ITinEdit pTinEdit = new TinClass();
       pTinEdit.InitNew(pGeoDataset.Extent);
       object pObj = Type.Missing;
       pTinEdit.AddFromFeatureClass(pFeatureClass, null, pField, null, esriTinSurfaceType.esriTinMassPoint, ref pObj);
       pTinEdit.SaveAs(pPath, ref pObj);
       pTinEdit.Refresh();
      return pTinEdit as ITin;
 }