public static void Mlayer_Krige_Click() { // 用克里金Krige插值生成的栅格图像。如下: IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); string pPath = Application.StartupPath + @"\MakeContours\Cont.shp"; string pFolder = System.IO.Path.GetDirectoryName(pPath); string pFileName = System.IO.Path.GetFileName(pPath); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFolder, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IFeatureClass oFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName); IFeatureClassDescriptor pFCDescriptor = new FeatureClassDescriptorClass(); pFCDescriptor.Create(oFeatureClass, null, "shape.z"); IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass(); IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment; object Cellsize = 0.004;//Cell size for output raster;0.004 pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref Cellsize); //设置输出范围 //27202 19104;27202 22947;31550 22947;31550 19104 object snapRasterData = Type.Missing; IEnvelope pExtent; pExtent = new EnvelopeClass(); Double xmin = 27202; Double xmax = 31550; Double ymin = 19104; Double ymax = 22947; pExtent.PutCoords(xmin, ymin, xmax, ymax); object extentProvider = pExtent; pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData); Double dSearchD = 10; object pSearchCount = 3; object missing = Type.Missing; IRasterRadius pRadius = new RasterRadius(); pRadius.SetFixed(dSearchD, ref pSearchCount); //pRadius.SetVariable((int)pSearchCount, ref dSearchD); IGeoDataset poutGeoDataset = pInterpolationOp.Krige((IGeoDataset)pFCDescriptor, esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisGaussianSemiVariogram, pRadius, false, ref missing); IRaster pOutRaster = poutGeoDataset as IRaster; IRasterLayer pOutRasLayer = new RasterLayer(); pOutRasLayer.CreateFromRaster(pOutRaster); IMap pMap = Common.DataEditCommon.g_pMap; pMap.AddLayer(pOutRasLayer); Common.DataEditCommon.g_axTocControl.Refresh(); Common.DataEditCommon.g_pAxMapControl.ActiveView.Refresh(); }
public static void Mlayer_Krige_Click() { // 用克里金Krige插值生成的栅格图像。如下: IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); string pPath = Application.StartupPath + @"\MakeContours\Cont.shp"; string pFolder = System.IO.Path.GetDirectoryName(pPath); string pFileName = System.IO.Path.GetFileName(pPath); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFolder, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IFeatureClass oFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName); IFeatureClassDescriptor pFCDescriptor = new FeatureClassDescriptorClass(); pFCDescriptor.Create(oFeatureClass, null, "shape.z"); IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass(); IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment; object Cellsize = 0.004;//Cell size for output raster;0.004 pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref Cellsize); //设置输出范围 //27202 19104;27202 22947;31550 22947;31550 19104 object snapRasterData = Type.Missing; IEnvelope pExtent; pExtent = new EnvelopeClass(); Double xmin = 27202; Double xmax = 31550; Double ymin = 19104; Double ymax = 22947; pExtent.PutCoords(xmin, ymin, xmax, ymax); object extentProvider = pExtent; pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData); Double dSearchD = 10; object pSearchCount = 3; object missing = Type.Missing; IRasterRadius pRadius = new RasterRadius(); pRadius.SetFixed(dSearchD, ref pSearchCount); //pRadius.SetVariable((int)pSearchCount, ref dSearchD); IGeoDataset poutGeoDataset = pInterpolationOp.Krige((IGeoDataset)pFCDescriptor, esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisGaussianSemiVariogram, pRadius, false, ref missing); IRaster pOutRaster = poutGeoDataset as IRaster; IRasterLayer pOutRasLayer = new RasterLayer(); pOutRasLayer.CreateFromRaster(pOutRaster); IMap pMap = Common.DataEditCommon.g_pMap; pMap.AddLayer(pOutRasLayer); Common.DataEditCommon.g_axTocControl.Refresh(); Common.DataEditCommon.g_pAxMapControl.ActiveView.Refresh(); }
private void btnGO_Click(object sender, EventArgs e) { IFeatureClass pInPointFClass;// '获得输入点特征数据类 String fileName; String rasterPath; String shpFile; int startX, endX; if (bDataPath == true) { fileName = comboBoxInPoint.Text; String shpDir = fileName.Substring(0, fileName.LastIndexOf("\\")); startX = fileName.LastIndexOf("\\"); endX = fileName.Length; shpFile = fileName.Substring(startX + 1, endX - startX - 1); IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new ShapefileWorkspaceFactory(); IFeatureWorkspace pFWS; pFWS = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(shpDir, 0); pInPointFClass = pFWS.OpenFeatureClass(shpFile); } else { pInPointFClass = GetFeatureFromMapLyr(comboBoxInPoint.Text); } IFeatureLayer pFeatLayer = new FeatureLayerClass(); pFeatLayer.FeatureClass = pInPointFClass; rasterPath = txtOutputRasterPath.Text; //'FeatureClassDescriptor //这个对象主要用于提供访问控制FeatureClass descriptor的成员;例如,定义FeatureClass的那个属性作为分析操作。 IFeatureClassDescriptor pFeatClsDes = new FeatureClassDescriptorClass(); if (comboBoxZValueField.Text != "无") { pFeatClsDes.Create(pInPointFClass, null, comboBoxZValueField.Text); } else { pFeatClsDes.Create(pInPointFClass, null, ""); } try { IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass(); String sCellSize = txtCellSize.Text; if (Convert.ToDouble(sCellSize) <= 0) { MessageBox.Show("还没输入栅格单元!请输入后在进行插值。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } double dCellSize = Convert.ToDouble(sCellSize); IRasterRadius pRsRadius = new RasterRadiusClass(); if (comboBoxSearchRadius.Text == "变化") { String sPointNums = txtPointNumbers.Text; if (sPointNums != "") { int iPointNums = Convert.ToInt32(sPointNums); if (txtDisMaxValue.Text != "") { double maxDis = Convert.ToDouble(txtDisMaxValue.Text); object objMaxDis = maxDis; pRsRadius.SetVariable(iPointNums, ref objMaxDis); } else { object objMaxDis = null; pRsRadius.SetVariable(iPointNums, ref objMaxDis); } } else { MessageBox.Show("还没输入点的数目!请输入后在进行插值。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } else { String sDistance = txtDisValue.Text; if (sDistance != "") { double dDistance = Convert.ToDouble(sDistance); if (txtMaxPointNums.Text != "") { double maxPointNums = Convert.ToDouble(txtMaxPointNums.Text); object objMinPointNums = maxPointNums; pRsRadius.SetFixed(dDistance, ref objMinPointNums); } else { object objMinPointNums = null; pRsRadius.SetFixed(dDistance, ref objMinPointNums); } } else { MessageBox.Show("还没输入距离的值!请输入后在进行插值。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } pInterpolationOp = SetRasterInterpolationAnalysisEnv(rasterPath, dCellSize, pFeatLayer); esriGeoAnalysisSemiVariogramEnum semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisNoneVariogram; if (RadioOrdinary.Checked) { switch (ComboBoxMethod.SelectedIndex) { case 0: semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisSphericalSemiVariogram; break; case 1: semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisCircularSemiVariogram; break; case 2: semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisExponentialSemiVariogram; break; case 3: semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisGaussianSemiVariogram; break; } } else { switch (ComboBoxMethod.SelectedIndex) { case 0: semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisUniversal1SemiVariogram; break; case 1: semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisUniversal2SemiVariogram; break; } } IRaster pOutRaster; object barrier = null; pOutRaster = (IRaster)pInterpolationOp.Krige((IGeoDataset)pFeatClsDes, semi, pRsRadius, true, ref barrier); //着色 IRasterLayer pRasterLayer = new RasterLayerClass(); pRasterLayer.Name = "反距离栅格"; ConvertRasterToRsDataset(rasterPath, ref pOutRaster, "反距离栅格"); pRasterLayer = SetRsLayerClassifiedColor(pOutRaster); frm.mainMapControl.AddLayer(pRasterLayer, 0); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void kriging(IFeatureClass pFeatureClass) { // FeatureClassDescriptor 对象用于控制和描述插值的参数 IFeatureClassDescriptor pFDescr = new FeatureClassDescriptorClass(); pFDescr.Create(pFeatureClass, null, "Ozone"); // 栅格半径辅助对象用于控制插值的参数 IRasterRadius pRasRadius = new RasterRadiusClass(); object object_Missing = System.Type.Missing; pRasRadius.SetVariable(12, ref object_Missing); IInterpolationOp pInterpOp = new RasterInterpolationOpClass(); IRaster pRasterOut = (IRaster)pInterpOp.Krige((IGeoDataset)pFDescr, esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisExponentialSemiVariogram, pRasRadius, false, ref object_Missing); }