Exemple #1
0
        protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            //1 select features based on geometry
            System.Windows.Point bottomRight = new System.Windows.Point();
            Dictionary <BasicFeatureLayer, List <long> > allfeatures = new Dictionary <BasicFeatureLayer, List <long> >();
            await QueuedTask.Run(() =>
            {
                allfeatures = ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.New, false, false);
            });

            //2 build a context menu with the layers and (re)select by user's layer-choice
            ShowContextMenu(bottomRight, allfeatures);

            //3
            BasicFeatureLayer bfl = null;

            foreach (KeyValuePair <BasicFeatureLayer, List <long> > entry in allfeatures)
            {
                if (entry.Key.SelectionCount > 0)
                {
                    bfl = entry.Key;
                }
            }

            return(true);
        }
Exemple #2
0
 protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
 {
     return(ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
     {
         // Using the active map view to select
         // the features that intersect the sketch geometry
         ActiveMapView.SelectFeatures(geometry);
         return true;
     }));
 }
Exemple #3
0
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            WKTExportFlags exportFlagsNoZ = WKTExportFlags.wktExportStripZs;
            WKTExportFlags exportFlagsNoM = WKTExportFlags.wktExportStripMs;
            var            wktString      = GeometryEngine.Instance.ExportToWKT(exportFlagsNoZ | exportFlagsNoM, geometry);

            Debug.WriteLine("geometry = " + wktString);

            var srid = geometry.SpatialReference.GcsWkid;

            Debug.WriteLine("srid = " + srid);

            //String sql = String.Format("select id from public.features where ST_Intersects(geom, ST_GeomFromText('{0}', {1}))", wktString, srid);
            String sql = String.Format("select id from public.features where ST_Intersects(geom, ST_Buffer(ST_GeomFromText('{0}', {1}), 0.05))", wktString, srid);

            Debug.WriteLine("sql = " + sql);
            Npgsql.NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;User Id=postgres; " +
                                                                "Password=postgres;Database=geomapmaker;");
            conn.Open();
            NpgsqlCommand    command = new NpgsqlCommand(sql, conn);
            NpgsqlDataReader dr      = command.ExecuteReader();

            DataTable dT = new DataTable();

            dT.Load(dr);

            foreach (DataRow row in dT.Rows)
            {
                Debug.Write("Hi there \n");
                //Debug.Write("{0} \n", row["name"].ToString());
                Debug.WriteLine(row["id"].ToString());
            }
            conn.Close();

            //return base.OnSketchCompleteAsync(geometry);
            return(ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
            {
                // Using the active map view to select
                // the features that intersect the sketch geometry
                ActiveMapView.SelectFeatures(geometry);
                return true;
            }));
        }
Exemple #4
0
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            return(QueuedTask.Run(() =>
            {
                try
                {
                    ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.Subtract);
                }

                catch (Exception ex)
                {
                    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 local GIS nerd.\n\n{ex}";

                    //Using the ArcGIS Pro SDK MessageBox class
                    MessageBox.Show(message, caption);
                }
                return true;
            }));
        }
Exemple #5
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;
            }));
        }
Exemple #6
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);
        }
Exemple #7
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;
            }));
        }
Exemple #8
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);
        }
Exemple #9
0
        protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            try
            {
                var standaloneTable = await QueuedTask.Run(() =>
                {
                    ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.New);
                    slComp = Module1.GetCompkey();
                    if (!string.IsNullOrEmpty(slComp))
                    {
                        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 = $"COMPKEY = {slComp}";
                            QueryDef queryDef  = new QueryDef()
                            {
                                Tables      = "SDE.sewerman.tblV8PMTOOL",
                                WhereClause = queryString,
                            };

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

                            var 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 base.OnSketchCompleteAsync(geometry);
                    return(null);
                });

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

            catch (Exception)
            {
                string caption = "Error Occured";
                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);
            }
            return(true);
        }