Beispiel #1
0
        protected override void OnClick()
        {
            QueuedTask.Run(() =>
            {
                try
                {
                    var mapView     = MapView.Active.Map;
                    string urlMH    = @"O:\SHARE\405 - INFORMATION SERVICES\GIS_Layers\[email protected]\SDE.sewerman.tblEAM_Manhole_Work";
                    string urlLines = @"O:\SHARE\405 - INFORMATION SERVICES\GIS_Layers\[email protected]\SDE.sewerman.tblEAM_Sewer_Work";
                    Uri mhURI       = new Uri(urlMH);
                    Uri linesURI    = new Uri(urlLines);

                    // Check to see if the tables are already added to the map.
                    IReadOnlyList <StandaloneTable> mhTables = mapView.FindStandaloneTables("Manholes Work History");
                    IReadOnlyList <StandaloneTable> slTables = mapView.FindStandaloneTables("Sewer Lines Work History");
                    {
                        if (mhTables.Count == 0 && slTables.Count == 0)
                        {
                            StandaloneTable manholesHistory = StandaloneTableFactory.Instance.CreateStandaloneTable(mhURI, mapView, "Manholes Work History");
                            SysModule.SetDisplayField(manholesHistory, "Manholes Work History", "INIT_DATE");
                            StandaloneTable linesHistory = StandaloneTableFactory.Instance.CreateStandaloneTable(linesURI, mapView, "Sewer Lines Work History");
                            SysModule.SetDisplayField(linesHistory, "Sewer Lines Work History", "INIT_DATE");
                        }
                        else if (mhTables.Count > 0 && slTables.Count == 0)
                        {
                            StandaloneTable linesHistory = StandaloneTableFactory.Instance.CreateStandaloneTable(linesURI, mapView, "Sewer Lines Work History");
                            SysModule.SetDisplayField(linesHistory, "Sewer Lines Work History", "INIT_DATE");
                            MessageBox.Show("'Manholes Work History' table is already present in map.\n\n'Sewer Lines Work History' table has been added", "Warning");
                        }

                        else if (mhTables.Count == 0 && slTables.Count > 0)
                        {
                            StandaloneTable manholesHistory = StandaloneTableFactory.Instance.CreateStandaloneTable(mhURI, mapView, "Manholes Work History");
                            SysModule.SetDisplayField(manholesHistory, "Manholes Work History", "INIT_DATE");
                            MessageBox.Show("'Sewer Lines Work History' table is already present in map.\n\n'Manholes Work History' table has been added", "Warning");
                        }

                        else if (mhTables.Count > 0 && slTables.Count > 0)
                        {
                            MessageBox.Show("Sewer Lines and Manholes Work History tables are already present in map.", "Warning");
                        }
                    }
                }

                catch (Exception ex)
                {
                    SysModule.LogError(ex.Message, ex.StackTrace);

                    string caption = "Failed to Load Tables";
                    string message = "Process failed. \nSave and restart ArcGIS Pro and try process again.\n" +
                                     "If problem persist, contact your GIS Admin.";

                    //Using the ArcGIS Pro SDK MessageBox class
                    MessageBox.Show(message, caption);
                }
            });
        }
