Exemple #1
0
        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.");
        }
Exemple #2
0
        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.");
        }
Exemple #3
0
        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.");
        }