Example #1
0
 public IFeatureLayer CreateRasterContour(IRaster raster)
 {
     try
     {
         ISurfaceOp  pSurface    = new RasterSurfaceOpClass();
         object      BaseHeight  = Type.Missing;
         IGeoDataset pGeoDataset = raster as IGeoDataset;
         double      interval    = Convert.ToDouble(txtContour.Text);
         if (interval <= 0)
         {
             MessageBox.Show("请指定大于0的正数!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return(null);
         }
         IGeoDataset   pContour       = pSurface.Contour(pGeoDataset, interval, ref BaseHeight);
         IFeatureLayer pFContourLayer = new FeatureLayerClass();
         pFContourLayer.FeatureClass = pContour as IFeatureClass;
         // IFeatureDataConverter pFeatureDataConvert = new FeatureDataConverter();
         OperateConvertToShape(m_ResultPath, pFContourLayer.FeatureClass);
         return(pFContourLayer);
     }
     catch (SystemException e)
     {
         MessageBox.Show(e.Message);
         return(null);
     }
 }
Example #2
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int    startX, endX;
            string shpDir;

            try
            {
                if (bDataPath == true)
                {
                    fileName = txtOutputData.Text;
                    shpDir   = fileName.Substring(0, fileName.LastIndexOf("\\"));
                    startX   = fileName.LastIndexOf("\\");
                    endX     = fileName.Length;
                    shpFile  = fileName.Substring(startX + 1, endX - startX - 1);
                }
                else
                {
                    shpDir  = txtOutputData.Text;
                    shpFile = "х╚ох¤▀";
                }
                if (m_pRasterLyr != null)
                {
                    double        dInterval        = Convert.ToDouble(txtConInterval.Text);
                    double        dBaseLine        = Convert.ToDouble(txtBaseLine.Text);
                    object        objBaseLine      = dBaseLine;
                    ISurfaceOp    pRasterSurfaceOp = new RasterSurfaceOpClass();
                    IRaster       pInRaster        = m_pRasterLyr.Raster;
                    IFeatureClass pOutFClass       = pRasterSurfaceOp.Contour(pInRaster as IGeoDataset, dInterval, ref objBaseLine) as IFeatureClass;
                    //2. QI to IDataset
                    IDataset pFDS = pOutFClass as IDataset;
                    //3. Get a shapefile workspace
                    IWorkspaceFactory pSWF = new  ShapefileWorkspaceFactoryClass();
                    IFeatureWorkspace pFWS = pSWF.OpenFromFile(shpDir, 0) as IFeatureWorkspace;
                    //4. Copy contour output to a new shapefile
                    IWorkspace pWS = pFWS as IWorkspace;
                    if (pWS.Exists() == true)
                    {
                        Utility.DelFeatureFile(shpDir, shpFile + ".shp");
                    }
                    pFDS.Copy(shpFile, pFWS as IWorkspace);
                    IFeatureLayer pFeatLyr = new FeatureLayerClass();
                    pFeatLyr.FeatureClass = pOutFClass;
                    pFeatLyr.Name         = pOutFClass.AliasName;
                    pFeatLyr.Visible      = true;
                    pMainFrm.getMapControl().AddLayer(pFeatLyr, 0);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #3
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int startX, endX;
            string shpDir;
            try
            {
                if (bDataPath == true)
                {
                    fileName=txtOutputData.Text;
                    shpDir =fileName.Substring(0, fileName.LastIndexOf("\\"));
                    startX=fileName.LastIndexOf("\\");
                    endX=fileName.Length;
                    shpFile=fileName.Substring(startX+1,endX-startX-1);
                }
                else
                {
                    shpDir=txtOutputData.Text;
                    shpFile="��ֵ��";
                }
                if (m_pRasterLyr != null)
                {
                    double dInterval=Convert.ToDouble(txtConInterval.Text);
                    double dBaseLine=Convert.ToDouble(txtBaseLine.Text);
                    object objBaseLine=dBaseLine;
                    ISurfaceOp pRasterSurfaceOp = new RasterSurfaceOpClass();
                    IRaster pInRaster = m_pRasterLyr.Raster;
                    IFeatureClass  pOutFClass= pRasterSurfaceOp.Contour(pInRaster as IGeoDataset , dInterval, ref objBaseLine) as IFeatureClass ;
                    //2. QI to IDataset
                    IDataset pFDS=pOutFClass as IDataset ;
                    //3. Get a shapefile workspace
                    IWorkspaceFactory pSWF=new  ShapefileWorkspaceFactoryClass();
                    IFeatureWorkspace pFWS=pSWF.OpenFromFile(shpDir,0) as IFeatureWorkspace ;
                    //4. Copy contour output to a new shapefile
                    IWorkspace pWS = pFWS as IWorkspace;
                    if (pWS.Exists() == true)
                        Utility.DelFeatureFile(shpDir, shpFile + ".shp");
                    pFDS.Copy(shpFile,pFWS as IWorkspace );
                    IFeatureLayer pFeatLyr = new FeatureLayerClass();
                    pFeatLyr.FeatureClass = pOutFClass;
                    pFeatLyr.Name = pOutFClass.AliasName;
                    pFeatLyr.Visible = true;
                    pMainFrm.getMapControl().AddLayer(pFeatLyr, 0);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //通过IDW插值生成栅格图层
            #region
            label2.Text = "正在进行IDW插值";
            IFeatureLayer pFeatureLayer_point = axMapControl1.Map.Layer[0] as IFeatureLayer;//获取点图层
            IRasterRadius pRadius             = new RasterRadiusClass();
            object        missing             = Type.Missing;
            pRadius.SetVariable(12, ref missing);
            IFeatureClassDescriptor pFCDescriptor = new FeatureClassDescriptorClass();
            pFCDescriptor.Create(pFeatureLayer_point.FeatureClass, null, "高程");

            object                     cellSizeProvider = 185.244192;
            IInterpolationOp           pInterpolationOp = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment pEnv             = pInterpolationOp as IRasterAnalysisEnvironment;
            pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
            IRaster pOutRaster;

            try
            {
                pOutRaster = pInterpolationOp.IDW(pFCDescriptor as IGeoDataset, 2, pRadius, ref missing) as IRaster;
            }
            catch
            {
                pOutRaster = pInterpolationOp.IDW(pFCDescriptor as IGeoDataset, 2, pRadius, ref missing) as IRaster;
            }

            //Add output into ArcMap as a raster layer
            RasterLayer pOutRasLayer = new RasterLayerClass();
            pOutRasLayer.CreateFromRaster(pOutRaster);
            pOutRasLayer.Name = "栅格";
            axMapControl1.Map.AddLayer(pOutRasLayer);
            #endregion
            //提取等值线
            #region
            label2.Text = "正在生成等值线...";
            IGeoDataset                pGeoDataSet                = pOutRaster as IGeoDataset;
            IWorkspaceFactory          pWorkspaceFactory1         = new ShapefileWorkspaceFactory();
            string                     file_path                  = System.IO.Path.GetDirectoryName(database_path);
            IWorkspace                 pShpWorkspace              = pWorkspaceFactory1.OpenFromFile(file_path, 0);
            ISurfaceOp2                pSurfaceOp2                = new RasterSurfaceOpClass();
            IRasterAnalysisEnvironment pRasterAnalysisEnvironment = pSurfaceOp2 as IRasterAnalysisEnvironment;

            pRasterAnalysisEnvironment.Reset();
            pRasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
            pRasterAnalysisEnvironment.OutWorkspace = pShpWorkspace;
            double      dInterval      = 0.8; //间距
            IGeoDataset pOutputDataSet = pSurfaceOp2.Contour(pGeoDataSet, dInterval, ref missing, ref missing);

            IFeatureClass pFeatureClass1 = pOutputDataSet as IFeatureClass;
            IFeatureLayer pFeatureLayer  = new FeatureLayerClass();
            pFeatureLayer.FeatureClass = pFeatureClass1;

            IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
            pGeoFeatureLayer.DisplayAnnotation = true;
            pGeoFeatureLayer.DisplayField      = "Contour";
            pGeoFeatureLayer.Name = "高程等值线";
            axMapControl1.Map.AddLayer(pGeoFeatureLayer);
            label2.Text = "完毕";
            #endregion
        }
Example #5
0
        public void CreateRasterFromPoints(IMap pMap, IFeatureLayer pp, String Path, String Name, String Field)
        {
            //1.将Shape文件读取成FeatureClass
            //2.根据FeatureClass生成IFeatureClassDescriptor
            //3.创建IRasterRaduis 对象
            //设置Cell
            //4.插值并生成表面
            object obj = null;

            IWorkspaceFactory pShapSpace;

            pShapSpace = new ShapefileWorkspaceFactory();

            IWorkspace pW;

            pW = pShapSpace.OpenFromFile(Path, 0);

            IFeatureWorkspace pFeatureWork;

            pFeatureWork = pW as IFeatureWorkspace;


            IFeatureClass pFeatureClass = pFeatureWork.OpenFeatureClass("Name");


            IGeoDataset Geo = pFeatureClass as IGeoDataset;

            object extend = Geo.Extent;

            object o = null;

            IFeatureClassDescriptor pFeatureClassDes = new FeatureClassDescriptorClass();

            pFeatureClassDes.Create(pFeatureClass, null, Field);

            IRasterRadius pRasterrad = new RasterRadiusClass();

            pRasterrad.SetVariable(10, ref obj);

            object dCell = 0.5;//可以根据不同的点图层进行设置

            IInterpolationOp Pinterpla = new RasterInterpolationOpClass();

            IRasterAnalysisEnvironment pRasterAnaEn = Pinterpla as IRasterAnalysisEnvironment;

            pRasterAnaEn.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCell);

            pRasterAnaEn.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extend, ref o);

            IGeoDataset pGRaster;

            object hh = 3;

            pGRaster = Pinterpla.IDW((IGeoDataset)pFeatureClassDes, 2, pRasterrad, ref hh);


            ISurfaceOp pSurF;

            pSurF = new RasterSurfaceOpClass();

            IGeoDataset pCour;

            object o1 = 0;

            pCour = pSurF.Contour(pGRaster, 5, ref o1);

            IFeatureLayer pLa;

            pLa = new FeatureLayerClass();

            IFeatureClass pClass = pCour as IFeatureClass;

            pLa.FeatureClass = pClass;

            pLa.Name = pClass.AliasName;

            pMap.AddLayer(pLa as ILayer);
        }
Example #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //得到dem、分成多个区域



            //获取等高线
            ILayer tLayer = this.axMapControl1.get_Layer(0);

            IRasterLayer tRasterLayer = (IRasterLayer)tLayer;

            IFeatureClass tFeatureClass = null;

            IGeoDataset tGeodataset = null;

            //使用接口参数(Raster,等高线间距,基值)
            ISurfaceOp tSurfaceop = new RasterSurfaceOpClass();

            object obj = 0;

            tGeodataset = tSurfaceop.Contour((IGeoDataset)tRasterLayer.Raster, 5, ref obj);  //等高线间距为10米

            IFeatureLayer tFeatureLayer = new FeatureLayerClass();

            //判断是否生成等高线
            if (tGeodataset != null)
            {
                tFeatureClass = (IFeatureClass)tGeodataset;

                if (tFeatureClass != null)
                {
                    tFeatureLayer.FeatureClass = tFeatureClass;

                    //this.axMapControl1.AddLayer((ILayer)tFeatureLayer);

                    //this.axMapControl1.Refresh();
                }
            }

            tFeatureLayer = deleteLine(tFeatureLayer);

            this.axMapControl1.AddLayer((ILayer)tFeatureLayer);

            this.axMapControl1.Refresh();

            /*选取特定高程的等高线*/

            //得到Feature的指针
            IQueryFilter queryFilter = new SpatialFilterClass();

            int maxContour = getMax(tFeatureLayer);

            int queryContour = maxContour - 10; //选择具体某条等高线

            queryFilter.WhereClause = "Contour = " + queryContour;

            IFeatureCursor featureCursor = tFeatureClass.Search(queryFilter, false);
            IFeature       feature       = featureCursor.NextFeature();

            //获取表的长度
            //int attributeTableLength = tFeatureClass.Fields.FindField("id");
            //string lenStr = attributeTableLength.ToString();
            //MessageBox.Show(lenStr);
            ////
            //IGeometry geometry;
            //IPolyline polyline;
            /* 筛选符合要求的等高线*/
            //while (feature!=null)
            //{
            //    IFields ptFields  =  feature.Fields;
            //    geometry =  feature.Shape;
            //    polyline =  (IPolyline)geometry;
            //    IField field = ptFields.get_Field(0);
            //    feature.get_Value();
            //    feature = featureCursor.NextFeature(); //指针移动到下一行。
            //}



            //释放游标
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);


            //获取选中的等高线
            IGeometry geometry = feature.Shape;
            IPolyline polyline = (IPolyline)geometry;

            //定义列表存储构成等高线的点的坐标、高程
            List <IPoint> contourPoint = new List <IPoint>();

            contourPoint = getPointByContourLine(polyline);

            /*将线转成面,并获取面的面积*/

            ////初始化Geoprocessor工具
            //Geoprocessor processor = new Geoprocessor();

            //FeatureToPolygon fPolygon = new FeatureToPolygon();

            //fPolygon.in_features = feature;

            //fPolygon.out_feature_class = "D:\\testData\\conPolygon.shp";

            //processor.Execute(fPolygon,null);


            //构造面,并将构成等高线的点赋予面

            //IPoint pPoint = new PointClass();

            //IPointCollection pointCollection = new PolygonClass();

            //object missing = Type.Missing;

            //double x, y;

            //for (int i = 0; i < contourPoint.Count; i++)
            //{

            //    x = contourPoint[i].X;

            //    y = contourPoint[i].Y;

            //    pPoint = new PointClass();

            //    pPoint.PutCoords(x, y);

            //    pointCollection.AddPoint(pPoint, ref missing, ref missing);

            //}

            //IPolygon pPolygon = new PolygonClass();

            ////生成面
            //pPolygon = (IPolygon)pointCollection;



            //获取指定数据库的要素类

            string path = "D:\\testPolygon";

            IFeatureClass featureclass = getFeatureClass(path);

            IFeatureLayer polyFeatureLayer = new FeatureLayerClass();

            IFeatureClass polyFeatclas = IfeatureBuffer(contourPoint, featureclass, maxContour.ToString());


            /*给由等高线生成的面添加新字段Contour(表示等高线高程值是多少)*/
            //定义新字段
            IField pField = new FieldClass();

            //字段编辑
            IFieldEdit pFieldEdit = pField as IFieldEdit;

            //新建字段名
            pFieldEdit.Name_2 = "Contour";

            //获取属性表
            IClass pTable = polyFeatclas as IClass;

            pTable.AddField(pFieldEdit);

            IFeature pFea = polyFeatclas.GetFeature(0);

            pFea.set_Value(pFea.Fields.FindField("Contour"), maxContour.ToString());

            //保存
            pFea.Store();

            polyFeatureLayer.FeatureClass = polyFeatclas;

            //将生成的面加入到当前地图控件中
            this.axMapControl1.AddLayer(polyFeatureLayer);

            this.axMapControl1.Refresh();

            IFeature polyFeature, lineFeature;

            polyFeature = polyFeatclas.GetFeature(0);

            lineFeature = feature;

            double judResult = calculate(polyFeature, lineFeature);

            double radius = fitting(contourPoint);

            RadiTBox.Text = radius.ToString();

            MessageBox.Show(judResult.ToString(), "面积/周长");
        }