Beispiel #2
0
        public static void MakeManholesLayer(Map mapView)
        {
            try
            {
                // Create the "Manholes"  layer object.
                var mh = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Manholes");

                //Get the selected features from the map.
                var mhOIDList = mh.GetSelection().GetObjectIDs();                 // Gets a list of Object IDs
                var mhOID     = mh.GetTable().GetDefinition().GetObjectIDField(); // Gets the OBJECTID field name for the def query

                // Check to see if there are manhole features selected in the map.
                if (mhOIDList.Count() == 0)
                {
                    MessageBox.Show("There are no manholes selected.");
                }

                else
                {
                    // Create the defenition query
                    string defQuery = $"{mhOID} in ({string.Join(",", mhOIDList)})";
                    string url      = @"O:\SHARE\405 - INFORMATION SERVICES\GIS_Layers\[email protected]\SDE.SEWERMAN.MANHOLES_VIEW";

                    // Create the Uri object create the feature layer.
                    Uri uri            = new Uri(url);
                    var selectionLayer = LayerFactory.Instance.CreateFeatureLayer(uri, mapView, 0, "Manholes SELECTION");

                    // Apply the definition query
                    selectionLayer.SetDefinitionQuery(defQuery);

                    // Create the point symbol renderer.
                    CIMPointSymbol pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(
                        ColorFactory.Instance.GreenRGB,
                        8.0,
                        SimpleMarkerStyle.Circle
                        );
                    CIMSimpleRenderer renderer = selectionLayer.GetRenderer() as CIMSimpleRenderer;
                    // Reference the existing renderer
                    renderer.Symbol = pointSymbol.MakeSymbolReference();
                    // Apply new renderer
                    selectionLayer.SetRenderer(renderer);
                }
            }

            catch (Exception ex)
            {
                SysModule.LogError(ex.Message, ex.StackTrace);

                string caption = "Error Occurred";
                string message = "Process failed. \nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your GIS Admin.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
        }
Beispiel #3
0
        public static void SewersStatus()
        {
            try
            {
                var map         = MapView.Active.Map;
                var mhExists    = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().Any(m => m.Name == "Manholes");
                var sewerExists = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().Any(s => s.Name == "Sewer Lines");
                if (mhExists == false && sewerExists == false)
                {
                    MessageBox.Show("Manholes & Sewers are missing from map.", "Layer(s) Missing");
                }
                else if (mhExists == false && sewerExists)
                {
                    MessageBox.Show("Sewer Lines layer is present. \n\nManholes layer is missing from map.", "Layer(s) Missing");
                }
                else if (mhExists && sewerExists == false)
                {
                    MessageBox.Show("Manholes layer is present. \n\nSewers layer is missing from map.", "Layer(s) Missing");
                }

                else
                {
                    var layers = map.GetLayersAsFlattenedList().OfType <FeatureLayer>();
                    foreach (var layer in layers)
                    {
                        if (layer.Name == "Manholes" || layer.Name == "Sewer Lines")
                        //if (layer.Name == "Manholes")
                        {
                            layer.SetSelectable(true);
                        }

                        else
                        {
                            layer.SetSelectable(false);
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                SysModule.LogError(ex.Message, ex.StackTrace);

                string caption = "Error Occurred";
                string message = "Process failed. \nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your GIS Admin.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
        }
Beispiel #4
0
        protected override void OnClick()
        {
            QueuedTask.Run(() =>
            {
                try
                {
                    // Check for "Manholes" and "Sewer Lines" layers in map.
                    var mapView     = MapView.Active.Map;
                    var mhExists    = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().Any(m => m.Name == "Manholes");
                    var sewerExists = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().Any(s => s.Name == "Sewer Lines");
                    if (mhExists == false && sewerExists == false)
                    {
                        MessageBox.Show("Manholes & Sewers are missing from map.", "Warning");
                    }
                    else if (mhExists == false && sewerExists)
                    {
                        MessageBox.Show("Sewer Lines layer is present. \n\nManholes layer is missing from map.", "Warning");
                    }
                    else if (mhExists && sewerExists == false)
                    {
                        MessageBox.Show("Manholes layer is present. \n\nSewers layer is missing from map.", "Warning");
                    }

                    else
                    {
                        SysModule.MakeSewersLayers(mapView);
                    }
                }

                catch (Exception ex)
                {
                    SysModule.LogError(ex.Message, ex.StackTrace);

                    string caption = "Create selection layer(s) failed!";
                    string message = "Process failed. \nSave and restart ArcGIS Pro and try process again.\n" +
                                     "If problem persist, contact your local GIS nerd.";

                    //Using the ArcGIS Pro SDK MessageBox class
                    MessageBox.Show(message, caption);
                }
            });
        }
Beispiel #5
0
        //protected override Task OnToolActivateAsync(bool active)
        //{
        //    return base.OnToolActivateAsync(active);
        //}

        // Method returns a  bool Task.  It's a part of the StreetView class that was created with this tool.
        // Async methods called on the UI thread but run on the Main CIM Thread.
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            // All the Synchronous methods within the scope of *OnSketchCompleteAsync*
            // need to be wrapped in a *QueuedTask* to call and run on the Main CIM Thread (not the UI).
            // QueuedTasks are used to manage threads.
            return(QueuedTask.Run(() =>
            {
                double lat;
                double lon;
                if (GeometryEngine.Instance.Project(geometry, SpatialReferences.WGS84) is MapPoint coord)
                {
                    lon = coord.X;
                    lat = coord.Y;
                    try
                    {
                        OpenStreetView(lat, lon);
                    }
                    catch (Exception ex)
                    {
                        //Log error to exception log on network.
                        SysModule.LogError(ex.Message, ex.StackTrace);

                        string caption = "Error Occurred";
                        string message = "Process failed. \n\nSave and restart ArcGIS Pro and try process again.\n\n" +
                                         "If problem persist, contact GIS Admin.";

                        //Using the ArcGIS Pro SDK MessageBox class
                        MessageBox.Show(message, caption);
                    }
                }
                return true;
            }));

            // Works with S#!tty code below.  Don't think it's "correct".
            //var ret = QueuedTask.Run(() =>
            //{
            //    return true;
            //});

            //return ret;
        }
Beispiel #6
0
        protected override Task OnToolActivateAsync(bool active)
        {
            return(QueuedTask.Run(() =>
            {
                try
                {
                    var mapView = MapView.Active.Map;
                    var mh = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Manholes");
                    var lines = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Sewer Lines");

                    //Get the selected features from the map.
                    var mhOIDList = mh.GetSelection().GetObjectIDs();
                    var mhOID = mh.GetTable().GetDefinition().GetObjectIDField();
                    var linesOIDList = lines.GetSelection().GetObjectIDs();
                    var linesOID = lines.GetTable().GetDefinition().GetObjectIDField();

                    if (mhOIDList.Count() == 0 && linesOIDList.Count() == 0)
                    {
                        MessageBox.Show("Manholes & Sewers contain no selected features.", "Warning");
                    }

                    else
                    {
                        base.OnToolActivateAsync(active);
                    }
                }

                catch (Exception ex)
                {
                    SysModule.LogError(ex.Message, ex.StackTrace);

                    string caption = "Failed to de-select features!";
                    string message = $"Process failed. \n\nSave and restart ArcGIS Pro and try process again.\n\n" +
                                     $"If problem persist, contact your GIS Admin.";

                    //Using the ArcGIS Pro SDK MessageBox class
                    MessageBox.Show(message, caption);
                }
            }));
        }
Beispiel #7
0
        protected async override void OnClick()
        {
            try
            {
                OpenItemDialog addToMap = new OpenItemDialog
                {
                    Title                    = "Add Layers",
                    InitialLocation          = @"O:\SHARE\405 - INFORMATION SERVICES\GIS_Layers\Production",
                    MultiSelect              = true,
                    AlwaysUseInitialLocation = true
                };


                bool?ok = addToMap.ShowDialog();

                if (ok == true)
                {
                    IEnumerable <Item> selectedItems = addToMap.Items;
                    foreach (Item selectedItem in selectedItems)
                    {
                        await QueuedTask.Run(() =>
                                             LayerFactory.Instance.CreateLayer(selectedItem, MapView.Active.Map, LayerPosition.AutoArrange));
                    }
                }
            }

            catch (Exception ex)
            {
                SysModule.LogError(ex.Message, ex.StackTrace);

                string caption = "Failed to Add Layers";
                string message = "Process failed.\nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your GIS Admin.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
        }
Beispiel #8
0
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            return(QueuedTask.Run(() =>
            {
                try
                {
                    ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.Add);
                }

                catch (Exception ex)
                {
                    SysModule.LogError(ex.Message, ex.StackTrace);

                    string caption = "Failed to Select Features";
                    string message = "Process failed. \nSave and restart ArcGIS Pro and try process again.\n" +
                                     "If problem persist, contact your GIS Admin.";

                    //Using the ArcGIS Pro SDK MessageBox class
                    MessageBox.Show(message, caption);
                }
                return true;
            }));
        }
Beispiel #9
0
        public static string GetPipeID()
        {
            try
            {
                string pipeID;
                var    map        = MapView.Active.Map;
                var    linesLayer = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault((m => m.Name == "Sewer Lines"));

                // Get the currently selected features in the map
                var selectedFeatures = map.GetSelection();
                var selectCount      = linesLayer.SelectionCount;

                // get the first layer and its corresponding selected feature OIDs
                var firstSelectionSet = selectedFeatures.First();

                // create an instance of the inspector class
                var inspector = new Inspector();

                // load the selected features into the inspector using a list of object IDs
                inspector.Load(firstSelectionSet.Key, firstSelectionSet.Value);

                //get the value of
                return(pipeID = inspector["ARCID"].ToString());
            }
            catch (Exception ex)
            {
                SysModule.LogError(ex.Message, ex.StackTrace);

                string caption = "Error Occured";
                string message = "Process failed.\nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your GIS Admin.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
                return(null);
            }
        }
Beispiel #10
0
        protected override void OnClick()
        {
            QueuedTask.Run(() =>
            {
                try
                {
                    // Check for "Manholes" layer in map.
                    var mapView = MapView.Active.Map;

                    var linesExists = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().Any(s => s.Name == "Manholes");

                    if (linesExists)
                    {
                        SysModule.MakeManholesLayer(mapView);
                    }

                    else
                    {
                        MessageBox.Show("There is no layer named 'Manholes' in map. " +
                                        "\n\nIf a manholes layer is present, make sure the layer is named 'Manholes'. " +
                                        "This tool will not work unless the layer is spelled exactly like above.", "Missing Layer(s)");
                    }
                }

                catch (Exception ex)
                {
                    SysModule.LogError(ex.Message, ex.StackTrace);

                    string caption = "Create selection layer(s) failed!";
                    string message = "Process failed. \nSave and restart ArcGIS Pro and try process again.\n" +
                                     "If problem persist, contact your local GIS nerd.";

                    //Using the ArcGIS Pro SDK MessageBox class
                    MessageBox.Show(message, caption);
                }
            });
        }
Beispiel #11
0
        protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            try
            {
                StandaloneTable standaloneTable = await QueuedTask.Run(() =>
                {
                    ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.New);

                    var map        = MapView.Active.Map;
                    var linesLayer = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault((m => m.Name == "Sewer Lines"));

                    // Get the currently selected features in the map
                    var selectedFeatures = map.GetSelection();
                    var selectCount      = linesLayer.SelectionCount;

                    if (selectCount == 0)
                    {
                        MessageBox.Show("No Sewer Line was selected.\n\nTry selection again.");
                    }

                    else if (selectCount > 1)
                    {
                        MessageBox.Show("More than one sewer line was selected.\n" +
                                        "Try selecting sewer line again.\nZooming in may help.");
                    }

                    else
                    {
                        pipeID = SysModule.GetPipeID();
                        if (!string.IsNullOrEmpty(pipeID))
                        {
                            Uri path = new Uri("O:\\SHARE\\405 - INFORMATION SERVICES\\GIS_Layers\\[email protected]");

                            // Set up Geodatabase Object)
                            using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(path)))
                            {
                                string queryString = $"PIPE_ID = '{pipeID}'";
                                QueryDef queryDef  = new QueryDef()
                                {
                                    Tables      = "SDE.sewerman.tblEAM_PM",
                                    WhereClause = queryString,
                                    SubFields   = "PIPE_ID, TASK, PREVDATE, NEXTDATE, INTERVAL, UNIT, OBJECTID",
                                };

                                QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
                                {
                                    MakeCopy    = true,
                                    Name        = $"Preventive Maintenance: {pipeID}",
                                    PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("SDE.sewerman.tblEAM_PM", "PIPE_ID")
                                };

                                Table queryTable = geodatabase.OpenQueryTable(queryTableDescription);

                                int count = queryTable.GetCount();
                                if (count == 0)
                                {
                                    MessageBox.Show("Sewer line selected has no preventive maintenance scheduled.");
                                }

                                else
                                {
                                    // Create a standalone table from the queryTable Table
                                    IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
                                    StandaloneTable pmTable = tableFactory.CreateStandaloneTable(queryTable, MapView.Active.Map);

                                    return(pmTable);
                                }
                            }
                        }
                        ;
                    }
                    return(null);
                });

                // Open the standalone table pane
                FrameworkApplication.Panes.OpenTablePane(standaloneTable, TableViewMode.eAllRecords);
            }

            catch (Exception ex)
            {
                SysModule.LogError(ex.Message, ex.StackTrace);

                string caption = "Error Occured";
                string message = "Process failed.\nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your GIS Admin.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
            return(true);
        }
