예제 #1
0
        /// <summary>
        /// Initialize a QueryBuilderControlProperties with the specified mapMember.  Use the current definition query of that mapMember (if it exists) to extend the
        /// initialization.
        /// </summary>
        /// <param name="mapMember">MapMember to initialize the QueryBuilderControlProperties. </param>
        private void BuildControlProperties(MapMember mapMember)
        {
            // find the current definition query for the mapMember
            string            expression = "";
            BasicFeatureLayer fLayer     = mapMember as BasicFeatureLayer;
            StandaloneTable   table      = mapMember as StandaloneTable;

            if (fLayer != null)
            {
                expression = fLayer.DefinitionQuery;
            }
            else if (table != null)
            {
                expression = table.DefinitionQuery;
            }

            // create it
            var props = new QueryBuilderControlProperties()
            {
                MapMember  = mapMember,
                Expression = expression,
            };

            // set the binding properties
            this.ControlProperties = props;
            MapMemberName          = mapMember?.Name ?? "";

            // keep track of the original expression
            _origExpression = expression;
        }
        private void exportMapContent(string xml, string outputDir)
        {
            var doc = new XmlDocument();

            doc.LoadXml(xml);
            XmlNodeList nodelist = doc.ChildNodes;
            Map         map      = MapView.Active.Map;
            var         cm       = CIMMap.FromXml(xml);

            foreach (var layer in cm.Layers)
            {
                Layer lyr = map.FindLayer(layer, true);

                GetLayerNode(lyr, doc);
            }
            foreach (var st in cm.StandaloneTables)
            {
                StandaloneTable tbl = map.FindStandaloneTable(st);
                XmlNode         lnd;
                lnd = doc.SelectSingleNode("//StandaloneTables/String[text()='" + tbl.URI + "']");
                CIMService          cs       = new MapMemberService((MapMember)tbl);
                var                 xmlLayer = cs.GetDefinitionAsync();
                XmlDocumentFragment xfrag    = doc.CreateDocumentFragment();
                xfrag.InnerXml = xmlLayer.Result;
                XmlNode nd = xfrag.FirstChild;
                lnd.AppendChild(nd);
            }
            string str = TransformDocument(doc.InnerXml, System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"Stylesheet\CIMMap.xslt"), System.IO.Path.Combine(outputDir, MakeValidFileName(map.Name)));
        }
예제 #3
0
        /// <summary>
        /// This model class validates the selected features in a map.
        /// </summary>
        /// <param name="map">The map to validate</param>
        /// <returns></returns>
        public static Task <string> ValidateMap(Map map)
        {
            return(QueuedTask.Run <string>(() =>
            {
                StringBuilder validationStringBuilder = new StringBuilder();

                // Get the selection from the map

                Dictionary <MapMember, List <long> > mapMembersWithSelection = map.GetSelection();

                // Step through each MapMember (FeatureLayer or StandaloneTable) that contains selected features

                foreach (KeyValuePair <MapMember, List <long> > dictionaryItem in mapMembersWithSelection)
                {
                    if (dictionaryItem.Key is FeatureLayer)
                    {
                        FeatureLayer featureLayer = dictionaryItem.Key as FeatureLayer;
                        using (Table table = featureLayer.GetTable())
                        {
                            validationStringBuilder.Append(ValidateTable(table, featureLayer.GetSelection()));
                        }
                    }
                    else if (dictionaryItem.Key is StandaloneTable)
                    {
                        StandaloneTable standaloneTable = dictionaryItem.Key as StandaloneTable;
                        using (Table table = standaloneTable.GetTable())
                        {
                            validationStringBuilder.Append(ValidateTable(table, standaloneTable.GetSelection()));
                        }
                    }
                }
                return validationStringBuilder.ToString();
            }));
        }
