Esempio n. 1
0
        private void btnPreprocess_Click(object sender, EventArgs e)
        {
            try
            {
                System.Windows.Forms.Application.DoEvents();
                System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

                DialogResult choice = MessageBox.Show(this, "Depending on the size of the network and DEM, this operation may take a long time.",
                                                      Properties.Resources.Caption_Notice, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                if (choice == DialogResult.OK)
                {
                    SetupOp setupOp = UrbanDelineationExtension.Extension.Setup;

                    setupOp.GeometricNetwork = cbxNetwork.SelectedValue as IGeometricNetwork;
                    IFeatureLayer inletLayer = cbxInlets.SelectedValue as IFeatureLayer;
                    setupOp.InletClass = inletLayer.FeatureClass;
                    IRasterLayer demLayer = cbxDEM.SelectedValue as IRasterLayer;
                    setupOp.DEM = demLayer.Raster;
                    setupOp.IncludeUpstreamPipeEnds   = chkIncludeUp.Checked;
                    setupOp.ExcludeDisabledNodes      = chkExcludeDisabled.Checked;
                    setupOp.ExcludeDownstreamPipeEnds = chkExcludeDown.Checked;
                    setupOp.SmoothBoundaries          = chkSmooth.Checked;
                    setupOp.Preprocess();

                    //Add results to map
                    EnumLayer layers = new EnumLayer();

                    IFeatureLayer drainLayer = new FeatureLayerClass();
                    drainLayer.FeatureClass = setupOp.DrainagePoints;
                    drainLayer.Name         = "Drainage Points";
                    drainLayer.Visible      = false;
                    layers.Add(drainLayer);

                    IRasterLayer punchedLayer = new RasterLayerClass();
                    punchedLayer.CreateFromRaster(setupOp.PunchedDEM);
                    punchedLayer.Name    = "Punched DEM";
                    punchedLayer.Visible = false;
                    layers.Add(punchedLayer);

                    IRasterLayer fillLayer = new RasterLayerClass();
                    fillLayer.CreateFromRaster(setupOp.FilledDEM);
                    fillLayer.Name    = "Filled DEM";
                    fillLayer.Visible = false;
                    layers.Add(fillLayer);

                    IRasterLayer flowDirLayer = new RasterLayerClass();
                    flowDirLayer.CreateFromRaster(setupOp.FlowDirection);
                    flowDirLayer.Name    = "Flow Direction";
                    flowDirLayer.Visible = false;
                    layers.Add(flowDirLayer);

                    IFeatureLayer catchmentLayer = new FeatureLayerClass();
                    catchmentLayer.FeatureClass = setupOp.Catchments;
                    catchmentLayer.Name         = "Inlet Catchments";
                    catchmentLayer.Visible      = false;
                    ((ILayerEffects)catchmentLayer).Transparency = 50;
                    layers.Add(catchmentLayer);

                    IMap map = null;
                    try
                    {
                        map = ArcMap.Document.FocusMap;
                        map.AddLayers(layers, true);

                        cbxFlowDirGrid.SelectedValue = flowDirLayer;
                        cbxCatchments.SelectedValue  = catchmentLayer;
                    }
                    finally
                    {
                        UrbanDelineationExtension.ReleaseComObject(map);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, Properties.Resources.Caption_Error);
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = Cursors.Default;
            }
        }
Esempio n. 2
0
        private void btnDelineate_Click(object sender, EventArgs e)
        {
            try
            {
                if (_CheckInput())
                {
                    System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

                    Delineator delineator = new Delineator();
                    delineator.Setup                  = UrbanDelineationExtension.Extension.Setup;
                    delineator.OutletSource           = cbxOutletSource.SelectedValue as IFeatureLayer;
                    delineator.OutletIdField          = cbxOutletField.SelectedValue as string;
                    delineator.ExtendOverland         = chkExtendOverland.Checked;
                    delineator.StopAtDisabledFeatures = chkStopAtDisabled.Checked;

                    if (chkSnapToPourPoint.Enabled && chkSnapToPourPoint.Checked)
                    {
                        delineator.SnapToPourPoint = true;
                        double snapDistance;
                        if (double.TryParse(tbxSnapDistance.Text, out snapDistance))
                        {
                            delineator.SnapDistance = snapDistance;
                        }
                    }
                    else
                    {
                        delineator.SnapToPourPoint = false;
                    }

                    delineator.DelineateCatchments();

                    EnumLayer layers = new EnumLayer();

                    //Add results to map
                    IFeatureLayer watershedLayer = new FeatureLayerClass();
                    watershedLayer.FeatureClass = delineator.OutletWatersheds;
                    watershedLayer.Name         = delineator.OutletWatersheds.AliasName;
                    ((ILayerEffects)watershedLayer).Transparency = 50;
                    if (!string.IsNullOrEmpty(delineator.OutletIdField))
                    {
                        _AddLabel(watershedLayer, delineator.OutletIdField);
                    }
                    layers.Add(watershedLayer);

                    IMap map = null;
                    try
                    {
                        map = ArcMap.Document.FocusMap;
                        map.AddLayers(layers, true);
                    }
                    finally
                    {
                        UrbanDelineationExtension.ReleaseComObject(map);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, Properties.Resources.Caption_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = Cursors.Default;
            }
        }