Beispiel #12
0
        protected override Task OnToolActivateAsync(bool active)
        {
            return(QueuedTask.Run(() =>
            {
                try
                {
                    var map = MapView.Active.Map;
                    map.SetSelection(null);
                    var mhExists = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().Any(m => m.Name == "Manholes");
                    var sewerExists = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().Any(s => s.Name == "Sewer Lines");

                    // Check for the SEWER LINES Layer and MANHOLES layers in the map.
                    if (mhExists == false && sewerExists == false)
                    {
                        MessageBox.Show("Manholes & Sewer Lines are missing from map.\n" +
                                        "'Manholes' and 'Sewer Lines' layers must be named exactly as such for trace to work",
                                        "Missing Layer(s)");
                    }
                    else if (mhExists == false && sewerExists)
                    {
                        MessageBox.Show("Sewer Lines layer is present. " +
                                        "\n\nManholes layer is missing from map." +
                                        "\n'Manholes' layer must be named exactly as such for trace to work",
                                        "Missing Layer(s)");
                    }
                    else if (mhExists && sewerExists == false)
                    {
                        MessageBox.Show("Manholes layer is present. " +
                                        "\n\nSewer Lines layer is missing from map." +
                                        "\n'Sewer Lines' layer must be named exactly as such for trace to work",
                                        "Missing Layer(s)");
                    }
                    else
                    {
                        // Build the Dictionaries now that it has been confirmed that the necessary layers are in map.
                        SysModule.BuildDictionariesAsync(arcNodeListDict, nodeArcListDict);

                        //Make manholes the only selectabe layer in map.
                        var layers = map.GetLayersAsFlattenedList().OfType <FeatureLayer>();
                        foreach (var layer in layers)
                        {
                            if (layer.Name == "Manholes")
                            {
                                layer.SetSelectable(true);
                            }
                            else
                            {
                                layer.SetSelectable(false);
                            }
                        }
                    }
                }

                catch (Exception ex)
                {
                    SysModule.LogError(ex.Message, ex.StackTrace);

                    string caption = "Selection Failed";
                    string message = "Manhole selection failed. " +
                                     "\n\nSave and restart ArcGIS Pro and try process again.\n\n" +
                                     "If problem persist, contact your local GIS Admin.";

                    //Using the ArcGIS Pro SDK MessageBox class
                    MessageBox.Show(message, caption);
                }
            }));
        }
