/// <summary> /// 获得全局聚类的EdgeList /// </summary> /// <returns></returns> private List <ITinEdge> GetGlobalEdgeList() { List <ITinEdge> globalEdge = new List <ITinEdge>(); ITinAdvanced tinAdvanced = m_DT as ITinAdvanced; double globalMean = GlobalMean(m_DT); double globalStDev = GlobalStDev(m_DT, globalMean); int nodeCount = tinAdvanced.NodeCount; for (int i = 1; i <= nodeCount; i++) { ITinNode tinNode = tinAdvanced.GetNode(i); double local1Mean = Local1Mean(tinNode); double globalConstraint = globalMean * (1 + globalStDev / local1Mean); ITinEdgeArray incdentEdges = tinNode.GetIncidentEdges(); int incdentEdgeCount = incdentEdges.Count; for (int j = 0; j < incdentEdgeCount; j++) { ITinEdge currentEdge = incdentEdges.get_Element(j); if (currentEdge.Length < globalConstraint && currentEdge.IsInsideDataArea) { globalEdge.Add(currentEdge); } } } //去掉多加的neighbor边 globalEdge = CompleteEdges(globalEdge); return(globalEdge); }
private void buttonXOK_Click(object sender, EventArgs e) { try { ITinAdvanced ptina = m_pTin as ITinAdvanced; // DirectoryInfo dir = Directory.CreateDirectory(m_DEMPath); DirectoryInfo dir = new DirectoryInfo(m_DEMPath); String sdir = dir.Parent.FullName; String name = dir.Name; //IRasterDataset rd1 = CreateRasterDataset(@"d:\dem", "aa.tif"); // IRasterDataset rd = CreateRasterDataset(sdir, name); //esriRasterizationType eRastConvType = esriRasterizationType.esriElevationAsRaster IRasterDataset pRD = TinToRaster_new(ptina, esriRasterizationType.esriElevationAsRaster, sdir, name, rstPixelType.PT_DOUBLE, doubleInputCellSize.Value, m_pTin.Extent, true); // TinToRaster_new(ITinAdvanced pTin, esriRasterizationType eRastConvType, String sDir, String sName, rstPixelType ePixelType, Double cellsize, IEnvelope pExtent, bool bPerm) pRD = null; GC.Collect(); MessageBox.Show("转换成功!"); } catch (SystemException ee) { m_DEMPath = ""; MessageBox.Show(ee.Message); } }
/// <summary> /// 创建TIN /// </summary> private void CreateDelaunay() { //创建TIN IFeatureLayer featureLayer = m_dataInfo.GetInputLayer() as IFeatureLayer; IFeatureClass featureClass = featureLayer.FeatureClass; IField pField = featureClass.Fields.get_Field(0); if (pField == null) { MessageBox.Show("创建Delaunay三角网失败"); return; } IGeoDataset pGeoDataset = featureClass as IGeoDataset; IEnvelope pEnvelope = pGeoDataset.Extent; pEnvelope.SpatialReference = pGeoDataset.SpatialReference; ITinEdit pTinEdit = new TinClass(); pTinEdit.InitNew(pEnvelope); object obj = Type.Missing; pTinEdit.AddFromFeatureClass(featureClass, null, pField, null, esriTinSurfaceType.esriTinMassPoint, ref obj); m_DT = pTinEdit as ITin; //将所有点标识为噪声点 ITinAdvanced tinAdvanced = m_DT as ITinAdvanced; for (int i = 0; i < tinAdvanced.NodeCount; i++) { m_nodeFlag.Add(-1); } }
public static void GetCurrentSurfaceMax(ILayer ilayer_0, out double double_0, out double double_1) { ISurface surfaceFromLayer = SurfaceInfo.GetSurfaceFromLayer(ilayer_0); if (surfaceFromLayer != null) { if (surfaceFromLayer is ITinAdvanced) { ITinAdvanced tinAdvanced = surfaceFromLayer as ITinAdvanced; IEnvelope extent = tinAdvanced.Extent; double_0 = ((extent.Width > extent.Height) ? extent.Width : extent.Height); double_1 = extent.ZMax; } else { IRasterSurface rasterSurface = surfaceFromLayer as IRasterSurface; IRasterProps rasterProps = rasterSurface.Raster as IRasterProps; IEnvelope extent = rasterProps.Extent; double_0 = ((extent.Width > extent.Height) ? extent.Width : extent.Height); IRasterBandCollection rasterBandCollection = rasterProps as IRasterBandCollection; IRasterBand rasterBand = rasterBandCollection.Item(0); IRasterStatistics statistics = rasterBand.Statistics; double_1 = statistics.Maximum; } } else { double_0 = 0.0; double_1 = 0.0; } }
/// <summary> /// Delaunay三角网整体边长平均值(全局) /// </summary> /// <param name="tin"></param> /// <returns></returns> private double GlobalMean(ITin tin) { double length = 0; ITinAdvanced tinAdvanced = tin as ITinAdvanced; int edgeCount = tinAdvanced.EdgeCount; for (int i = 1; i <= edgeCount; i++) { if (tinAdvanced.GetEdge(i).IsInsideDataArea) { length = length + tinAdvanced.GetEdge(i).Length; } } return(length / (double)tinAdvanced.DataEdgeCount); }
/// <summary> /// 整体边长标准差(全局) /// </summary> /// <param name="tin"></param> /// <param name="globalMean"></param> /// <returns></returns> private double GlobalStDev(ITin tin, double globalMean) { double a = 0; ITinAdvanced tinAdvanced = tin as ITinAdvanced; int edgeCount = tinAdvanced.EdgeCount; // int edgeCount = tinAdvanced.DataEdgeCount; for (int i = 1; i <= edgeCount; i++) { if (tinAdvanced.GetEdge(i).IsInsideDataArea) { ITinEdge tinEdge = tinAdvanced.GetEdge(i); a = a + (globalMean - tinEdge.Length) * (globalMean - tinEdge.Length); } } return(System.Math.Sqrt(a / (double)tinAdvanced.DataEdgeCount)); }
private void cmbcolor_SelectedIndexChanged(object sender, EventArgs e) { if (cmbclasses.SelectedItem != null) { ITinAdvanced pTinAdv = pTLayer.Dataset as ITinAdvanced; IColorRamp pColorRamp = null; int symbol_index = cmbcolor.SelectedIndex;//获取选择的序号 IStyleGalleryItem mStyleGalleryItem = pSymbolClass.GetItem(symbol_index); // IColorRamp pColorRamp = (IColorRamp)mStyleGalleryItem.Item;//获取选择的符号 pColorRamp.Size = int.Parse(cmbclasses.SelectedItem.ToString()); bool bOK = false; pColorRamp.CreateRamp(out bOK); for (int i = 0; i < pColorRamp.Size; i++) { (datagridsymbol.Rows[i].Cells[0]).Style.BackColor = ClsGDBDataCommon.IColorToColor(pColorRamp.get_Color(i)); } datagridsymbol.CurrentCell = null; } }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { // TODO: Add ToolModefyTINNode.OnMouseMove implementation ITin pTin = pTinLayer.Dataset; ITinEdit pTinEdit = pTin as ITinEdit; ITinAdvanced pTinAdvanced = (ITinAdvanced)pTin; IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; if (pMapCtr != null) { IPoint mapPoint = pMapCtr.ToMapPoint(X, Y); ITinNode pTINNode = new TinNodeClass(); double distance = 0; pTinAdvanced.QueryNearestNode(mapPoint, pTINNode, ref distance); pNode = pTINNode; IPoint pt = new PointClass(); pt.PutCoords(pNode.X, pNode.Y); pMovePtFeedBack.MoveTo(pt); } }
//更新gridview控件 private void updatadatagrid() { int classcount = int.Parse(cmbclasses.SelectedItem.ToString()); ITinAdvanced pTinAdv = pTLayer.Dataset as ITinAdvanced; double dZMin = pTinAdv.Extent.ZMin; //tin的Z轴最高值 double dZMax = pTinAdv.Extent.ZMax; //tin的Z轴最低值 double dInterval = (dZMax - dZMin) / classcount; double dLowBreak = dZMin; double dHighBreak = dLowBreak + dInterval; //创建颜色集合 IColorRamp pColorRamp = null; int symbol_index = cmbcolor.SelectedIndex;//获取选择的序号 IStyleGalleryItem mStyleGalleryItem = pSymbolClass.GetItem(symbol_index); // IColorRamp pColorRamp = (IColorRamp)mStyleGalleryItem.Item;//获取选择的符号 pColorRamp.Size = classcount; bool bOK = false; pColorRamp.CreateRamp(out bOK); lowbreak.Clear(); highbreak.Clear(); dataTable2.Rows.Clear(); for (int i = 0; i < pColorRamp.Size; i++) { lowbreak.Add(dLowBreak); highbreak.Add(dHighBreak); DataRow row = dataTable2.NewRow(); row[1] = dLowBreak.ToString("#.#") + " - " + dHighBreak.ToString("#.#"); row[2] = row[1]; dataTable2.Rows.Add(row); dLowBreak = dHighBreak; dHighBreak = dHighBreak + dInterval; datagridsymbol.Rows[i].Cells[0].Style.BackColor = ClsGDBDataCommon.IColorToColor(pColorRamp.get_Color(i)); } datagridsymbol.CurrentCell = null; }
private void btnSure_Click(object sender, EventArgs e) { SysCommon.CProgress vProgress = new SysCommon.CProgress("进度条"); try { if (comboBoxOpen.Text == "") { MessageBox.Show("请选择数据!", "提示!"); return; } if (txtZFactor.Text == "") { MessageBox.Show("请设置Z值参数!", "提示!"); return; } if (txtCellSize.Text == "") { MessageBox.Show("请设置输出精度参数!", "提示!"); return; } if (txtSave.Text == "") { MessageBox.Show("请输入保存文件名!", "提示!"); return; } string Unit; if (radioBtnDegree.Checked) { Unit = "DEGREE"; } else { Unit = "PERCENT"; } //this.Hide(); //Progress.FormProgress vProgress.EnableCancel = false;//设置进度条 vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); vProgress.SetProgress("正在进行坡度分析"); ILayer pLayer = GetLayerByName(ref fileName);//根据图层名获取图层 IGeoDataset pGeoDataset = pLayer as IGeoDataset; ISurfaceOp pSurfaceOp; IRasterAnalysisEnvironment pRasterAnalysisEnvironment = new RasterSurfaceOp(); pSurfaceOp = pRasterAnalysisEnvironment as ISurfaceOp; object pObject = Convert.ToDouble(txtCellSize.Text); object pZFactor = Convert.ToDouble(txtZFactor.Text); pRasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref pObject); //设置输出数据的像元值大小 IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass(); string OutPath = System.IO.Path.GetDirectoryName(txtSave.Text); //输出文件存储的目录信息 string TempPath = string.Concat(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "\\Temp\\"); //临时文件存储位置 if (!Directory.Exists(TempPath)) { Directory.CreateDirectory(TempPath);// 当路径不存在时创建临时文件存储路径 } IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(TempPath, 0); pRasterAnalysisEnvironment.OutWorkspace = pWorkspace; IRasterBandCollection pRasterBandCollection; string Newfile = System.IO.Path.GetFileName(txtSave.Text); if (pGeoDataset is IRasterLayer) { IRasterLayer pRasterLayer = pLayer as IRasterLayer; pGeoDataset = (IGeoDataset)pRasterLayer.Raster; if (Unit == "DEGREE")//选择不同单位进行坡度分析 { pRasterBandCollection = pSurfaceOp.Slope(pGeoDataset, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, ref pZFactor) as IRasterBandCollection; } else { pRasterBandCollection = pSurfaceOp.Slope(pGeoDataset, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopePercentrise, ref pZFactor) as IRasterBandCollection; } pWorkspace = pWorkspaceFactory.OpenFromFile(OutPath, 0); pRasterBandCollection.SaveAs(Newfile, pWorkspace, RasterType); //保存分析结果到固定路径下 vProgress.Close(); if (MessageBox.Show("坡度分析成功,是否加载分析结果", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { vProgress.ShowProgress(); vProgress.SetProgress("正在进行加载结果数据"); IRasterWorkspace pRasterWorkspace = pWorkspaceFactory.OpenFromFile(OutPath, 0) as IRasterWorkspace; // 张琪 20110613 IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(txtSave.Text)); //包含扩展名的表面数据集 IRasterLayer pOutRasterLayer = new RasterLayerClass(); pOutRasterLayer.CreateFromDataset(pRasterDataset); m_pCurrentSceneControl.Scene.AddLayer(pOutRasterLayer as ILayer, true); vProgress.Close(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(pRasterBandCollection); } else if (pGeoDataset is ITinLayer) { ITinLayer pTinLayer = pGeoDataset as ITinLayer; ITinAdvanced pTinAdvanced = pTinLayer.Dataset as ITinAdvanced; Cls3DModulsefun pCls3DModulsefun = new Cls3DModulsefun(); IRasterDataset pRasterDataset; esriRasterizationType pesriRasterizationType; if (Unit == "DEGREE") { pesriRasterizationType = esriRasterizationType.esriDegreeSlopeAsRaster; } else { pesriRasterizationType = esriRasterizationType.esriPercentageSlopeAsRaster; } rstPixelType prstPixelType = rstPixelType.PT_LONG; //TIN数据转换成Raster数据并进行坡度分析(暂时未成功) vProgress.Close(); pRasterDataset = pCls3DModulsefun.TinToRaster2(pTinAdvanced, pesriRasterizationType, OutPath, Newfile, prstPixelType, Convert.ToDouble(txtCellSize.Text), pTinAdvanced.Extent, true, RasterType); if (MessageBox.Show("坡度分析成功,是否加载分析结果", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { IRasterLayer pOutRasterLayer = new RasterLayerClass(); pOutRasterLayer.CreateFromDataset(pRasterDataset); m_pCurrentSceneControl.Scene.AddLayer(pOutRasterLayer as ILayer, true); if (this.WriteLog) { Plugin.LogTable.Writelog("坡度分析,表面集为:" + comboBoxOpen.Text); Plugin.LogTable.Writelog("输出栅格路径为:" + txtSave.Text); } } } else { MessageBox.Show("目前不支持对当前选择图层的坡度分析功能", "提示!"); } m_pCurrentSceneControl.SceneGraph.RefreshViewers(); this.Close(); DeleteFolder(TempPath);//清楚临时文件 } catch { vProgress.Close(); this.Close(); MessageBox.Show("很抱歉,操作失败!", "提示!"); return; } }
private void btnok_Click(object sender, EventArgs e) { if (treeshow.SelectedIndex == 1) { ITinRenderer pRenderNew = new TinFaceRenderer() as ITinRenderer; ITinSingleSymbolRenderer pUVRenderer = pRenderNew as ITinSingleSymbolRenderer; ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass(); pSymbol.Color = ClsGDBDataCommon.ColorToIColor(btncolor.SelectedColor); pUVRenderer.Symbol = pSymbol as ISymbol; pTLayer.ClearRenderers(); pTLayer.InsertRenderer(pRenderNew, 0); pTocContral.SetBuddyControl(pMapContral); pTocContral.Refresh(); pMapContral.Refresh(); if (bar3.SelectedDockTab == 2) { IActiveView pActiveView = pSceneControl.Scene as IActiveView; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pTLayer, null); } this.Close(); } else { ITinRenderer pTinRenderer = new TinElevationRenderer() as ITinRenderer; //设置样式 if (pTinRenderer is ITinColorRampRenderer) { if (pTinRenderer.Name == "Elevation") { if (lowbreak.Count > 0) { int ClassCount = int.Parse(cmbclasses.SelectedItem.ToString()); ITinAdvanced pTinAdv = pTLayer.Dataset as ITinAdvanced; ITinColorRampRenderer pTinColorRampRenderer = pTinRenderer as ITinColorRampRenderer; IClassBreaksUIProperties pClassBreaksUIProperties = pTinRenderer as IClassBreaksUIProperties; INumberFormat pNumberFormat = pClassBreaksUIProperties.NumberFormat; pTinColorRampRenderer.MinimumBreak = lowbreak[0]; pTinColorRampRenderer.BreakCount = int.Parse(cmbclasses.SelectedItem.ToString()); ISimpleFillSymbol pSymbol = null; for (int j = 0; j < pTinColorRampRenderer.BreakCount; j++) { pClassBreaksUIProperties.set_LowBreak(j, lowbreak[j]); pTinColorRampRenderer.set_Break(j, highbreak[j]); //用于图层控制中分级标示显示 pTinColorRampRenderer.set_Label(ClassCount - j - 1, datagridsymbol.Rows[j].Cells[2].Value.ToString()); pSymbol = new SimpleFillSymbolClass(); pSymbol.Color = ClsGDBDataCommon.ColorToIColor(datagridsymbol.Rows[j].Cells[0].Style.BackColor); pTinColorRampRenderer.set_Symbol(ClassCount - j - 1, pSymbol as ISymbol); } pTLayer.ClearRenderers(); (pTinColorRampRenderer as ITinRenderer).Visible = true; pTLayer.InsertRenderer(pTinColorRampRenderer as ITinRenderer, 0);//插入一个渲染模型 pTocContral.SetBuddyControl(pMapContral); pTocContral.Refresh(); pMapContral.Refresh(); if (bar3.SelectedDockTab == 2) { IActiveView pActiveView = pSceneControl.Scene as IActiveView; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pTLayer, null); } this.Close(); } } } } }
/// <summary> /// TIN数据转栅格数据并进行坡度分析 张琪 20110614 /// </summary> /// <param name="pTinAdvanced"></param> /// <param name="pRastConvType"></param> /// <param name="sDir"></param> /// <param name="sName"></param> /// <param name="ePixelType"></param> /// <param name="cellsize"></param> /// <param name="pExtent"></param> /// <param name="bPerm"></param> /// <param name="strType"></param> /// <returns></returns> public IRasterDataset TinToRaster(ITinAdvanced pTinAdvanced, esriRasterizationType pRastConvType, String sDir, String sName, rstPixelType ePixelType, Double cellsize, IEnvelope pExtent, bool bPerm, String strType) { try { ESRI.ArcGIS.Geometry.IPoint pOrigin = pExtent.LowerLeft; pOrigin.X = pOrigin.X - (cellsize * 0.5); pOrigin.Y = pOrigin.Y - (cellsize * 0.5); int nCol, nRow; nCol = Convert.ToInt32(Math.Round(pExtent.Width / cellsize)) + 1; nRow = Convert.ToInt32(Math.Round(pExtent.Height / cellsize)) + 1; IGeoDataset pGeoDataset = pTinAdvanced as IGeoDataset; ISpatialReference2 pSpatialReference2 = pGeoDataset.SpatialReference as ISpatialReference2; IRasterDataset pRasterDataset = CreateRasterSurf(sDir, sName, strType, pOrigin, nCol, nRow, cellsize, cellsize, ePixelType, pSpatialReference2, bPerm); IRawPixels pRawPixels = GetRawPixels(pRasterDataset, 0); object pCache = pRawPixels.AcquireCache(); ITinSurface pTinSurface = pTinAdvanced as ITinSurface; IGeoDatabaseBridge2 pbridge2 = (IGeoDatabaseBridge2) new GeoDatabaseHelperClass(); IRasterProps pRasterProps = pRawPixels as IRasterProps; //float nodataFloat; //int nodataInt; double dZMin = pTinAdvanced.Extent.ZMin; object vNoData; if (ePixelType.ToString() == "PT_FLOAT") { vNoData = (dZMin - 1).ToString(); } else { vNoData = Convert.ToInt32((dZMin - 1)); } pRasterProps.NoDataValue = vNoData; IPnt pOffset = new DblPntClass(); int lMaxBlockX = 2048; if (nCol < lMaxBlockX) { lMaxBlockX = nCol; } int lMaxBlockY = 2048; if (nRow < lMaxBlockY) { lMaxBlockY = nRow; } IPnt pBlockSize = new DblPntClass(); pBlockSize.X = lMaxBlockX; pBlockSize.Y = lMaxBlockY; IPixelBlock3 pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize) as IPixelBlock3; object blockArray = pPixelBlock.get_PixelDataByRef(0); ITrackCancel pCancel = new CancelTrackerClass(); pCancel.CancelOnClick = false; pCancel.CancelOnKeyPress = true; int lBlockCount = Convert.ToInt32(Math.Round((nCol / lMaxBlockX) + 0.49) * Math.Round((nRow / lMaxBlockY) + 0.49)); ESRI.ArcGIS.Geometry.IPoint pBlockOrigin = new ESRI.ArcGIS.Geometry.PointClass(); int lColOffset, lRowOffset; for (lRowOffset = 0; lRowOffset < (nRow - 1);) { for (lColOffset = 0; lColOffset < (nCol - 1);) { if ((nCol - lColOffset) < lMaxBlockX) { pBlockSize.X = (nCol - lColOffset); pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize) as IPixelBlock3; blockArray = pPixelBlock.get_PixelDataByRef(0); } pBlockOrigin.X = pOrigin.X + (lColOffset * cellsize) + (cellsize * 0.5); pBlockOrigin.Y = pOrigin.Y + ((nRow - lRowOffset) * cellsize) - (cellsize * 0.5); pbridge2.QueryPixelBlock(pTinSurface, pBlockOrigin.X, pBlockOrigin.Y, cellsize, cellsize, pRastConvType, vNoData, ref blockArray); //pTinSurface.QueryPixelBlock(pBlockOrigin.X, pBlockOrigin.Y, cellsize, cellsize, pRastConvType, vNoData, blockArray); pOffset.X = lColOffset; pOffset.Y = lRowOffset; pPixelBlock.set_PixelData(0, (System.Object)blockArray); pRawPixels.Write(pOffset, pPixelBlock as IPixelBlock); if (lBlockCount > 1) { if (!pCancel.Continue()) { break; } else if (pTinAdvanced.ProcessCancelled) { break; } } lColOffset = lColOffset + lMaxBlockX; } bool bReset = false; if (pBlockSize.X != lMaxBlockX) { pBlockSize.X = lMaxBlockX; bReset = true; } if ((nRow - lRowOffset) < lMaxBlockY) { pBlockSize.Y = (nRow - lRowOffset); bReset = true; } if (bReset) { pPixelBlock.set_PixelData(0, blockArray); pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize) as IPixelBlock3; blockArray = pPixelBlock.get_PixelDataByRef(0); } lRowOffset = lRowOffset + lMaxBlockY; } pRawPixels.ReturnCache(pCache); pCache = null; pRawPixels = null; pPixelBlock = null; pRasterProps = null; blockArray = 0; pRasterDataset = OpenRasterDataset(sDir, sName); if (lBlockCount == 1) { pTinAdvanced.TrackCancel = null; } return(pRasterDataset); } catch { return(null); } }
public IRasterDataset TinToRaster2(ITinAdvanced pTinAdvanced, esriRasterizationType pRastConvType, String sDir, String sName, rstPixelType ePixelType, Double cellsize, IEnvelope pExtent, bool bPerm, String strType) { try { ESRI.ArcGIS.Geometry.IPoint pOrigin = pExtent.LowerLeft; pOrigin.X = pOrigin.X - (cellsize * 0.5); pOrigin.Y = pOrigin.Y - (cellsize * 0.5); int nCol, nRow; nCol = Convert.ToInt32(Math.Round(pExtent.Width / cellsize)) + 1; nRow = Convert.ToInt32(Math.Round(pExtent.Height / cellsize)) + 1; IGeoDataset pGeoDataset = pTinAdvanced as IGeoDataset; ISpatialReference2 pSpatialReference2 = pGeoDataset.SpatialReference as ISpatialReference2; IRasterDataset pRasterDataset = CreateRasterSurf(sDir, sName, strType, pOrigin, nCol, nRow, cellsize, cellsize, ePixelType, pSpatialReference2, bPerm); IRawPixels pRawPixels = GetRawPixels(pRasterDataset, 0); IPnt pBlockSize = new DblPntClass(); pBlockSize.X = nCol; pBlockSize.Y = nRow; IPixelBlock3 pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize) as IPixelBlock3; object blockArray = pPixelBlock.get_PixelDataByRef(0); ITinSurface pTinSurface = pTinAdvanced as ITinSurface; IGeoDatabaseBridge2 pbridge2 = (IGeoDatabaseBridge2) new GeoDatabaseHelperClass(); IRasterProps pRasterProps = pRawPixels as IRasterProps; object nodataFloat; object nodataInt; pOrigin.X = pOrigin.X + (cellsize * 0.5); pOrigin.Y = pOrigin.Y + (cellsize * nRow) - (cellsize * 0.5); if (ePixelType.ToString() == "PT_FLOAT") { nodataFloat = pRasterProps.NoDataValue; pTinSurface.QueryPixelBlock(pOrigin.X, pOrigin.Y, cellsize, cellsize, pRastConvType, nodataFloat, blockArray); } else { nodataInt = pRasterProps.NoDataValue; pTinSurface.QueryPixelBlock(pOrigin.X, pOrigin.Y, cellsize, cellsize, pRastConvType, nodataInt, blockArray); } if (pTinAdvanced.ProcessCancelled == false) { return(null); } IPnt pOffset = new DblPntClass(); pOffset.X = 0; pOffset.Y = 0; pRawPixels.Write(pOffset, pPixelBlock as IPixelBlock); if (!bPerm && ePixelType.ToString() == "PT_FLOAT") { IRasterBand pBand = pRawPixels as IRasterBand; IRasterStatistics pStats = pBand.Statistics; pStats.Recalculate(); } if (bPerm) { pRawPixels = null; pPixelBlock = null; pRasterProps = null; blockArray = 0; pRasterDataset = OpenRasterDataset(sDir, sName); } return(pRasterDataset); } catch { return(null); } }
/// <summary> /// 面积、体积统计及三维效果绘制 张琪 20110629 /// </summary> private void StaTisTic() { SysCommon.CProgress vProgress = new SysCommon.CProgress("进度条"); try { vProgress.EnableCancel = false;//设置进度条 vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); vProgress.SetProgress("正在计算"); object before = Type.Missing; object after = Type.Missing; if (m_StaPolygon == null) { txtArea2DSel.Text = m_SurFace.GetProjectedArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceAbove).ToString(); txtAreaAbove.Text = m_SurFace.GetSurfaceArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceAbove).ToString(); txtAreaBelow.Text = m_SurFace.GetSurfaceArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceBelow).ToString(); txtVolumeBelow.Text = m_SurFace.GetVolume(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceBelow).ToString(); txtVolumeAbove.Text = m_SurFace.GetVolume(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceAbove).ToString(); } else//在地图上绘制多边形时 { if (m_IsTin)//为true是指数据为TIN { ITinSurface pTinsurface = m_SurFace as ITinSurface; ITinAdvanced pTinAdvanced = pTinsurface as ITinAdvanced; ////ITriangleLabelInPolyFilter = new //ITinFilter pTCFilterBasic = pTCFilter as ITinFilter; //pTCFilterBasic.DataElementsOnly = true; int Criteria = 4; IEnumTinTriangle pEnumTriangles = pTinAdvanced.MakeTriangleEnumerator(m_StaPolygon.Envelope, Criteria, null); object dVolumeBelow = null; object dSurfaceArea = null; object dProjectedArea = null; //根据绘制的多边形和Z值来计算基准面以上的面积和体积 pTinsurface.GetPartialVolumeAndArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceAbove, pEnumTriangles, ref dVolumeBelow, ref dSurfaceArea, ref dProjectedArea); txtAreaAbove.Text = Convert.ToDouble(dSurfaceArea).ToString(); txtVolumeAbove.Text = dVolumeBelow.ToString(); txtArea2DSel.Text = dProjectedArea.ToString(); //根据绘制的多边形和Z值来计算基准面以下的面积和体积 pTinsurface.GetPartialVolumeAndArea(Convert.ToDouble(txtPlaneHeight.Text), esriPlaneReferenceType.esriPlaneReferenceBelow, pEnumTriangles, ref dVolumeBelow, ref dSurfaceArea, ref dProjectedArea); txtAreaBelow.Text = dSurfaceArea.ToString(); txtVolumeBelow.Text = dVolumeBelow.ToString(); } else { MessageBox.Show("抱歉该功能暂不支持Raster数据", "提示!"); vProgress.Close(); return; } } IPointCollection pPolygon; ESRI.ArcGIS.Geometry.IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass(); //IPolygon pOutPoly; if (m_StaPolygon == null)//当绘制范围为空,获取整张图的范围 { pPolygon = new PolygonClass(); IZAware pZawre; pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference; pPoint.X = m_SurFace.Domain.Envelope.XMin; pPoint.Y = m_SurFace.Domain.Envelope.YMin; pZawre = pPoint as IZAware; pZawre.ZAware = true; pPoint.Z = Convert.ToDouble(txtPlaneHeight.Text); pPolygon.AddPoint(pPoint, ref before, ref after); pPoint = new ESRI.ArcGIS.Geometry.PointClass(); pZawre = pPoint as IZAware; pZawre.ZAware = true; pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference; pPoint.X = m_SurFace.Domain.Envelope.XMax; pPoint.Y = m_SurFace.Domain.Envelope.YMin; pPoint.Z = Convert.ToDouble(txtPlaneHeight.Text); pPolygon.AddPoint(pPoint, ref before, ref after); pPoint = new ESRI.ArcGIS.Geometry.PointClass(); pZawre = pPoint as IZAware; pZawre.ZAware = true; pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference; pPoint.X = m_SurFace.Domain.Envelope.XMax; pPoint.Y = m_SurFace.Domain.Envelope.YMax; pPoint.Z = Convert.ToDouble(txtPlaneHeight.Text); pPolygon.AddPoint(pPoint, ref before, ref after); pPoint = new ESRI.ArcGIS.Geometry.PointClass(); pZawre = pPoint as IZAware; pZawre.ZAware = true; pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference; pPoint.X = m_SurFace.Domain.Envelope.XMin; pPoint.Y = m_SurFace.Domain.Envelope.YMax; pPoint.Z = Convert.ToDouble(txtPlaneHeight.Text); pPolygon.AddPoint(pPoint, ref before, ref after); pPoint = new ESRI.ArcGIS.Geometry.PointClass(); pZawre = pPoint as IZAware; pZawre.ZAware = true; pPoint.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference; pPoint.X = m_SurFace.Domain.Envelope.XMin; pPoint.Y = m_SurFace.Domain.Envelope.YMin; pPoint.Z = Convert.ToDouble(txtPlaneHeight.Text); pPolygon.AddPoint(pPoint, ref before, ref after); //获得整张图范围组成的多边形 IGeometry pGeometry = pPolygon as IGeometry; pGeometry.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference; } else { pPolygon = m_StaPolygon as IPointCollection; } if (pPolygon == null) { vProgress.Close(); return; } //显示参考面 ShowRefPlane(pPolygon as IPolygon); //显示周边 ShowCountour(pPolygon as IPolygon); //获取轮廓线的周长 m_ScenePoly = pPolygon as IPolygon; ITopologicalOperator pTopo = pPolygon as ITopologicalOperator; IPolyline pPolyLine = pTopo.Boundary as IPolyline; txtPara.Text = pPolyLine.Length.ToString(); vProgress.Close(); } catch { vProgress.Close(); } }
public static IRasterDataset TinToRaster(ITinAdvanced itinAdvanced_0, esriRasterizationType esriRasterizationType_0, string string_0, string string_1, rstPixelType rstPixelType_0, double double_0, IEnvelope ienvelope_0, bool bool_0) { IPoint lowerLeft = ienvelope_0.LowerLeft; lowerLeft.X -= double_0 * 0.5; lowerLeft.Y -= double_0 * 0.5; int num = (int)Math.Round((double)((ienvelope_0.Width / double_0) + 1.0)); int num2 = (int)Math.Round((double)((ienvelope_0.Height / double_0) + 1.0)); IGeoDataset dataset = itinAdvanced_0 as IGeoDataset; ISpatialReference2 spatialReference = dataset.SpatialReference as ISpatialReference2; IRasterDataset dataset2 = CreateRasterSurf(string_0, string_1, "GRID", lowerLeft, num, num2, double_0, double_0, rstPixelType_0, spatialReference, true); IRasterBandCollection bands = dataset2 as IRasterBandCollection; IRawPixels pixels = bands.Item(0) as IRawPixels; ITinSurface pSurface = itinAdvanced_0 as ITinSurface; pSurface.RasterInterpolationMethod = esriSurfaceInterpolationType.esriNaturalNeighborInterpolation; IRasterProps props = pixels as IRasterProps; object noDataValue = props.NoDataValue; IPnt tlc = new DblPnt(); int num3 = 2048; int num4 = 2048; if (num < 2048) { num3 = num; } if (num2 < num4) { num4 = num2; } IPnt size = new DblPnt { X = num3, Y = num4 }; IPixelBlock pxls = pixels.CreatePixelBlock(size); object block = pxls.get_SafeArray(0); IPoint point2 = new Point(); for (int i = 0; i < num2; i += num4) { for (int j = 0; j < num; j += num3) { if ((num - j) < num3) { size.X = num - j; pxls = pixels.CreatePixelBlock(size); block = pxls.get_SafeArray(0); } point2.X = (lowerLeft.X + (j * double_0)) + (double_0 * 0.5); point2.Y = (lowerLeft.Y + ((num2 - i) * double_0)) - (double_0 * 0.5); IGeoDatabaseBridge2 bridge = new GeoDatabaseHelper() as IGeoDatabaseBridge2; bridge.QueryPixelBlock(pSurface, point2.X, point2.Y, double_0, double_0, esriRasterizationType_0, noDataValue, ref block); tlc.X = j; tlc.Y = i; pxls.set_SafeArray(0, block); pixels.Write(tlc, pxls); } bool flag = false; if (size.X != num3) { size.X = num3; flag = true; } if ((num2 - i) < num4) { size.Y = num2 - i; } if (flag) { block = pixels.CreatePixelBlock(size).get_SafeArray(0); } } return(dataset2); }
public static IRasterDataset TinToRaster(ITinAdvanced itinAdvanced_0, esriRasterizationType esriRasterizationType_0, string string_0, string string_1, string string_2, rstPixelType rstPixelType_0, double double_0, IEnvelope ienvelope_0, bool bool_0) { object obj3; IPoint lowerLeft = ienvelope_0.LowerLeft; lowerLeft.X -= double_0 * 0.5; lowerLeft.Y -= double_0 * 0.5; int num = ((int)Math.Round((double)(ienvelope_0.Width / double_0))) + 1; int num2 = ((int)Math.Round((double)(ienvelope_0.Height / double_0))) + 1; IGeoDataset dataset = itinAdvanced_0 as IGeoDataset; ISpatialReference2 spatialReference = dataset.SpatialReference as ISpatialReference2; IRasterDataset dataset2 = CreateRasterSurf(string_0, string_1, string_2, lowerLeft, num, num2, double_0, double_0, 1, rstPixelType_0, spatialReference, bool_0); IRawPixels rawPixels = GetRawPixels(dataset2, 0); object cache = rawPixels.AcquireCache(); ITinSurface pSurface = itinAdvanced_0 as ITinSurface; IRasterProps o = rawPixels as IRasterProps; double zMin = itinAdvanced_0.Extent.ZMin; if (rstPixelType_0 == rstPixelType.PT_FLOAT) { obj3 = (float)(zMin - 1.0); } else { obj3 = (int)(zMin - 1.0); } o.NoDataValue = obj3; IPnt tlc = new DblPnt(); int num4 = 2048; if (num < 2048) { num4 = num; } int num5 = 2048; if (num2 < 2048) { num5 = num2; } IPnt size = new DblPnt { X = num4, Y = num5 }; IPixelBlock3 block = rawPixels.CreatePixelBlock(size) as IPixelBlock3; ITrackCancel cancel = new CancelTracker { CancelOnClick = false, CancelOnKeyPress = true }; int num6 = (int)(Math.Round((double)((num / num4) + 0.49)) * Math.Round((double)((num2 / num5) + 0.49))); if (num6 == 1) { itinAdvanced_0.TrackCancel = cancel; } IPoint point2 = new Point(); object obj4 = block.get_PixelDataByRef(0); for (int i = 0; i < num2; i += num5) { for (int j = 0; j < num; j += num4) { if ((num - j) < num4) { size.X = num - j; block = rawPixels.CreatePixelBlock(size) as IPixelBlock3; obj4 = block.get_PixelDataByRef(0); } point2.X = (lowerLeft.X + (j * double_0)) + (double_0 * 0.5); point2.Y = (lowerLeft.Y + ((num2 - i) * double_0)) - (double_0 * 0.5); IGeoDatabaseBridge2 bridge = new GeoDatabaseHelper() as IGeoDatabaseBridge2; bridge.QueryPixelBlock(pSurface, point2.X, point2.Y, double_0, double_0, esriRasterizationType_0, obj3, ref obj4); tlc.X = j; tlc.Y = i; block.set_PixelData(0, obj4); rawPixels.Write(tlc, block as IPixelBlock); } bool flag = false; if (size.X != num4) { size.X = num4; flag = true; } if ((num2 - i) < num5) { size.Y = num2 - i; flag = true; } if (flag) { block = rawPixels.CreatePixelBlock(size) as IPixelBlock3; obj4 = block.get_PixelDataByRef(0); } } rawPixels.ReturnCache(cache); Marshal.ReleaseComObject(cache); cache = null; Marshal.ReleaseComObject(rawPixels); rawPixels = null; Marshal.ReleaseComObject(block); block = null; Marshal.ReleaseComObject(o); o = null; obj4 = 0; GC.Collect(); return(dataset2); }
private void method_3(IColorRamp icolorRamp_1, ITinColorRampRenderer itinColorRampRenderer_1, int int_0, ITin itin_0) { IClassify classify = this.method_2((itinColorRampRenderer_1 as IClassBreaksUIProperties).Method) as IClassify; if (classify != null) { bool flag; if (classify is IClassifyMinMax2) { ITinAdvanced dataset = this.itinLayer_0.Dataset as ITinAdvanced; double zMin = dataset.Extent.ZMin; double zMax = dataset.Extent.ZMax; (classify as IClassifyMinMax2).ClassifyMinMax(zMin, zMax, ref int_0); } else if (!(classify is IDeviationInterval)) { } itinColorRampRenderer_1.BreakCount = int_0; this.bool_0 = false; this.cboClassifyNum.SelectedIndex = int_0 - 1; this.bool_0 = true; double[] classBreaks = (double[])classify.ClassBreaks; if (classBreaks.Length == 0) { icolorRamp_1.Size = 5; } else { icolorRamp_1.Size = classBreaks.Length; } icolorRamp_1.CreateRamp(out flag); IEnumColors colors = icolorRamp_1.Colors; ISymbol sym = null; for (int i = 0; i < (classBreaks.Length - 1); i++) { IColor color = colors.Next(); if ((itinColorRampRenderer_1 as ITinRenderer).Name == "Elevation") { ISimpleFillSymbol symbol2 = new SimpleFillSymbolClass { Color = color, Style = esriSimpleFillStyle.esriSFSSolid }; sym = symbol2 as ISymbol; } else if ((itinColorRampRenderer_1 as ITinRenderer).Name == "Node elevation") { IMarkerSymbol symbol3 = new SimpleMarkerSymbolClass { Color = color }; sym = symbol3 as ISymbol; } itinColorRampRenderer_1.set_Symbol(i, sym); (itinColorRampRenderer_1 as IClassBreaksUIProperties).set_LowBreak(i, classBreaks[i]); itinColorRampRenderer_1.set_Break(i, classBreaks[i + 1]); string label = classBreaks[i].ToString() + " - " + classBreaks[i + 1].ToString(); itinColorRampRenderer_1.set_Label(i, label); } } }
public IRasterDataset TinToRaster_new(ITinAdvanced pTin, esriRasterizationType eRastConvType, String sDir, String sName, rstPixelType ePixelType, Double cellsize, IEnvelope pExtent, bool bPerm) { IPoint pOrigin = pExtent.LowerLeft; //pOrigin.X = pOrigin.X - (cellsize * 0.5); //pOrigin.Y = pOrigin.Y - (cellsize * 0.5); pOrigin.X = pOrigin.X; pOrigin.Y = pOrigin.Y; int nCol, nRow; nCol = (int)Math.Round(pExtent.Width / cellsize); nRow = (int)Math.Round(pExtent.Height / cellsize); IGeoDataset pGDS = pTin as IGeoDataset; ISpatialReference2 pSR = pGDS.SpatialReference as ISpatialReference2; //这个pOrigin为栅格左下角 IWorkspaceFactory pworkspaceFactory = new RasterWorkspaceFactory(); IRasterWorkspace2 rasterws = pworkspaceFactory.OpenFromFile(sDir, 0) as IRasterWorkspace2; IPoint originpoint = pOrigin; //用于计算的 float型的栅格数据 IRasterDataset demdataset = rasterws.CreateRasterDataset(sName, "TIFF", originpoint, nCol, nRow, cellsize, cellsize, 1, rstPixelType.PT_DOUBLE, null, true); IRasterDataset pRDS = demdataset; //IRawPixels pRawPixels = GetRawPixels(pRDS, 0); IRaster pRaster = pRDS.CreateDefaultRaster(); IPnt pBlockSize = new DblPnt(); //nCol = 50; //nRow = 50; pBlockSize.X = nCol; pBlockSize.Y = nRow; IPixelBlock pPixelBlock = pRaster.CreatePixelBlock(pBlockSize); //IPixelBlock pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize); IPixelBlock3 pPixelBlock3 = pPixelBlock as IPixelBlock3; //object val = pPixelBlock.get_SafeArray(0); ITinSurface pTinSurf = pTin as ITinSurface; // IRasterProps pRasterProps = pRawPixels as IRasterProps; IRasterProps pRasterProps = pRaster as IRasterProps; object nodata; //pOrigin.X = pOrigin.X + (cellsize * 0.5); //pOrigin.Y = pOrigin.Y + (cellsize * nRow) - (cellsize * 0.5); pOrigin.X = pOrigin.X; pOrigin.Y = pOrigin.Y + (cellsize * nRow); nodata = pRasterProps.NoDataValue; IGeoDatabaseBridge2 pbridge2 = (IGeoDatabaseBridge2) new GeoDatabaseHelperClass(); //这个pOrigin为栅格左上角 //pbridge2.QueryPixelBlock(pTinSurf, pOrigin.X, pOrigin.Y, cellsize, cellsize, esriRasterizationType.esriElevationAsRaster, nodata, ref val); //if (pTin.ProcessCancelled) // return null; //val.GetType(); CalPixelArray(pTinSurf, pOrigin.X, pOrigin.Y, cellsize, cellsize, ref pPixelBlock3); IPnt pOffset = new DblPnt(); pOffset.X = 0; pOffset.Y = 0; //pPixelBlock3.set_PixelData(0, val); //pRawPixels.Write(pOffset, (IPixelBlock)pPixelBlock3);//写入硬盘 IRasterEdit prasteredit = pRaster as IRasterEdit; prasteredit.Write(pOffset, (IPixelBlock)pPixelBlock3); //pRDS = OpenOutputRasterDataset(sDir, sName); //IPixelBlock pb = pRaster.CreatePixelBlock(pBlockSize); //pRaster.Read(pOffset,pb); // ISaveAs pSaveas = pRasterProps as ISaveAs2; // pSaveas.SaveAs(sDir + "\\" + sName, null, "TIFF"); prasteredit.Refresh(); return(pRDS); }
private void method_0(IClassify iclassify_0, ITinColorRampRenderer itinColorRampRenderer_0, int int_0, ITin itin_1) { bool flag; IRandomColorRamp ramp = new RandomColorRampClass { StartHue = 40, EndHue = 120, MinValue = 65, MaxValue = 90, MinSaturation = 25, MaxSaturation = 45, Size = 5, Seed = 23 }; IColorRamp ramp2 = ramp; if (iclassify_0 is IClassifyMinMax2) { ITinAdvanced advanced = itin_1 as ITinAdvanced; double zMin = advanced.Extent.ZMin; double zMax = advanced.Extent.ZMax; (iclassify_0 as IClassifyMinMax2).ClassifyMinMax(zMin, zMax, ref int_0); } else if (!(iclassify_0 is IDeviationInterval)) { } itinColorRampRenderer_0.BreakCount = int_0; double[] classBreaks = (double[])iclassify_0.ClassBreaks; if (classBreaks.Length == 0) { ramp2.Size = 5; } else { ramp2.Size = classBreaks.Length; } ramp2.CreateRamp(out flag); IEnumColors colors = ramp2.Colors; ISymbol sym = null; for (int i = 0; i < (classBreaks.Length - 1); i++) { IColor color = colors.Next(); if ((itinColorRampRenderer_0 as ITinRenderer).Name == "Elevation") { ISimpleFillSymbol symbol2 = new SimpleFillSymbolClass { Color = color, Style = esriSimpleFillStyle.esriSFSSolid }; sym = symbol2 as ISymbol; } else if ((itinColorRampRenderer_0 as ITinRenderer).Name == "Node elevation") { IMarkerSymbol symbol3 = new SimpleMarkerSymbolClass { Color = color }; sym = symbol3 as ISymbol; } itinColorRampRenderer_0.set_Symbol(i, sym); (itinColorRampRenderer_0 as IClassBreaksUIProperties).set_LowBreak(i, classBreaks[i]); itinColorRampRenderer_0.set_Break(i, classBreaks[i + 1]); string label = classBreaks[i].ToString() + " - " + classBreaks[i + 1].ToString(); itinColorRampRenderer_0.set_Label(i, label); } }