예제 #4
0
        public static void SetDisplayField(StandaloneTable saTable, string tableName, string fieldName)
        {
            var mapView = MapView.Active.Map;

            QueuedTask.Run(() =>
            {
                //Gets a list of the standalone tables in map with the name specified in the method arguments.
                IReadOnlyList <StandaloneTable> tables = mapView.FindStandaloneTables(tableName);
                foreach (var table in tables)
                {
                    //Gets the list of fields from the stand alone table.
                    var descriptions = table.GetFieldDescriptions();
                    foreach (var desc in descriptions)
                    {
                        if (desc.Name == fieldName) // If field name equals "INITDATE"
                        {
                            //Creates variable that's equal to "INITDATE"
                            string displayName = desc.Name;

                            // Get's the CIM definition from the StandaloneTable
                            var cimTableDefinition = table.GetDefinition() as CIMStandaloneTable;

                            // Set DisplayField property of the cimTableDefinition equall to displayName("INITDATE")
                            cimTableDefinition.DisplayField = displayName;

                            // USe the SetDefinition method to apply the modified table definition (cimTableDefninition)
                            saTable.SetDefinition(cimTableDefinition);

                            // Use to check the result when debugin in break point.
                            var result = table.GetDefinition().DisplayField;
                        }
                    }
                }
            });
        }
예제 #5
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);
                }
            });
        }
        protected override void OnClick()
        {
            QueuedTask.Run(async() =>
            {
                //find layer and derive geodatabase
                var cpLayer = MapView.Active.Map.FindLayers("CrowdPlanning").FirstOrDefault() as FeatureLayer;

                if (cpLayer == null)
                {
                    return;
                }
                var geodatabase = cpLayer.GetFeatureClass().GetDatastore() as Geodatabase;

                //Advise if the project has edits. Need to clear edits to make schema changes.
                if (Project.Current.HasEdits)
                {
                    MessageBox.Show("Please save or discard edits", "Pending Edits");
                    return;
                }

                //Delete and Create the editlog table
                //For the purpose of this sample, start with a fresh table
                var mva = Geoprocessing.MakeValueArray(geodatabase.GetPath().AbsolutePath, "EditLog");
                var cts = new System.Threading.CancellationTokenSource();
                await Geoprocessing.ExecuteToolAsync("CreateTable_management", mva);

                //add fields to editlog
                var tablePath = geodatabase.GetPath().AbsolutePath + @"\EditLog";
                mva           = Geoprocessing.MakeValueArray(tablePath, "Layer", "STRING");
                await Geoprocessing.ExecuteToolAsync("AddField_management", mva);
                mva = Geoprocessing.MakeValueArray(tablePath, "OID", "LONG");
                await Geoprocessing.ExecuteToolAsync("AddField_management", mva);
                mva = Geoprocessing.MakeValueArray(tablePath, "Date", "DATE");
                await Geoprocessing.ExecuteToolAsync("AddField_management", mva);
                mva = Geoprocessing.MakeValueArray(tablePath, "EditType", "STRING");
                await Geoprocessing.ExecuteToolAsync("AddField_management", mva);

                _ehTable = MapView.Active.Map.FindStandaloneTables("EditLog").FirstOrDefault();

                //setup row events for layer
                if (_rowChangedToken == null)
                {
                    _rowChangedToken = RowChangedEvent.Subscribe(OnRowEvent, cpLayer.GetTable());
                }
                if (_rowCreatedToken == null)
                {
                    _rowCreatedToken = RowCreatedEvent.Subscribe(OnRowEvent, cpLayer.GetTable());
                }
                if (_rowDeletedToken == null)
                {
                    _rowDeletedToken = RowDeletedEvent.Subscribe(OnRowEvent, cpLayer.GetTable());
                }
            });
        }