Beispiel #13
0
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            return(QueuedTask.Run(() =>
            {
                try
                {
                    ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.New);


                    var map = MapView.Active.Map;
                    var mhLayer = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault((m => m.Name == "Manholes"));

                    // Get the currently selected features in the map
                    var selectedFeatures = map.GetSelection();
                    var selectCount = mhLayer.SelectionCount;

                    if (selectCount == 0)
                    {
                        MessageBox.Show("No manhole was selected." +
                                        "\n\nTry selecting a manhole again.");
                    }
                    else if (selectCount > 1)
                    {
                        MessageBox.Show("More than one manhole selected." +
                                        "\n\nTry selecting manholes again. Zooming in may help.");
                    }
                    else
                    {
                        progDial.Show();


                        // get the first layer and its corresponding selected feature OIDs
                        var firstSelectionSet = selectedFeatures.First();

                        // create an instance of the inspector class
                        var inspector = new Inspector();

                        // load the selected features into the inspector using a list of object IDs
                        inspector.Load(firstSelectionSet.Key, firstSelectionSet.Value);

                        //get the value of
                        string mhNum = inspector["MH_NO"].ToString();

                        // Create the workArcList to store the Arcs(VALUES as int) from the nodeArcListDict
                        // for the selected mhNum(KEY as string)
                        List <int> workArcList = new List <int>();

                        // Output the Arc ObjectID (VALUES) as List<int> for the selected mhNum (KEY)
                        nodeArcListDict.TryGetValue(mhNum, out List <int> arcValues);

                        // Loop through Output List<int> and add VALUE to workArcList
                        foreach (var arcValue in arcValues)
                        {
                            workArcList.Add(arcValue);
                        }

                        // Create the removeArcsList to store the Arcs(VALUES as int)
                        List <int> removeArcsList = new List <int>();

                        // loop through workArcList check if it contains downstream node = mhNum selected by user
                        foreach (var workArc in workArcList)
                        {
                            // Get the list of Values from the arcNodeListDict for the current arc KEY (workArc) in workArcList.
                            arcNodeListDict.TryGetValue(workArc, out List <string> nodeWorkVals);

                            //Get the downstream manhole [0] from list.
                            string downMH = nodeWorkVals[1];

                            // Check if downstream manhole and selected manhole are the same.
                            if (downMH == mhNum)
                            {
                                // Add to removeArcList
                                removeArcsList.Add(workArc);
                            }
                        }

                        // Loop through removeArcsList remove each removeArc in list from workArcList (this is getting confusing)
                        foreach (var removeArc in removeArcsList)
                        {
                            // Remove from workArcList
                            workArcList.Remove(removeArc);
                        }

                        if (workArcList.Count() == 0)
                        {
                            MessageBox.Show("No downstream sewer lines found.", "Warning!");
                        }

                        // Create dictionary to store downstream arcs that will be used to create query string.
                        // Only reason dictionary is used is because it's a quick way to prevent duplicate KEYS.
                        Dictionary <string, string> downStreamArcDict = new Dictionary <string, string>();

                        //string downStreamNode = "";
                        List <string> workManholeList = new List <string>();

                        int loopCount = 0;

                        // At start of loop, workArcList has >0 arcs from initial selection.
                        do
                        {
                            loopCount++;

                            workManholeList.Clear();
                            removeArcsList.Clear();

                            foreach (var arc in workArcList)
                            {
                                if (downStreamArcDict.ContainsKey(arc.ToString()) == false)
                                {
                                    // Add arc to downstream arc dictionary
                                    downStreamArcDict.Add(arc.ToString(), "TRUE");
                                }
                            }

                            foreach (var dwnArc in workArcList)
                            {
                                arcNodeListDict.TryGetValue(dwnArc, out List <string> nodeWorkVals);

                                //Get the downstream manhole [1] from list.
                                string downMH = nodeWorkVals[1];

                                // Add downstream manhole for selected downstream arc to workManholeList.
                                // This will be used to get more more downstream arcs later.
                                workManholeList.Add(downMH);
                            }

                            // Clear workArcList to add new arcs later.
                            workArcList.Clear();

                            // Get all the arcs connected to all the manholes in the workManholeList using nodeArcListDict dictionary.
                            // Add these arcs to workArcList.
                            foreach (var mh in workManholeList)
                            {
                                // Get all the arcs attached to manhole/node.
                                nodeArcListDict.TryGetValue(mh, out List <int> arcVals);
                                // Add list of arcs to workArcList list.
                                workArcList.AddRange(arcVals);
                            }

                            // Loop through all the arcs in workArcList and for arcs that have downstream manholes in the workManholeList,
                            // add that arc to removeArcsList.
                            foreach (var arc2 in workArcList)
                            {
                                // get list of nodes for arcs in workArcList.
                                arcNodeListDict.TryGetValue(arc2, out List <string> nodeWorkVals2);

                                // Get the downstream manhole [0] from list.
                                string downMH = nodeWorkVals2[1];

                                // Check workManholeList for downMH and remove from removeArcList if TRUE.
                                if (workManholeList.Contains(downMH))
                                {
                                    removeArcsList.Add(arc2);
                                }
                            }

                            // Remove arcs in removeArcsList from workArcsList
                            foreach (var arc3 in removeArcsList)
                            {
                                workArcList.Remove(arc3);
                            }



                            // Loop through again if condition is met.
                        } while (workArcList.Count > 0);



                        // Build the query string from the downStreamArcDict KEYS to select the downstream sewer lines.
                        int count = 0;

                        var stringBuilder = new StringBuilder();

                        foreach (var key in downStreamArcDict.Keys)
                        {
                            if (count == 0)
                            {
                                stringBuilder.Append($"OBJECTID IN ({key}");
                            }
                            else if (count < downStreamArcDict.Keys.Count)
                            {
                                stringBuilder.Append($",{key}");
                            }

                            count++;
                        }
                        stringBuilder.Append($")");

                        // Select sewers using StringBuilder object above for the WhereClause.
                        QueryFilter queryFilter = new QueryFilter {
                            WhereClause = stringBuilder.ToString()
                        };
                        var sewerLines = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Sewer Lines");
                        var manholes = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Manholes");

                        sewerLines.Select(queryFilter, SelectionCombinationMethod.New);

                        progDial.Hide();
                    }
                }

                catch (Exception ex)
                {
                    SysModule.LogError(ex.Message, ex.StackTrace);

                    string caption = "Trace Failed";
                    string message = "Downstream trace failed! \nSave and restart ArcGIS Pro and try process again.\n" +
                                     "If problem persist, contact your GIS Admin.";

                    progDial.Hide();

                    //Using the ArcGIS Pro SDK MessageBox class
                    MessageBox.Show(message, caption);
                }
                return true;
            }));
        }
