private void FormMain_Load(object sender, EventArgs e) { Ctrl_Tab.SelectedIndex = 1; Ctrl_Tab.SelectedIndex = 0; IFeatureWorkspace pFWorkspace = OpenWorkspace(@"data.gdb") as IFeatureWorkspace; INetworkDataset networkDataset = OpenNetworkDataset(pFWorkspace as IWorkspace, "rdCenLineDataSet_ND", "rdCenLineDataSet"); m_NAContext = CreateSolverContext(networkDataset); INetworkLayer pNetworkLayer = new NetworkLayerClass(); pNetworkLayer.NetworkDataset = networkDataset; ILayer pLayer = pNetworkLayer as ILayer; pLayer.Name = "NetworkLayer"; Ctrl_Map.AddLayer(pLayer, 0); IFeatureLayer pJunctionLayer = new FeatureLayerClass(); pJunctionLayer.FeatureClass = pFWorkspace.OpenFeatureClass("rdCenLineDataSet_ND_Junctions"); pJunctionLayer.Name = pJunctionLayer.FeatureClass.AliasName; Ctrl_Map.AddLayer(pJunctionLayer, 0); IFeatureLayer pRoadLayer = new FeatureLayerClass(); pRoadLayer.FeatureClass = pFWorkspace.OpenFeatureClass("road_toLine"); pRoadLayer.Name = pRoadLayer.FeatureClass.AliasName; Ctrl_Map.AddLayer(pRoadLayer, 0); INALayer pNALayer = m_NAContext.Solver.CreateLayer(m_NAContext); (pNALayer as ILayer).Name = m_NAContext.Solver.DisplayName; Ctrl_Map.AddLayer(pNALayer as ILayer, 0); }
private void Btn_Slope_Click(object sender, EventArgs e) { IRasterLayer pFromRasterLayer = m_selectedLayer as IRasterLayer; if (pFromRasterLayer == null) { MessageBox.Show("非栅格图层"); return; } IRaster pFromRaster = pFromRasterLayer.Raster; IRasterBandCollection pFromRasterBandCollection = pFromRaster as IRasterBandCollection; IRasterBand pFromRasterBand = pFromRasterBandCollection.Item(0); IRasterDataset pFromRasterDataset = pFromRasterBand as IRasterDataset; IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass(); IRasterWorkspace pRasterWorkspace = pWorkspaceFactory.OpenFromFile(@"DB", 0) as IRasterWorkspace; ISurfaceOp pSurfaceOp = new RasterSurfaceOpClass(); IRasterAnalysisEnvironment pRasterAnalysisEnvironment; pRasterAnalysisEnvironment = pSurfaceOp as IRasterAnalysisEnvironment; pRasterAnalysisEnvironment.OutWorkspace = pWorkspaceFactory as IWorkspace; object zFactor = new object(); IGeoDataset pGeoDataset, pRasterGetDataset; pRasterGetDataset = pFromRasterDataset as IGeoDataset; pGeoDataset = pSurfaceOp.Slope(pRasterGetDataset, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopePercentrise, ref zFactor); IRasterBandCollection pOutRasterBandCollection = pGeoDataset as IRasterBandCollection; string strOutRasterName = pFromRasterLayer.Name.Split('.')[0] + "_slope.tif"; pOutRasterBandCollection.SaveAs(strOutRasterName, pRasterWorkspace as IWorkspace, "TIFF"); IRasterDataset pNewRasterDataset = pRasterWorkspace.OpenRasterDataset(strOutRasterName); IRasterLayer pNewRasterLayer = new RasterLayerClass(); pNewRasterLayer.CreateFromDataset(pNewRasterDataset); ILayer pNewLayer = pNewRasterLayer as ILayer; Ctrl_Map.AddLayer(pNewLayer); }