private void _CalculateFlowDir() { OnProgress("Filling DEM..."); // - Fill & calculate flow direction IHydrologyOp hydroOp = new RasterHydrologyOpClass(); IRasterMakerOp rasterMaker = new RasterMakerOpClass(); ILogicalOp logicalOp = new RasterMathOpsClass(); IConditionalOp conditionalOp = new RasterConditionalOpClass(); IGeoDataset fillTemp = null; IGeoDataset flowTemp = null; IGeoDataset flowTemp2 = null; IGeoDataset demNulls = null; IGeoDataset zeroRaster = null; IWorkspace resultWorkspace = null; try { SetAnalysisEnvironment((IRasterAnalysisEnvironment)hydroOp); SetAnalysisEnvironment((IRasterAnalysisEnvironment)rasterMaker); SetAnalysisEnvironment((IRasterAnalysisEnvironment)conditionalOp); SetAnalysisEnvironment((IRasterAnalysisEnvironment)logicalOp); object zLimit = null; fillTemp = hydroOp.Fill((IGeoDataset)_punchedDEM, ref zLimit); //Make output permanent resultWorkspace = GetResultRasterWorkspace(); ITemporaryDataset tempFillDataset = ((IRasterAnalysisProps)fillTemp).RasterDataset as ITemporaryDataset; string fillPath = CreateTempFileName(_GetResultDir(), "filldem", ""); string fillFileName = System.IO.Path.GetFileName(fillPath); tempFillDataset.MakePermanentAs(fillFileName, resultWorkspace, "GRID"); _filledDEM = ((IRasterWorkspace)resultWorkspace).OpenRasterDataset(fillFileName).CreateDefaultRaster() as IRaster; OnProgress("Calculating flow direction..."); flowTemp = hydroOp.FlowDirection((IGeoDataset)fillTemp, false, true); //Set holes to flowdir of 0 object boxedFlowTemp = flowTemp; zeroRaster = rasterMaker.MakeConstant(0.0, true); flowTemp2 = conditionalOp.Con(logicalOp.IsNull((IGeoDataset)fillTemp), zeroRaster, ref boxedFlowTemp); demNulls = logicalOp.IsNull((IGeoDataset)_dem); string flowPath = CreateTempFileName(_GetResultDir(), "flowdir", ""); _flowDir = GeoprocessingTools.SetNull((IRaster)demNulls, (IRaster)flowTemp2, flowPath); } finally { UrbanDelineationExtension.ReleaseComObject(flowTemp); UrbanDelineationExtension.ReleaseComObject(flowTemp2); UrbanDelineationExtension.ReleaseComObject(demNulls); UrbanDelineationExtension.ReleaseComObject(zeroRaster); UrbanDelineationExtension.ReleaseComObject(conditionalOp); UrbanDelineationExtension.ReleaseComObject(logicalOp); UrbanDelineationExtension.ReleaseComObject(rasterMaker); UrbanDelineationExtension.ReleaseComObject(hydroOp); UrbanDelineationExtension.ReleaseComObject(resultWorkspace); } OnProgress("Flow direction calculated."); }
private void _CalculateFlowDir() { OnProgress("Filling DEM..."); // - Fill & calculate flow direction IHydrologyOp hydroOp = new RasterHydrologyOpClass(); IRasterMakerOp rasterMaker = new RasterMakerOpClass(); ILogicalOp logicalOp = new RasterMathOpsClass(); IGeoDataset flowTemp = null; IRaster flowTemp2 = null; IGeoDataset demNulls = null; IGeoDataset zeroRaster = null; try { SetAnalysisEnvironment((IRasterAnalysisEnvironment)hydroOp); SetAnalysisEnvironment((IRasterAnalysisEnvironment)rasterMaker); SetAnalysisEnvironment((IRasterAnalysisEnvironment)logicalOp); string fillPath = CreateTempFileName(_GetResultDir(), "filldem", ""); _filledDEM = GeoprocessingTools.Fill(_punchedDEM, fillPath); OnProgress("Calculating flow direction..."); flowTemp = hydroOp.FlowDirection((IGeoDataset)_filledDEM, false, true); //Set holes to flowdir of 0 zeroRaster = rasterMaker.MakeConstant(0.0, true); string flowTemp2Path = CreateTempFileName(_GetTempDir(), "flowtemp2", ""); flowTemp2 = GeoprocessingTools.Con((IRaster)logicalOp.IsNull((IGeoDataset)_filledDEM), (IRaster)zeroRaster, (IRaster)flowTemp, flowTemp2Path); demNulls = logicalOp.IsNull((IGeoDataset)_dem); string flowPath = CreateTempFileName(_GetResultDir(), "flowdir", ""); _flowDir = GeoprocessingTools.SetNull((IRaster)demNulls, flowTemp2, flowPath); } finally { UrbanDelineationExtension.ReleaseComObject(flowTemp); UrbanDelineationExtension.ReleaseComObject(flowTemp2); UrbanDelineationExtension.ReleaseComObject(demNulls); UrbanDelineationExtension.ReleaseComObject(zeroRaster); UrbanDelineationExtension.ReleaseComObject(logicalOp); UrbanDelineationExtension.ReleaseComObject(rasterMaker); UrbanDelineationExtension.ReleaseComObject(hydroOp); } OnProgress("Flow direction calculated."); }
private void _PunchDEM() { OnProgress("Punching DEM with drainage points..."); IConversionOp conversionOp = new RasterConversionOpClass(); ILogicalOp logicalOp = new RasterMathOpsClass(); IGeoDataset inletLocations = null; IWorkspace tempWorkspace = null; try { tempWorkspace = GetTempRasterWorkspace(); SetAnalysisEnvironment((IRasterAnalysisEnvironment)conversionOp); SetAnalysisEnvironment((IRasterAnalysisEnvironment)logicalOp); IFeatureClassDescriptor sourceDescriptor = new FeatureClassDescriptorClass(); sourceDescriptor.Create(_drainClass, null, _drainClass.OIDFieldName); string gridPath = SetupOp.CreateTempFileName(_GetTempDir(), "TmpInlets", null); string gridName = System.IO.Path.GetFileName(gridPath); IRasterDataset pRasterDataset = null; try { pRasterDataset = conversionOp.ToRasterDataset((IGeoDataset)sourceDescriptor, "GRID", tempWorkspace, gridName); inletLocations = logicalOp.BooleanNot(logicalOp.IsNull((IGeoDataset)pRasterDataset)); string outputPath = CreateTempFileName(_GetResultDir(), "punchdem", ""); _punchedDEM = GeoprocessingTools.SetNull((IRaster)inletLocations, _dem, outputPath); } finally { _MarkForDisposal((IDataset)pRasterDataset); } } finally { UrbanDelineationExtension.ReleaseComObject(tempWorkspace); UrbanDelineationExtension.ReleaseComObject(conversionOp); UrbanDelineationExtension.ReleaseComObject(logicalOp); } OnProgress("DEM punched."); }
private void _DelineateInletCatchments() { OnProgress("Delineating inlet catchments..."); //Determine output path string outputDir = _GetResultDir(); string outputPathSmooth = SetupOp.CreateTempFileName(outputDir, "Catchments_smooth", ".shp"); string outputPathDetailed = SetupOp.CreateTempFileName(outputDir, "Catchments_detailed", ".shp"); string outputNameSmooth = System.IO.Path.GetFileNameWithoutExtension(outputPathSmooth); string outputNameDetailed = System.IO.Path.GetFileNameWithoutExtension(outputPathDetailed); //Calculate catchments IRaster seedGrid = _DrainagePointsToSeedGrid(_drainClass, "SeedPts", SetupOp.EID_FIELD_NAME); string watershedPath = CreateTempFileName(_GetTempDir(), "inletws", ""); IRaster catchmentGrid = GeoprocessingTools.Watershed(_flowDir, seedGrid, watershedPath); OnProgress("Converting catchments to polygon..."); IFeatureClass smoothCatchmentClass = RasterToPolygon(catchmentGrid, outputNameSmooth, outputDir, true); IFeatureClass detailedCatchmentClass = RasterToPolygon(catchmentGrid, outputNameDetailed, outputDir, false); if (_smooth) { _catchmentClass = smoothCatchmentClass; } else { _catchmentClass = detailedCatchmentClass; } var seedDataset = ((IRasterAnalysisProps)seedGrid).RasterDataset; _MarkForDisposal((IDataset)seedDataset); var catchmentDataset = ((IRasterAnalysisProps)catchmentGrid).RasterDataset; _MarkForDisposal(catchmentGrid as IDataset); OnProgress("Inlet catchments delineated."); }