Beispiel #14
0
        protected override void OnClick()
        {
            ProgressDialog progDial = new ProgressDialog("I'm doing my thing.\nPlease be patient, Human.", false);

            QueuedTask.Run(() =>
            {
                try
                {
                    var map         = MapView.Active.Map;
                    var mhExists    = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().Any(m => m.Name == "Manholes");
                    var sewerExists = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().Any(s => s.Name == "Sewer Lines");

                    // Check for the SEWER LINES Layer and MANHOLES layers in the map.
                    if (mhExists == false && sewerExists == false)
                    {
                        MessageBox.Show("Manholes & Sewers are missing from map.", "Missing Layer(s)");
                    }
                    else if (mhExists == false && sewerExists)
                    {
                        MessageBox.Show("Sewer Lines layer is present. \n\nManholes layer is missing from map.", "Missing Layer(s)");
                    }
                    else if (mhExists && sewerExists == false)
                    {
                        MessageBox.Show("Manholes layer is present. \n\nSewers layer is missing from map.", "Missing Layer(s)");
                    }
                    else
                    {
                        var sewerLines  = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Sewer Lines");
                        var manholes    = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Manholes");
                        var selectCount = sewerLines.SelectionCount;

                        if (selectCount == 0)
                        {
                            MessageBox.Show("No sewer trace is in map! \n\nA sewer trace must be performed to add\nmanholes associate with trace.", "Sewer Trace Missing!");
                        }

                        else
                        {
                            progDial.Show();
                            string spatialRelate = "INTERSECT";
                            int distance         = 0;
                            string selectType    = "NEW_SELECTION";
                            string invertRelate  = "NOT_INVERT";

                            var parameters = Geoprocessing.MakeValueArray(manholes, spatialRelate, sewerLines, distance, selectType, invertRelate);

                            Geoprocessing.ExecuteToolAsync("management.SelectLayerByLocation", parameters);
                            progDial.Hide();
                        }
                    }
                }

                catch (Exception ex)
                {
                    SysModule.LogError(ex.Message, ex.StackTrace);

                    string caption = "Add Manholes to Trace Failed";
                    string message = "Failed to add manholes selection to trace. \n\nSave and restart ArcGIS Pro and try process again.\n" +
                                     "If problem persist, contact your local GIS nerd.";
                    progDial.Hide();


                    //Using the ArcGIS Pro SDK MessageBox class
                    MessageBox.Show(message, caption);
                }
            });
        }