예제 #7
0
파일: Main.cs 프로젝트: agrc/TrailsAddin
        Main()
        {
            // get layer references
            SegmentsLayer             = GetLayer(TrailSegments);
            HeadsLayer                = GetLayer(Trailheads);
            TempSegmentsLayer         = GetLayer("Temporary Segments");
            USNGLayer                 = GetLayer("SGID10.INDICES.NationalGrid");
            RoutesStandaloneTable     = GetStandAloneTable(Routes);
            RouteToTrailSegmentsTable = GetStandAloneTable(RouteToTrailSegments);
            RouteToTrailheadsTable    = GetStandAloneTable(RouteToTrailheads);

            MapSelectionChangedEvent.Subscribe((MapSelectionChangedEventArgs args) =>
            {
                if (BuildOnSelect && args.Selection.Keys.Contains(SegmentsLayer as MapMember))
                {
                    AddSelectedToTemp();
                }

                if (args.Selection.Keys.Contains(RoutesStandaloneTable) && !BuildOnSelect)
                {
                    if (RoutesStandaloneTable.SelectionCount == 0)
                    {
                        SelectedRoute = null;
                        return;
                    }

                    if (RoutesStandaloneTable.SelectionCount > 1)
                    {
                        SelectedRoute = null;
                        return;
                    }

                    ShowRoute();
                }
                else
                {
                    SelectedRoute = null;
                }
            });
        }
        public bool AddLayerFromTable(ITable theTable, string aName, bool Messages = false)
        {
            // check we have nput
            if (theTable == null)
            {
                if (Messages)
                {
                    MessageBox.Show("Please pass a table", "Add Layer From Table");
                }
                return false;
            }
            IMap pMap = GetMap();
            if (pMap == null)
            {
                if (Messages)
                {
                    MessageBox.Show("No map found", "Add Layer From Table");
                }
                return false;
            }
            IStandaloneTableCollection pStandaloneTableCollection = (IStandaloneTableCollection)pMap;
            IStandaloneTable pTable = new StandaloneTable();
            IMxDocument mxDoc = GetIMXDocument();

            pTable.Table = theTable;
            pTable.Name = aName;

            // Remove if already exists
            if (TableLayerExists(aName))
                RemoveStandaloneTable(aName);

            mxDoc.UpdateContents();
            
            pStandaloneTableCollection.AddStandaloneTable(pTable);
            mxDoc.UpdateContents();
            return true;
        }
 public static Task <CIMStandaloneTable> GetDefinitionAsync(this StandaloneTable tbl)
 {
     return(QueuedTask.Run(() => {
         return tbl.GetDefinition();
     }));
 }
예제 #10
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);
        }
        public async Task AddToMapCallback2(CancelableProgressorSource cpd)
        {
            try
            {
                await QueuedTask.Run(() =>
                {
                    if (MapView.Active == null)
                    {
                        _strMessage.SelectString = "No active map view.";
                        cpd.Message = "There is no active map view.  Please select a map and try again.";
                        return;
                    }

                    //create table name for the toc layer
                    Random r       = new Random();
                    int n          = r.Next();
                    string s       = n.ToString();
                    s              = s.Substring(s.Length - 4);
                    string lyrname = _currentTable + "_" + s;

                    //open an Esri database connection type to sap
                    ComboBoxItem item2      = (ComboBoxItem)cboEnv.cboBox.SelectedItem;
                    ConnectionItem connitem = item2.Icon as ConnectionItem;
                    string tst2             = new System.Net.NetworkCredential(string.Empty, connitem.pass).Password;
                    string serverport       = connitem.server.ToString();
                    DatabaseConnectionProperties connectionProperties;

                    if (Globals.RdbmsType == "Hana")
                    {
                        string inst          = serverport.Substring(0, serverport.IndexOf(":"));
                        connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.Hana)
                        {
                            AuthenticationMode = AuthenticationMode.DBMS,
                            Instance           = inst, //cboEnv.cboBox.Text, //@"sapqe2hana",
                            User     = connitem.userid,
                            Password = tst2,
                            Version  = "dbo.DEFAULT"
                        };
                    }
                    else if (Globals.RdbmsType == "Oracle")
                    {
                        connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
                        {
                            AuthenticationMode = AuthenticationMode.DBMS,
                            Instance           = serverport, //cboEnv.cboBox.Text, //@"sapqe2hana",
                            User     = connitem.userid,
                            Password = tst2,
                            Version  = "sde.DEFAULT"
                        };
                    }

                    //=====================add to map
                    QueryText.SelectString = "SELECT * FROM \"" + _currentSchema + "\".\"" + _currentTable + "\"";

                    using (Database db = new Database(connectionProperties))
                    {
                        QueryDescription qds = db.GetQueryDescription(_querytext.SelectString, lyrname);

                        Table pTab2 = db.OpenTable(qds);

                        if (_spatialCol.SelectString != "" && _objidCol.SelectString != "none")
                        {
                            _strMessage.SelectString = "Adding Layer";
                            // Add a new layer to the map
                            FeatureLayer pFL = (FeatureLayer)LayerFactory.Instance.CreateLayer(pTab2.GetDataConnection(), MapView.Active.Map, layerName: lyrname);
                            pFL.Select(null, SelectionCombinationMethod.New);
                            MapView.Active.ZoomToSelected();
                            pFL.ClearSelection();
                            FeatureClass featureClass = pFL.GetFeatureClass();


                            _strMessage.SelectString = "Layer added.";
                            cpd.Message = "Layer added.";
                            MessageBox.Show("Layer added successsful to map.");
                        }
                        else
                        {
                            StandaloneTable pFL      = (StandaloneTable)StandaloneTableFactory.Instance.CreateStandaloneTable(pTab2.GetDataConnection(), MapView.Active.Map, tableName: lyrname);
                            _strMessage.SelectString = "Table added.";


                            cpd.Message = "Standalone table added successsfuly to map.";
                            MessageBox.Show("Standalone table added successsfuly to map.");
                        }
                    }
                    cpd.Dispose();
                });
            }
            catch (Exception ex)
            {
                lock (_aLock)
                { BtnMapVis = false; }

                MessageBox.Show("The table could not be added to ArcGIS Pro.  " + ex.Message.ToString());
                if (Globals.DBConn.State != ConnectionState.Closed)
                {
                    Globals.DBConn.Close();
                }

                cpd.Message = "Table not added.";
                cpd.Dispose();
            }
        }