Example #7
0
        public void CreateRasterFromPoints(IMap pMap, IFeatureLayer pp,String Path, String Name, String Field)
        {
            //1.��Shape�ļ���ȡ��FeatureClass
            //2.����FeatureClass����IFeatureClassDescriptor
            //3.����IRasterRaduis ����
            //����Cell
            //4.��ֵ�����ɱ���
            object obj = null;

            IWorkspaceFactory pShapSpace;

            pShapSpace = new ShapefileWorkspaceFactory();

            IWorkspace pW;

            pW = pShapSpace.OpenFromFile(Path, 0);

            IFeatureWorkspace pFeatureWork;

            pFeatureWork = pW as IFeatureWorkspace;

            IFeatureClass pFeatureClass = pFeatureWork.OpenFeatureClass("Name");

            IGeoDataset Geo = pFeatureClass as IGeoDataset;

            object extend = Geo.Extent;

            object o = null;

            IFeatureClassDescriptor pFeatureClassDes = new FeatureClassDescriptorClass();

            pFeatureClassDes.Create(pFeatureClass, null, Field);

            IRasterRadius pRasterrad = new RasterRadiusClass();

            pRasterrad.SetVariable(10, ref obj);

            object dCell = 0.5;//���Ը��ݲ�ͬ�ĵ�ͼ���������

            IInterpolationOp Pinterpla = new RasterInterpolationOpClass();

            IRasterAnalysisEnvironment pRasterAnaEn = Pinterpla as IRasterAnalysisEnvironment;

            pRasterAnaEn.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCell);

            pRasterAnaEn.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extend, ref o);

            IGeoDataset pGRaster;

            object hh = 3;

            pGRaster = Pinterpla.IDW((IGeoDataset)pFeatureClassDes , 2, pRasterrad, ref hh);

            ISurfaceOp pSurF;

            pSurF = new RasterSurfaceOpClass();

            IGeoDataset pCour;

            object  o1 = 0;

            pCour = pSurF.Contour(pGRaster, 5, ref o1);

            IFeatureLayer pLa;

            pLa = new FeatureLayerClass();

            IFeatureClass pClass = pCour as IFeatureClass;

            pLa.FeatureClass = pClass;

            pLa.Name = pClass.AliasName;

            pMap.AddLayer(pLa as ILayer);
        }
        private void iDW插值ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFeatureClass pFeatureClass = GetFeatureClass(@".\data\IDW数据", "山东20100321");

             IGeoDataset pGeoDataset = IDW(pFeatureClass, "H", 0.005, 0.05, 2);

             IRasterLayer pRasterlayer = new RasterLayerClass();

             //IRasterDataset pRs = pGeoDataset as IRasterDataset;

             pRasterlayer.CreateFromRaster(pGeoDataset as IRaster);

             axMapControl1.Map.AddLayer(pRasterlayer as ILayer);

             ISurfaceOp pSurface = new RasterSurfaceOpClass();
             object BaseHeight = Type.Missing;

             IGeoDataset p = pSurface.Contour(pGeoDataset, 2, ref BaseHeight);

             IFeatureLayer pFContourLayer = new FeatureLayerClass();

             pFContourLayer.FeatureClass = p as IFeatureClass;

             axMapControl1.AddLayer(pFContourLayer as ILayer);

             axMapControl1.Refresh();

             IWorkspaceFactory WF = new RasterWorkspaceFactoryClass();

             IWorkspace pRasterWS = WF.OpenFromFile(@".\data\IDW数据", 0);

             ISaveAs pSaveAs = (ISaveAs)pGeoDataset;

             pSaveAs.SaveAs("RasterTest.tif", pRasterWS, "TIFF");

             axMapControl1.ActiveView.Refresh();
        }