Beispiel #15
0
        protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            try
            {
                var standaloneTable = await QueuedTask.Run(() =>
                {
                    ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.New);

                    var map   = MapView.Active.Map;
                    var mh    = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(m => m.Name == "Manholes");
                    var lines = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Sewer Lines");

                    // Get the number of selections for manholes layer
                    var selectedFeatures = map.GetSelection();
                    var mhSelectCount    = mh.SelectionCount;
                    var linesSelectCount = lines.SelectionCount;
                    Uri path             = new Uri("O:\\SHARE\\405 - INFORMATION SERVICES\\GIS_Layers\\[email protected]");

                    // If Manholes layer has selection, remove lines selection and query work history for manhole selected.
                    if (mhSelectCount == 1)
                    {
                        lines.ClearSelection();
                        mhID = SysModule.GetManholeID();
                        //Uri path = new Uri("O:\\SHARE\\405 - INFORMATION SERVICES\\GIS_Layers\\[email protected]");

                        // Set up Geodatabase Object)
                        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(path)))
                        {
                            string queryString = $"MH_ID = '{mhID}'";
                            QueryDef queryDef  = new QueryDef()
                            {
                                Tables      = "SDE.sewerman.tblEAM_Manhole_Work",
                                WhereClause = queryString,
                            };

                            QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
                            {
                                MakeCopy    = true,
                                Name        = $"Manhole work history: {mhID}",
                                PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("SDE.sewerman.tblEAM_Manhole_Work", "MH_ID")
                            };

                            var queryTable = geodatabase.OpenQueryTable(queryTableDescription);
                            int count      = queryTable.GetCount();
                            if (count == 0)
                            {
                                MessageBox.Show("Manhole selected has no work history.");
                                return(null);
                            }

                            else
                            {
                                // Create a standalone table from the queryTable Table
                                IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
                                StandaloneTable whTable = tableFactory.CreateStandaloneTable(queryTable, MapView.Active.Map);

                                return(whTable);
                            }
                        }
                    }

                    // Query work history forSewer Lines selection
                    else if (linesSelectCount == 1)
                    {
                        pipeID = SysModule.GetPipeID();
                        //Uri path = new Uri("O:\\SHARE\\405 - INFORMATION SERVICES\\GIS_Layers\\[email protected]");

                        // Set up Geodatabase Object)
                        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(path)))
                        {
                            string queryString = $"PIPE_ID = '{pipeID}'";
                            QueryDef queryDef  = new QueryDef()
                            {
                                Tables      = "SDE.sewerman.tblEAM_Sewer_Work",
                                WhereClause = queryString,
                            };

                            QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
                            {
                                MakeCopy    = true,
                                Name        = $"Sewer line work history: {pipeID}",
                                PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("SDE.sewerman.tblEAM_Sewer_Work", "PIPE_ID")
                            };

                            var queryTable = geodatabase.OpenQueryTable(queryTableDescription);

                            int count = queryTable.GetCount();
                            if (count == 0)
                            {
                                MessageBox.Show("Sewer line selected has no work history.");
                                return(null);
                            }

                            else
                            {
                                // Create a standalone table from the queryTable Table
                                IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
                                StandaloneTable whTable = tableFactory.CreateStandaloneTable(queryTable, MapView.Active.Map);

                                return(whTable);
                            }
                        }
                    }

                    else if (linesSelectCount == 0 && mhSelectCount == 0)
                    {
                        MessageBox.Show("No manhole or sewer line was selected.\n\nTry selection again.");
                    }

                    else if (linesSelectCount > 1 && mhSelectCount == 0)
                    {
                        MessageBox.Show("More than one sewer line was selected. " +
                                        "\nPlease select a single sewer. " +
                                        "\nZooming in may help.");
                    }

                    else if (mhSelectCount > 1 && linesSelectCount == 0)
                    {
                        MessageBox.Show("More than one manhole was selected. " +
                                        "\nPlease select a single manhole. " +
                                        "\nZooming in may help.");
                    }

                    else if (mhSelectCount > 1 && linesSelectCount > 1)
                    {
                        MessageBox.Show("More than one sewer feature was selected. " +
                                        "\nPlease select a single feature. " +
                                        "\nZooming in may help.");
                    }
                    return(null);
                });

                // Open the standalone table pane
                FrameworkApplication.Panes.OpenTablePane(standaloneTable, TableViewMode.eAllRecords);
            }

            catch (Exception ex)
            {
                SysModule.LogError(ex.Message, ex.StackTrace);

                string caption = "Error Occured";
                string message = "Process failed.\nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your GIS Admin.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
            return(true);
            //return base.OnSketchCompleteAsync(geometry);
        }