private void button1_Click(object sender, EventArgs e) { IGeoDataset inGeoDataSet; IGeoDataset outGeoDataSet; ISurfaceOp SurfaceOp = new RasterSurfaceOpClass(); ILayer layer = GetLayerByName(comboBox1.SelectedItem.ToString()); IRasterLayer rasterLayer = layer as IRasterLayer; IRaster raster = rasterLayer.Raster; inGeoDataSet = raster as IGeoDataset; azimuthAngle = System.Convert.ToDouble(azimuthBox.Text); verticalAngle = System.Convert.ToDouble(verticalBox.Text); outGeoDataSet = SurfaceOp.HillShade(inGeoDataSet, azimuthAngle, verticalAngle, true); try { IWorkspaceFactory pWKSF = new RasterWorkspaceFactoryClass(); IWorkspace pWorkspace = pWKSF.OpenFromFile(System.IO.Path.GetDirectoryName(textBox1.Text), 0); ISaveAs pSaveAs = outGeoDataSet as ISaveAs; pSaveAs.SaveAs(System.IO.Path.GetFileName(textBox1.Text), pWorkspace, "TIFF"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } IRasterLayer pRlayer = new RasterLayer(); pRlayer.CreateFromRaster((IRaster)outGeoDataSet); pRlayer.Name = System.IO.Path.GetFileName(textBox1.Text); mainForm.axMapControl1.AddLayer(pRlayer, 0); }
public IRaster CreateRasterHillShade(IRaster raster) { try { RasterSurfaceOpClass class2 = new RasterSurfaceOpClass(); IGeoDataset geoDataset = raster as IGeoDataset; double zFactor = Convert.ToDouble(textBoxX3.Text); if (zFactor <= 0) { MessageBox.Show("请指定大于0的正数!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } object o = zFactor; double azimuth = slider2.Value; double altitude = slider1.Value; bool inModelShadows = false; if (cmbRenderType.SelectedIndex == 1) { inModelShadows = true; } IGeoDataset pGeoDataset = class2.HillShade(geoDataset, azimuth, altitude, inModelShadows, ref o); IRaster pRaster = (IRaster)pGeoDataset; ISaveAs2 pSaveAs = pRaster as ISaveAs2; IDataset pDataset = pSaveAs.SaveAs(m_ResultPath + ".tif", null, "TIFF"); System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataset); MessageBox.Show("山体阴影计算完毕!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return(pRaster); } catch (SystemException e) { MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } }