Example #1
0
        //
        //����դ������������
        //
        public static IDistanceOp SetRasterDisAnalysisEnv(string rasterpath, double cellSize, IFeatureLayer pFeatLayer)
        {
            object Missing = Type.Missing;
            IWorkspace pWorkspace;
            pWorkspace = UtilityFunction.setRasterWorkspace(rasterpath);
            IDistanceOp pDistranceOp = new RasterDistanceOpClass();

            IRasterAnalysisEnvironment pRsEnv = pDistranceOp as IRasterAnalysisEnvironment;
            pRsEnv.OutWorkspace = pWorkspace;
            //װ�����
            object objCellSize = cellSize;

            pRsEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objCellSize);
            IEnvelope pEnv = new EnvelopeClass();
            pEnv.XMin = pFeatLayer.AreaOfInterest.XMin;
            pEnv.XMax = pFeatLayer.AreaOfInterest.XMax;
            pEnv.YMin = pFeatLayer.AreaOfInterest.YMin;
            pEnv.YMax = pFeatLayer.AreaOfInterest.YMax;
            object objExtent = pEnv;
            pRsEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objExtent, ref Missing);
            return pDistranceOp;
        }
Example #2
0
        private void buildPathAllocation()
        {
            IDistanceOp2 dOp = new RasterDistanceOpClass();
            IRasterAnalysisEnvironment rasterAnalysisEnvironment = (ESRI.ArcGIS.GeoAnalyst.IRasterAnalysisEnvironment)dOp;

            rasterAnalysisEnvironment.OutSpatialReference = ((IGeoDataset)Dem).SpatialReference;
            rasterAnalysisEnvironment.OutWorkspace        = OutWorkspace;
            object ext  = ((IGeoDataset)RoadFeatureClass).Extent;
            object snap = ((IGeoDataset)Dem);

            rasterAnalysisEnvironment.SetCellSize(ESRI.ArcGIS.GeoAnalyst.esriRasterEnvSettingEnum.esriRasterEnvValue, Dem);
            rasterAnalysisEnvironment.SetExtent(ESRI.ArcGIS.GeoAnalyst.esriRasterEnvSettingEnum.esriRasterEnvValue, ext, Dem);
            IRasterAnalysisGlobalEnvironment analysisGlobalEnv = (IRasterAnalysisGlobalEnvironment)dOp;

            analysisGlobalEnv.AvoidDataConversion = true;

            IRasterOpBase      rasOpBase = (IRasterOpBase)dOp;
            IRasterDatasetName rasDatasetName;

            rasDatasetName = new RasterDatasetNameClass();

            IDatasetName datasetName;

            datasetName = (IDatasetName)rasDatasetName;
            datasetName.WorkspaceName = (IWorkspaceName)((IDataset)OutWorkspace).FullName;
            string onRoadNm = rsUtil.getSafeOutputName(OutWorkspace, "onRoadHr");

            datasetName.Name = onRoadNm;
            rasOpBase.AddOutputDatasetName(0, datasetName);

            object noVl = Type.Missing;
            IFunctionRasterDataset cr1    = rsUtil.calcArithmaticFunction(RoadRaster, speedConFactor, esriRasterArithmeticOperation.esriRasterMultiply);
            IFunctionRasterDataset costRs = rsUtil.calcArithmaticFunction(1, cr1, esriRasterArithmeticOperation.esriRasterDivide);
            IGeoDataset            rpdOut = dOp.PathDistance((IGeoDataset)FacilityFeatureClass, costRs, Dem, noVl, noVl, noVl, noVl, noVl, noVl);//outputs in hours

            FunctionAccumulatedPathDistance = rsUtil.createIdentityRaster((IRaster)rpdOut);
            // Use FunctonAccumulated Path Distance (hours) for allocation
            string frRoadDist = rsUtil.getSafeOutputName(OutWorkspace, "offRoadHr");

            datasetName.Name = frRoadDist;

            string             frRoadAllo      = rsUtil.getSafeOutputName(OutWorkspace, "onRoadAllo");
            IRasterDatasetName rasDatasetName2 = new RasterDatasetNameClass();
            IDatasetName       datasetName2    = (IDatasetName)rasDatasetName2;

            datasetName2.WorkspaceName = (IWorkspaceName)((IDataset)OutWorkspace).FullName;
            datasetName2.Name          = frRoadAllo;

            string             frRoadBack      = rsUtil.getSafeOutputName(OutWorkspace, "offRoadBack");
            IRasterDatasetName rasDatasetName3 = new RasterDatasetNameClass();
            IDatasetName       datasetName3    = (IDatasetName)rasDatasetName3;

            datasetName3.WorkspaceName = (IWorkspaceName)((IDataset)OutWorkspace).FullName;
            datasetName3.Name          = frRoadBack;

            rasOpBase.AddOutputDatasetName(0, datasetName);
            rasOpBase.AddOutputDatasetName(1, datasetName3);
            rasOpBase.AddOutputDatasetName(2, datasetName2);
            IFunctionRasterDataset costRS = null;

            //add in barriers to costRS
            if (OffRoadSpeedRaster != null)
            {
                IFunctionRasterDataset c1 = rsUtil.calcArithmaticFunction(OffRoadSpeedRaster, speedConFactor, esriRasterArithmeticOperation.esriRasterMultiply);
                costRS = rsUtil.calcArithmaticFunction(1, c1, esriRasterArithmeticOperation.esriRasterDivide);
            }
            else
            {
                costRS = rsUtil.constantRasterFunction(FunctionAccumulatedPathDistance, 1 / (OffRoadSpeed * speedConFactor));
            }

            //add in barriers to costRs
            IFunctionRasterDataset rdCs = null;//rsUtil.calcArithmaticFunction(FunctionAccumulatedPathDistance, 1000, esriRasterArithmeticOperation.esriRasterMultiply, rstPixelType.PT_LONG);

            if (BarriersFeatureClass != null)
            {
                IFunctionRasterDataset[] rslt = addBarrierRasters(costRS, FunctionAccumulatedPathDistance);
                costRS = rslt[0];
                rdCs   = rslt[1];
            }
            else
            {
                rdCs = rsUtil.calcArithmaticFunction(FunctionAccumulatedPathDistance, 1000, esriRasterArithmeticOperation.esriRasterMultiply, rstPixelType.PT_LONG);
            }
            IGeoDataset           rpdOut2 = dOp.PathDistanceFull((IGeoDataset)rdCs, true, false, true, costRS, Dem, noVl, noVl, noVl, noVl, noVl, rdCs);
            IRasterBandCollection rsbc    = (IRasterBandCollection)rpdOut;

            FunctionAccumulatedFromPathDistance = rsUtil.getBand((IRaster)rpdOut2, 0);
            FunctionAccumulatedPathAllocation   = rsUtil.getBand((IRaster)rpdOut2, 1);
        }
Example #3
0
        protected override void OnMouseUp(MouseEventArgs arg)
        {
            base.OnMouseUp(arg);

            IMxDocument document = null;

            try
            {
                // Get user point
                document = ArcMap.Document;
                IPoint mapPoint = ArcMap.ThisApplication.Display.DisplayTransformation.ToMapPoint(arg.X, arg.Y);

                // Get flow direction
                SetupOp setupOp = UrbanDelineationExtension.Extension.Setup;
                IRaster flowDir = setupOp.FlowDirection;
                if (flowDir == null)
                {
                    MessageBox.Show(_appWindow, Properties.Resources.Error_NoFlowDirection, Properties.Resources.Category_UrbanDelineation);
                    return;
                }
                IGeoDataset flowDirDataset = (IGeoDataset)flowDir;

                // Process point
                IPointCollection pointCollection = new MultipointClass();
                ((IGeometry)pointCollection).SpatialReference = flowDirDataset.SpatialReference;
                mapPoint.Project(flowDirDataset.SpatialReference);
                IPoint[] points = new IPoint[] { mapPoint };
                pointCollection.AddPoints(1, ref points[0]);

                // Get flow path geometry
                IPolyline   flowPath   = null;
                string      outputDir  = null;
                IDistanceOp distanceOp = new RasterDistanceOpClass();
                try
                {
                    IEnvelope outputExtent = _GetSurfaceOutputExtent(mapPoint);
                    if (outputExtent == null)
                    {
                        setupOp.SetAnalysisEnvironment((IRasterAnalysisEnvironment)distanceOp);
                    }
                    else
                    {
                        // Expand to ensure full boundary of watershed is included.
                        double cellWidth  = ((IRasterAnalysisProps)setupOp.FlowDirection).PixelWidth;
                        double cellHeight = ((IRasterAnalysisProps)setupOp.FlowDirection).PixelHeight;
                        outputExtent.Expand(cellWidth * 3.0, cellHeight * 3.0, false);

                        setupOp.SetAnalysisEnvironment((IRasterAnalysisEnvironment)distanceOp, outputExtent);
                    }

                    // The RasterDistanceOpClass does not properly clean up after itself, so we have to do it ourselves
                    // To do this, we need to track the output directory and delete it, since we don't have direct access to the
                    // dataset that is left behind. To delete the directory, it must contain only the temp files generated by
                    // the RasterDistanceOpClass and no others, so we create one here. The directory is then deleted in the
                    // finally clause.
                    ((IRasterAnalysisEnvironment)distanceOp).OutWorkspace = _GetUniqueOutputWorkspace();
                    outputDir = ((IRasterAnalysisEnvironment)distanceOp).OutWorkspace.PathName;

                    IGeometryCollection flowPaths = distanceOp.CostPathAsPolyline(pointCollection, flowDirDataset, flowDirDataset);
                    if (flowPaths.GeometryCount > 0)
                    {
                        flowPath = flowPaths.get_Geometry(0) as IPolyline;
                    }
                }
                finally
                {
                    UrbanDelineationExtension.ReleaseComObject(distanceOp);
                    try
                    {
                        if (Directory.Exists(outputDir))
                        {
                            Directory.Delete(outputDir, true);
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("FlowTracingTool.OnMouseUp: " + ex.GetType().FullName + ": " + ex.Message);
                    }
                }

                // Add flow path to map
                if (flowPath != null && !flowPath.IsEmpty)
                {
                    // Create graphic element
                    flowPath.SpatialReference = flowDirDataset.SpatialReference;
                    // Weed removes points that are in-line since flow path is generated with vertices for every cell, even if they are exactly in-line
                    ((IPolycurve)flowPath).Weed(0.001);
                    IElement flowElement = new LineElementClass();
                    ((IElementProperties3)flowElement).Name = ELEMENT_NAME;
                    flowElement.Geometry = flowPath;

                    // Set color
                    ILineSymbol lineSymbol  = ((ILineElement)flowElement).Symbol;
                    IRgbColor   color       = lineSymbol.Color as IRgbColor;
                    Color       systemColor = Color.Red;
                    color.Blue       = systemColor.B;
                    color.Red        = systemColor.R;
                    color.Green      = systemColor.G;
                    lineSymbol.Color = color;
                    ((ILineElement)flowElement).Symbol = lineSymbol;

                    ((IGraphicsContainer)document.FocusMap.BasicGraphicsLayer).AddElement(flowElement, 0);
                    ((IDocumentDirty)document).SetDirty();

                    document.ActiveView.Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(_appWindow, ex.Message, Properties.Resources.Caption_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                UrbanDelineationExtension.ReleaseComObject(document);
            }
        }
        public IGeoDataset CreateDistanceOpCostPathRaster(IGeoDataset pGeoDataset1, IGeoDataset pGeoDataset2, IGeoDataset pGeoDataset3)
        {
            IDistanceOp pDistanceOp = new RasterDistanceOpClass();

             IGeoDataset pGeoDatasetOutput = pDistanceOp.CostPath(pGeoDataset1, pGeoDataset2, pGeoDataset3, esriGeoAnalysisPathEnum.esriGeoAnalysisPathForEachZone);

             return pGeoDatasetOutput;
        }