Beispiel #1
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.");
        }
Beispiel #2
0
        private IRaster _DrainagePointsToSeedGrid(IFeatureClass featureClass, string baseName, string valueField)
        {
            Geoprocessor gp         = new Geoprocessor();
            bool         addOutputs = gp.AddOutputsToMap;

            try
            {
                IRasterDataset demRasterDataset = ((IRasterAnalysisProps)DEM).RasterDataset;
                IDataset       demDataset       = (IDataset)demRasterDataset;
                string         path             = System.IO.Path.Combine(demDataset.Workspace.PathName, demDataset.Name);

                gp.SetEnvironmentValue("snapRaster", path);

                string extent = string.Format("{0} {1} {2} {3}", ((IGeoDataset2)demRasterDataset).Extent.XMin, ((IGeoDataset2)demRasterDataset).Extent.YMin, ((IGeoDataset2)demRasterDataset).Extent.XMax, ((IGeoDataset2)demRasterDataset).Extent.YMax);
                gp.SetEnvironmentValue("extent", extent);

                gp.AddOutputsToMap = false;

                FeatureToRaster featureToRasterTool = new FeatureToRaster();

                featureToRasterTool.cell_size = ((IRasterAnalysisProps)DEM).PixelHeight;
                featureToRasterTool.field     = valueField;

                IDataset dataset          = (IDataset)featureClass;
                string   featureClassPath = System.IO.Path.Combine(dataset.Workspace.PathName, dataset.Name + ".shp");
                featureToRasterTool.in_features = featureClassPath;

                string outputName = SetupOp.CreateTempFileName(this.ScratchDirectory, baseName, null);
                featureToRasterTool.out_raster = outputName;

                string outputShortName = System.IO.Path.GetFileNameWithoutExtension(outputName);

                RunTool(gp, featureToRasterTool, null);

                IRasterWorkspace rws = this.GetTempRasterWorkspace() as IRasterWorkspace;
                return(rws.OpenRasterDataset(outputShortName).CreateDefaultRaster());
            }
            finally
            {
                gp.AddOutputsToMap = addOutputs;
            }
        }
Beispiel #3
0
        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
            IHydrologyOp hydroOp       = new RasterHydrologyOpClass();
            IGeoDataset  seedGrid      = null;
            IGeoDataset  catchmentGrid = null;

            try
            {
                SetAnalysisEnvironment((IRasterAnalysisEnvironment)hydroOp);
                seedGrid      = (IGeoDataset)_DrainagePointsToSeedGrid(_drainClass, "SeedPts", SetupOp.EID_FIELD_NAME);
                catchmentGrid = hydroOp.Watershed((IGeoDataset)_flowDir, seedGrid);
                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;
                }

                _MarkForDisposal((IDataset)seedGrid);
                _MarkForDisposal(catchmentGrid as IDataset);
            }
            finally
            {
                UrbanDelineationExtension.ReleaseComObject(hydroOp);
            }
            OnProgress("Inlet catchments delineated.");
        }
Beispiel #4
0
        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.");
        }