Exemple #1
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            if (this.txtRepresentationName.Text.Trim().Length == 0)
            {
                MessageBox.Show("名字不能为空!");
            }
            else if (this.txtruleIDFldName.Text.Trim().Length == 0)
            {
                MessageBox.Show("RuleID字段不能为空!");
            }
            else if (this.txtoverrideFldName.Text.Trim().Length == 0)
            {
                MessageBox.Show("Override字段不能为空!");
            }
            else
            {
                try
                {
                    IFeatureClass featureClass = this.ifeatureLayer_0.FeatureClass;
                    IRepresentationWorkspaceExtension repWSExtFromFClass =
                        RepresentationAssist.GetRepWSExtFromFClass(featureClass);
                    if (repWSExtFromFClass != null)
                    {
                        IRepresentationRule  repRule = RepresentationAssist.CreateRepresentationRule(featureClass);
                        IRepresentationRules rules   = new RepresentationRulesClass();
                        rules.Add(repRule);
                        IRepresentationClass class3 = repWSExtFromFClass.CreateRepresentationClass(featureClass,
                                                                                                   this.txtRepresentationName.Text, this.txtruleIDFldName.Text, this.txtoverrideFldName.Text,
                                                                                                   this.rdoRequireShapeOverride.Checked, rules, null);
                        if ((this.imap_0 != null) && this.chkAddLayer.Checked)
                        {
                            IFeatureLayer layer = new FeatureLayerClass
                            {
                                FeatureClass = featureClass
                            };
                            IFeatureRenderer renderer = new RepresentationRendererClass();
                            (renderer as IRepresentationRenderer).RepresentationClass = class3;
                            (layer as IGeoFeatureLayer).Renderer = renderer;
                            this.imap_0.AddLayer(layer);
                            (this.imap_0 as IActiveView).Refresh();
                        }
                        base.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        base.DialogResult = DialogResult.OK;
                    }
                }
                catch (COMException exception)
                {
                    switch (exception.ErrorCode)
                    {
                    case -2147218682:
                        MessageBox.Show(exception.Message);
                        return;

                    case -2147218675:
                        MessageBox.Show("该要素类中已存在同名的制图表现");
                        break;

                    case -2147218674:
                        MessageBox.Show("该要素类中已存在同名RuleID字段或Override字段");
                        break;
                    }
                }
                catch (Exception)
                {
                }
            }
        }
        // bool hasTopologyStuff, bool hasStationFunction,
        private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool useRepresentation)
        {
            // Get references to the map for adding layers and tables
            IMxDocument MxDoc = (IMxDocument)ArcMap.Document;
            IMap thisMap = MxDoc.FocusMap;
            IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap;

            // Create a group layer
            IGroupLayer GeoMapGroupLayer = new GroupLayerClass();
            GeoMapGroupLayer.Name = "Geologic Map";

            // Create a group layer
            IGroupLayer StationGroupLayer = new GroupLayerClass();
            StationGroupLayer.Name = "Observation Data";

            //if (hasTopologyStuff == true)
            {
                #region "GeologicMapTopology"
                ITopology geoMapTopo = commonFunctions.OpenTopology(ValidNcgmpDatabase, "GeologicMapTopology");
                ITopologyLayer geoMapTopoTL = new TopologyLayerClass();
                geoMapTopoTL.Topology = geoMapTopo;

                ILayer geoMapTopoL = (ILayer)geoMapTopoTL;
                geoMapTopoL.Name = "Geologic Map Topology";
                geoMapTopoL.Visible = false;

                // Minimizing the legend info in the Table of Contents is not trivial
                ILegendInfo geoMapTopoLegendInfo = (ILegendInfo)geoMapTopoL;
                ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(1);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(2);
                geoMapTopoLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(geoMapTopoL);

                #endregion
            }
            {
                #region "OrientationPoints"
                IFeatureClass orientationPointsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationPoints");
                IFeatureLayer orientationPointsFL = new FeatureLayerClass();
                orientationPointsFL.FeatureClass = orientationPointsFC;

                orientationPointsFL.Name = "Orientation Points";
                orientationPointsFL.DisplayField = "Type";

                if (useRepresentation == true)
                {
                    // Set the layer renderer to use representations
                    IGeoFeatureLayer orientationPointsGeoFL = (IGeoFeatureLayer)orientationPointsFL;

                    IRepresentationRenderer orientationPointsRepRend = new RepresentationRendererClass();
                    orientationPointsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "OrientationPoints_Rep");

                    orientationPointsGeoFL.Renderer = (IFeatureRenderer)orientationPointsRepRend;

                    commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, orientationPointsFL as ILayer, "OrientationPoints");
                }

                ILegendInfo orientationPointsLegendInfo = (ILegendInfo)orientationPointsFL;
                ILegendGroup orientationPointsLegendGroup = orientationPointsLegendInfo.get_LegendGroup(0);
                orientationPointsLegendGroup.Visible = false;

                StationGroupLayer.Add(orientationPointsFL);

                #endregion

                #region "ObservationData"
                string[] arr = new string[4]; // Initialize
                arr[0] = "Stations";               // Element 1
                arr[1] = "GenericPoints";               // Element 2
                arr[2] = "GenericSamples";             // Element 3
                arr[3] = "GeochronPoints";              // Element 4

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;
                        FL.Visible = false;

                        ILegendInfo LegendInfo = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        StationGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion

            }

            //add station group layer to map document
            GeoMapGroupLayer.Add(StationGroupLayer);

            {
                #region "LinesWithoutRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "CartographicLines";               // Element 1
                arr[1] = "IsoValueLines";               // Element 2

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;
                        FL.Visible = false;

                        ILegendInfo LegendInfo = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "LinesWithRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "GeologicLines";               // Element 1
                arr[1] = "ContactsAndFaults";               // Element 2

                foreach (string s in arr)
                {
                    try {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        if (useRepresentation == true)
                        {
                            // Set the layer renderer to use representations
                            IGeoFeatureLayer GeoFL = (IGeoFeatureLayer)FL;

                            IRepresentationRenderer RepRend = new RepresentationRendererClass();
                            RepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, s + "_Rep");

                            GeoFL.Renderer = (IFeatureRenderer)RepRend;

                            commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, FL as ILayer, s);
                        }

                        ILegendInfo LegendInfo = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Polygons"
                string[] arr = new string[3]; // Initialize
                arr[0] = "DataSourcePolys";               // Element 1
                arr[1] = "MapUnitPolys";               // Element 2
                arr[2] = "OtherPolys";               // Element 3

                foreach (string s in arr)
                {
                    try {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        ILegendInfo LegendInfo = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Tables"
                string[] arr = new string[7]; // Initialize
                arr[0] = "DataSources";               // Element 1
                arr[1] = "DescriptionOfMapUnits";               // Element 2
                arr[2] = "ExtendedAttributes";             // Element 3
                arr[3] = "GeologicEvents";              // Element 4
                arr[4] = "Glossary";              // Element 5
                arr[5] = "Notes";              // Element 6
                arr[6] = "StandardLithology";              // Element 7
                foreach (string s in arr)
                {
                    try {
                        ITable Table = commonFunctions.OpenTable(ValidNcgmpDatabase, s);
                        IStandaloneTable Standalone = new StandaloneTableClass();
                        Standalone.Table = Table;

                        Standalone.Name = s;

                        thisMapTables.AddStandaloneTable(Standalone);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }

            // Add the Geologic Map Group Layer to the map
            GeoMapGroupLayer.Expanded = true;
            thisMap.AddLayer(GeoMapGroupLayer);

            // Adjust the MapUnitPolys Renderer
            commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase);

            // Adjust the MapUnitPolys Feature Templates
            commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase);
        }
        private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool hasTopologyStuff, bool hasStationFunction, bool useRepresentation)
        {
            // Get references to the map for adding layers and tables
            IMxDocument MxDoc = (IMxDocument)ArcMap.Document;
            IMap thisMap = MxDoc.FocusMap;
            IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap;

            // Create a group layer
            IGroupLayer GeoMapGroupLayer = new GroupLayerClass();
            GeoMapGroupLayer.Name = "Geologic Map";

            if (hasTopologyStuff == true)
            {
                #region "GeologicMapTopology"
                ITopology geoMapTopo = commonFunctions.OpenTopology(ValidNcgmpDatabase,"GeologicMapTopology");
                ITopologyLayer geoMapTopoTL = new TopologyLayerClass();
                geoMapTopoTL.Topology = geoMapTopo;

                ILayer geoMapTopoL = (ILayer)geoMapTopoTL;
                geoMapTopoL.Name = "Geologic Map Topology";
                geoMapTopoL.Visible = false;

                // Minimizing the legend info in the Table of Contents is not trivial
                ILegendInfo geoMapTopoLegendInfo = (ILegendInfo)geoMapTopoL;
                ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(1);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(2);
                geoMapTopoLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(geoMapTopoL);

                #endregion
            }

            if (hasStationFunction == true)
            {
                // Create a Group layer
                IGroupLayer stationGroupLayer = new GroupLayerClass();
                stationGroupLayer.Name = "Station Data";

                #region "StationPoints"
                // Open a FeatureClass, set it to a FeatureLayer
                IFeatureClass stationFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "StationPoints");
                IFeatureLayer stationFL = new FeatureLayerClass();
                stationFL.FeatureClass = stationFC;

                // Configure the FeatureLayer
                stationFL.Name = "Stations";
                stationFL.DisplayField = "FieldID";

                // Collapse the legend for this layer
                ILegendInfo stationLegendInfo = (ILegendInfo)stationFL;
                ILegendGroup stationLegendGroup = stationLegendInfo.get_LegendGroup(0);
                stationLegendGroup.Visible = false;

                // Finally, add the layer to the group layer
                stationGroupLayer.Add(stationFL);

                #endregion

                // Repeat for all these FeatureClasses
                #region "SamplePoints"
                IFeatureClass sampleFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "SamplePoints");
                IFeatureLayer sampleFL = new FeatureLayerClass();
                sampleFL.FeatureClass = sampleFC;

                sampleFL.Name = "Samples";
                sampleFL.DisplayField = "FieldID";

                ILegendInfo sampleLegendInfo = (ILegendInfo)sampleFL;
                ILegendGroup sampleLegendGroup = sampleLegendInfo.get_LegendGroup(0);
                sampleLegendGroup.Visible = false;

                stationGroupLayer.Add(sampleFL);

                #endregion

                #region "OrientationDataPoints"
                IFeatureClass structureFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationDataPoints");
                IFeatureLayer structureFL = new FeatureLayerClass();
                structureFL.FeatureClass = structureFC;

                structureFL.Name = "Orientation Data";
                structureFL.DisplayField = "Type";

                // Symbology, if representations are present
                if (useRepresentation == true)
                {
                    // FeatureLayer must be cast as a GeoFeatureLayer in order to access the Renderer
                    IGeoFeatureLayer structureGeoFL = (IGeoFeatureLayer)structureFL;

                    // Create a RepresentationClassRenderer, assign the appropriate RepresentationClass to it
                    IRepresentationRenderer structureRepRend = new RepresentationRendererClass();
                    structureRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "r_OrientationDataPoints");

                    // Assign the RepresentationClassRenderer to the GeoFeatureLayer
                    structureGeoFL.Renderer = (IFeatureRenderer)structureRepRend;

                    // Assign generic FeatureTemplates
                    commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, structureFL as ILayer, "OrientationDataPoints");
                }

                ILegendInfo structureLegendInfo = (ILegendInfo)structureFL;
                ILegendGroup structureLegendGroup = structureLegendInfo.get_LegendGroup(0);
                structureLegendGroup.Visible = false;

                stationGroupLayer.Add(structureFL);

                #endregion

                // Add the Group Layer to the main layer
                stationGroupLayer.Expanded = true;
                GeoMapGroupLayer.Add(stationGroupLayer);

                #region "Notes Table"
                ITable notesTable = commonFunctions.OpenTable(ValidNcgmpDatabase, "Notes");
                IStandaloneTable notesStandalone = new StandaloneTableClass();
                notesStandalone.Table = notesTable;

                notesStandalone.Name = "Notes";
                notesStandalone.DisplayField = "Type";

                thisMapTables.AddStandaloneTable(notesStandalone);

                #endregion

                #region "RelatedDocuments Table"
                ITable relatedDocsTable = commonFunctions.OpenTable(ValidNcgmpDatabase, "RelatedDocuments");
                IStandaloneTable relatedDocsStandalone = new StandaloneTableClass();
                relatedDocsStandalone.Table = relatedDocsTable;

                relatedDocsStandalone.Name = "Related Documents";
                relatedDocsStandalone.DisplayField = "Type";

                thisMapTables.AddStandaloneTable(relatedDocsStandalone);

                #endregion
            }

            if (hasTopologyStuff == true)
            {
                #region "OtherLines"
                IFeatureClass otherLinesFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OtherLines");
                IFeatureLayer otherLinesFL = new FeatureLayerClass();
                otherLinesFL.FeatureClass = otherLinesFC;

                otherLinesFL.Name = "Other Lines";
                otherLinesFL.DisplayField = "Type";

                if (useRepresentation == true)
                {
                    IGeoFeatureLayer otherLinesGeoFL = (IGeoFeatureLayer)otherLinesFL;

                    IRepresentationRenderer otherLinesRepRend = new RepresentationRendererClass();
                    otherLinesRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "r_OtherLines");

                    otherLinesGeoFL.Renderer = (IFeatureRenderer)otherLinesRepRend;

                    commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, otherLinesFL as ILayer, "OtherLines");
                }

                ILegendInfo otherLinesLegendInfo = (ILegendInfo)otherLinesFL;
                ILegendGroup otherLinesLegendGroup = otherLinesLegendInfo.get_LegendGroup(0);
                otherLinesLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(otherLinesFL);

                #endregion

            }

            #region "ContactsAndFaults"
            IFeatureClass contactsAndFaultsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "ContactsAndFaults");
            IFeatureLayer contactsAndFaultsFL = new FeatureLayerClass();
            contactsAndFaultsFL.FeatureClass = contactsAndFaultsFC;

            contactsAndFaultsFL.Name = "Contacts and Faults";
            contactsAndFaultsFL.DisplayField = "Type";

            if (useRepresentation == true)
            {
                // Set the layer renderer to use representations
                IGeoFeatureLayer contactsAndFaultsGeoFL = (IGeoFeatureLayer)contactsAndFaultsFL;

                IRepresentationRenderer contactsAndFaultsRepRend = new RepresentationRendererClass();
                contactsAndFaultsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "r_ContactsAndFaults");

                contactsAndFaultsGeoFL.Renderer = (IFeatureRenderer)contactsAndFaultsRepRend;

                commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, contactsAndFaultsFL as ILayer, "ContactsAndFaults");
            }

            ILegendInfo contactsAndFaultsLegendInfo = (ILegendInfo)contactsAndFaultsFL;
            ILegendGroup contactsAndFaultsLegendGroup = contactsAndFaultsLegendInfo.get_LegendGroup(0);
            contactsAndFaultsLegendGroup.Visible = false;

            GeoMapGroupLayer.Add(contactsAndFaultsFL);

            #endregion

            if (hasTopologyStuff == true)
            {
                #region "OverlayPolys"
                IFeatureClass overlayPolysFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OverlayPolys");
                IFeatureLayer overlayPolysFL = new FeatureLayerClass();
                overlayPolysFL.FeatureClass = overlayPolysFC;

                overlayPolysFL.Name = "Overlay Polygons";
                overlayPolysFL.DisplayField = "MapUnit";

                ILegendInfo overlayPolysLegendInfo = (ILegendInfo)overlayPolysFL;
                ILegendGroup overlayPolysLegendGroup = overlayPolysLegendInfo.get_LegendGroup(0);
                overlayPolysLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(overlayPolysFL);

                #endregion
            }

            #region "MapUnitPolys"
            IFeatureClass mapUnitPolysFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "MapUnitPolys");
            IFeatureLayer mapUnitPolysFL = new FeatureLayerClass();
            mapUnitPolysFL.FeatureClass = mapUnitPolysFC;

            mapUnitPolysFL.Name = "Distribution of Map Units";
            mapUnitPolysFL.DisplayField = "MapUnit";

            ILegendInfo mapUnitPolysLegendInfo = (ILegendInfo)mapUnitPolysFL;
            ILegendGroup mapUnitPolysLegendGroup = mapUnitPolysLegendInfo.get_LegendGroup(0);
            mapUnitPolysLegendGroup.Visible = false;

            GeoMapGroupLayer.Add(mapUnitPolysFL);
            #endregion

            if (hasTopologyStuff == true)
            {
                #region "DataSourcePolys"
                IFeatureClass dataSourcePolysFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "DataSourcePolys");
                IFeatureLayer dataSourcePolysFL = new FeatureLayerClass();
                dataSourcePolysFL.FeatureClass = dataSourcePolysFC;

                dataSourcePolysFL.Name = "Data Source Polys";
                dataSourcePolysFL.DisplayField = "DataSourceID";

                ILegendInfo dataSourcePolysLegendInfo = (ILegendInfo)dataSourcePolysFL;
                ILegendGroup dataSourcePolysLegendGroup = dataSourcePolysLegendInfo.get_LegendGroup(0);
                dataSourcePolysLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(dataSourcePolysFL);

                #endregion
            }

            // Add the Geologic Map Group Layer to the map
            GeoMapGroupLayer.Expanded = true;
            thisMap.AddLayer(GeoMapGroupLayer);

            // Adjust the MapUnitPolys Renderer
            commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase);

            // Adjust the MapUnitPolys Feature Templates
            commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase);
        }
        private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool useRepresentation) // bool hasTopologyStuff, bool hasStationFunction,
        {
            // Get references to the map for adding layers and tables
            IMxDocument MxDoc   = (IMxDocument)ArcMap.Document;
            IMap        thisMap = MxDoc.FocusMap;
            IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap;

            // Create a group layer
            IGroupLayer GeoMapGroupLayer = new GroupLayerClass();

            GeoMapGroupLayer.Name = "Geologic Map";

            // Create a group layer
            IGroupLayer StationGroupLayer = new GroupLayerClass();

            StationGroupLayer.Name = "Observation Data";

            //if (hasTopologyStuff == true)
            {
                #region "GeologicMapTopology"
                ITopology      geoMapTopo   = commonFunctions.OpenTopology(ValidNcgmpDatabase, "GeologicMapTopology");
                ITopologyLayer geoMapTopoTL = new TopologyLayerClass();
                geoMapTopoTL.Topology = geoMapTopo;

                ILayer geoMapTopoL = (ILayer)geoMapTopoTL;
                geoMapTopoL.Name    = "Geologic Map Topology";
                geoMapTopoL.Visible = false;

                // Minimizing the legend info in the Table of Contents is not trivial
                ILegendInfo  geoMapTopoLegendInfo  = (ILegendInfo)geoMapTopoL;
                ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup         = geoMapTopoLegendInfo.get_LegendGroup(1);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup         = geoMapTopoLegendInfo.get_LegendGroup(2);
                geoMapTopoLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(geoMapTopoL);

                #endregion
            }
            {
                #region "OrientationPoints"
                IFeatureClass orientationPointsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationPoints");
                IFeatureLayer orientationPointsFL = new FeatureLayerClass();
                orientationPointsFL.FeatureClass = orientationPointsFC;

                orientationPointsFL.Name         = "Orientation Points";
                orientationPointsFL.DisplayField = "Type";

                if (useRepresentation == true)
                {
                    // Set the layer renderer to use representations
                    IGeoFeatureLayer orientationPointsGeoFL = (IGeoFeatureLayer)orientationPointsFL;

                    IRepresentationRenderer orientationPointsRepRend = new RepresentationRendererClass();
                    orientationPointsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "OrientationPoints_Rep");

                    orientationPointsGeoFL.Renderer = (IFeatureRenderer)orientationPointsRepRend;

                    commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, orientationPointsFL as ILayer, "OrientationPoints");
                }

                ILegendInfo  orientationPointsLegendInfo  = (ILegendInfo)orientationPointsFL;
                ILegendGroup orientationPointsLegendGroup = orientationPointsLegendInfo.get_LegendGroup(0);
                orientationPointsLegendGroup.Visible = false;

                StationGroupLayer.Add(orientationPointsFL);

                #endregion

                #region "ObservationData"
                string[] arr = new string[4]; // Initialize
                arr[0] = "Stations";          // Element 1
                arr[1] = "GenericPoints";     // Element 2
                arr[2] = "GenericSamples";    // Element 3
                arr[3] = "GeochronPoints";    // Element 4

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name    = s;
                        FL.Visible = false;

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        StationGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }

            //add station group layer to map document
            GeoMapGroupLayer.Add(StationGroupLayer);

            {
                #region "LinesWithoutRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "CartographicLines"; // Element 1
                arr[1] = "IsoValueLines";     // Element 2

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name    = s;
                        FL.Visible = false;

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "LinesWithRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "GeologicLines";     // Element 1
                arr[1] = "ContactsAndFaults"; // Element 2

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        if (useRepresentation == true)
                        {
                            // Set the layer renderer to use representations
                            IGeoFeatureLayer GeoFL = (IGeoFeatureLayer)FL;

                            IRepresentationRenderer RepRend = new RepresentationRendererClass();
                            RepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, s + "_Rep");

                            GeoFL.Renderer = (IFeatureRenderer)RepRend;

                            commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, FL as ILayer, s);
                        }

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Polygons"
                string[] arr = new string[3]; // Initialize
                arr[0] = "DataSourcePolys";   // Element 1
                arr[1] = "MapUnitPolys";      // Element 2
                arr[2] = "OtherPolys";        // Element 3

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Tables"
                string[] arr = new string[7];     // Initialize
                arr[0] = "DataSources";           // Element 1
                arr[1] = "DescriptionOfMapUnits"; // Element 2
                arr[2] = "ExtendedAttributes";    // Element 3
                arr[3] = "GeologicEvents";        // Element 4
                arr[4] = "Glossary";              // Element 5
                arr[5] = "Notes";                 // Element 6
                arr[6] = "StandardLithology";     // Element 7
                foreach (string s in arr)
                {
                    try
                    {
                        ITable           Table      = commonFunctions.OpenTable(ValidNcgmpDatabase, s);
                        IStandaloneTable Standalone = new StandaloneTableClass();
                        Standalone.Table = Table;

                        Standalone.Name = s;

                        thisMapTables.AddStandaloneTable(Standalone);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }

            // Add the Geologic Map Group Layer to the map
            GeoMapGroupLayer.Expanded = true;
            thisMap.AddLayer(GeoMapGroupLayer);

            // Adjust the MapUnitPolys Renderer
            commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase);

            // Adjust the MapUnitPolys Feature Templates
            commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase);
        }