예제 #12
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);
        }
예제 #13
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);
        }
예제 #14
0
        public static void AddDataset(IBasicMap ibasicMap_0, IDataset idataset_0, string string_0)
        {
            if (string_0 == null)
            {
                string_0 = "";
            }
            switch (idataset_0.Type)
            {
            case esriDatasetType.esriDTFeatureDataset:
            {
                IEnumDataset subsets = idataset_0.Subsets;
                subsets.Reset();
                for (IDataset dataset2 = subsets.Next(); dataset2 != null; dataset2 = subsets.Next())
                {
                    AddDataset(ibasicMap_0, dataset2, string_0);
                }
                break;
            }

            case esriDatasetType.esriDTFeatureClass:
            {
                IFeatureLayer layer;
                IFeatureClass class2 = (IFeatureClass)idataset_0;
                if (class2.FeatureType != esriFeatureType.esriFTAnnotation)
                {
                    if (class2.FeatureType == esriFeatureType.esriFTDimension)
                    {
                        IFeatureLayer dimensionLayer = new DimensionLayer() as IFeatureLayer;
                        dimensionLayer.FeatureClass = class2;
                        dimensionLayer.Name         = string_0 + class2.AliasName;
                        layer = dimensionLayer as IFeatureLayer;
                        ibasicMap_0.AddLayer(layer);
                    }
                    else
                    {
                        layer = new FeatureLayer
                        {
                            FeatureClass = class2,
                            Name         = string_0 + class2.AliasName
                        };
                        ibasicMap_0.AddLayer(layer);
                    }
                    break;
                }
                layer = new FDOGraphicsLayer() as IFeatureLayer;
                try
                {
                    layer.FeatureClass = class2;
                    layer.Name         = string_0 + class2.AliasName;
                    ibasicMap_0.AddLayer(layer);
                }
                catch (Exception exception)
                {
                    exception.ToString();
                }
                break;
            }

            case esriDatasetType.esriDTGeometricNetwork:
            {
                IGeometricNetwork network = idataset_0 as IGeometricNetwork;
                if (network != null)
                {
                    IFeatureLayer     layer7;
                    IEnumFeatureClass class3 = network.get_ClassesByType(esriFeatureType.esriFTSimpleJunction);
                    class3.Reset();
                    IFeatureClass class4 = class3.Next();
                    while (class4 != null)
                    {
                        layer7 = new FeatureLayer
                        {
                            FeatureClass = class4,
                            Name         = string_0 + (class4 as IDataset).Name
                        };
                        ibasicMap_0.AddLayer(layer7);
                        class4 = class3.Next();
                    }
                    class3 = network.get_ClassesByType(esriFeatureType.esriFTComplexJunction);
                    class3.Reset();
                    for (class4 = class3.Next(); class4 != null; class4 = class3.Next())
                    {
                        layer7 = new FeatureLayer
                        {
                            FeatureClass = class4,
                            Name         = string_0 + (class4 as IDataset).Name
                        };
                        ibasicMap_0.AddLayer(layer7);
                    }
                    class3 = network.get_ClassesByType(esriFeatureType.esriFTSimpleEdge);
                    class3.Reset();
                    for (class4 = class3.Next(); class4 != null; class4 = class3.Next())
                    {
                        layer7 = new FeatureLayer
                        {
                            FeatureClass = class4,
                            Name         = string_0 + (class4 as IDataset).Name
                        };
                        ibasicMap_0.AddLayer(layer7);
                    }
                    class3 = network.get_ClassesByType(esriFeatureType.esriFTComplexEdge);
                    class3.Reset();
                    for (class4 = class3.Next(); class4 != null; class4 = class3.Next())
                    {
                        layer7 = new FeatureLayer
                        {
                            FeatureClass = class4,
                            Name         = string_0 + (class4 as IDataset).Name
                        };
                        ibasicMap_0.AddLayer(layer7);
                    }
                }
                break;
            }

            case esriDatasetType.esriDTTopology:
            {
                ITopologyLayer layer = new TopologyLayer() as ITopologyLayer;
                layer.Topology = idataset_0 as ITopology;
                ITopologyLayer layer3 = layer as ITopologyLayer;
                (layer3 as ILayer).Name = string_0 + idataset_0.Name;
                ibasicMap_0.AddLayer(layer3 as ILayer);
                break;
            }

            case esriDatasetType.esriDTTable:
                try
                {
                    IRasterCatalogTable pCatalog = new RasterCatalogTable
                    {
                        Table = (ITable)idataset_0
                    };
                    pCatalog.Update();
                    IRasterCatalogLayer pLayer = new RasterCatalogLayer() as IRasterCatalogLayer;
                    pLayer.Create(pCatalog);
                    pLayer.Name = string_0 + idataset_0.BrowseName;
                    ibasicMap_0.AddLayer(pLayer);
                }
                catch
                {
                    try
                    {
                        IStandaloneTableCollection tables = ibasicMap_0 as IStandaloneTableCollection;
                        IPropertySet connectionProperties = idataset_0.Workspace.ConnectionProperties;
                        bool         flag = false;
                        for (int i = 0; i < tables.StandaloneTableCount; i++)
                        {
                            ITable table = tables.get_StandaloneTable(i).Table;
                            if (connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) &&
                                ((table as IDataset).Name == idataset_0.Name))
                            {
                                goto Label_03E1;
                            }
                        }
                        goto Label_03E4;
Label_03E1:
                        flag = true;
Label_03E4:
                        if (!flag)
                        {
                            IStandaloneTable table3 = new StandaloneTable
                            {
                                Table = idataset_0 as ITable
                            };
                            tables.AddStandaloneTable(table3);
                        }
                    }
                    catch (Exception exception2)
                    {
                        CErrorLog.writeErrorLog(null, exception2, "");
                    }
                }
                break;

            case esriDatasetType.esriDTRasterDataset:
            case esriDatasetType.esriDTRasterBand:
            {
                IRasterLayer layer5 = new RasterLayer();
                layer5.CreateFromDataset((IRasterDataset)idataset_0);
                layer5.Name = string_0 + idataset_0.Name;
                ibasicMap_0.AddLayer(layer5);
                break;
            }

            case esriDatasetType.esriDTTin:
            {
                ITinLayer layer4 = new TinLayer
                {
                    Dataset = (ITin)idataset_0,
                    Name    = string_0 + idataset_0.Name
                };
                ibasicMap_0.AddLayer(layer4);
                break;
            }

            case esriDatasetType.esriDTCadDrawing:
            {
                ICadLayer layer2 = new CadLayer() as ICadLayer;
                layer2.CadDrawingDataset = idataset_0 as ICadDrawingDataset;
                layer2.Name = idataset_0.Name;
                ibasicMap_0.AddLayer(layer2);
                break;
            }
            }
        }