Exemple #1
0
        private Dictionary <string, string> GetDmuIdFromNameLookup()
        {
            // First get all DMU entries
            DescriptionOfMapUnitsAccess DmuAccess = new DescriptionOfMapUnitsAccess(m_theWorkspace);

            DmuAccess.AddDescriptionOfMapUnits();

            // Pass these records into a new Dictionary correlating ID to HierarchyKey
            Dictionary <string, string> idDmuDictionary = new Dictionary <string, string>();

            foreach (KeyValuePair <string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> aDictionaryEntry in DmuAccess.DescriptionOfMapUnitsDictionary)
            {
                DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisDmuEntry = (DescriptionOfMapUnitsAccess.DescriptionOfMapUnit)aDictionaryEntry.Value;
                if (thisDmuEntry.ParagraphStyle.Contains("Heading") == true)
                {
                    idDmuDictionary.Add(thisDmuEntry.Name, thisDmuEntry.DescriptionOfMapUnits_ID);
                }
                else
                {
                    idDmuDictionary.Add(thisDmuEntry.MapUnit + " - " + thisDmuEntry.Name, thisDmuEntry.DescriptionOfMapUnits_ID);
                }
            }

            return(idDmuDictionary);
        }
        public static void UpdateMapUnitPolysFeatureTemplates(IWorkspace theWorkspace)
        {
            // Get the MapUnitPolys Layer from the ToC
            IFeatureLayer theLayer = commonFunctions.FindFeatureLayer(theWorkspace, "MapUnitPolys");

            // If the layer was not found, don't try and update the templates!
            if (theLayer == null)
            {
                return;
            }

            // Get a reference to the template editor, remove current templates
            IEditor3 templateEditor = (IEditor3)ArcMap.Editor;

            templateEditor.RemoveAllTemplatesInLayer((ILayer)theLayer);

            // Get the DMU entries
            var sortedDmu = GetDmuSortedByHierarchy(theWorkspace);

            // Loop through the DMU, add templates to an array
            IArray templateArray = new ArrayClass();

            foreach (KeyValuePair <string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> anEntry in sortedDmu)
            {
                // Get this DMU entry
                DescriptionOfMapUnitsAccess.DescriptionOfMapUnit dmuEntry = anEntry.Value;

                // Build the template if this is not a heading
                if (dmuEntry.ParagraphStyle.Contains("Heading") == true)
                {
                    continue;
                }
                IEditTemplateFactory templateFactory = new EditTemplateFactoryClass();
                IEditTemplate        newTemplate     = templateFactory.Create(dmuEntry.MapUnit + " - " + dmuEntry.Name, (ILayer)theLayer);

                // Set the Template's default values
                newTemplate.SetDefaultValue("MapUnit", dmuEntry.MapUnit, false);
                newTemplate.SetDefaultValue("Label", dmuEntry.Label, false);
                newTemplate.SetDefaultValue("IdentityConfidence", "certain", false);

                // Set defaults for landslide types
                switch (anEntry.Value.Name)
                {
                case "Rock Fall":
                    newTemplate.SetDefaultValue("MoveType", "Fall", false);
                    newTemplate.SetDefaultValue("MoveClass", "Rock Fall", false);
                    newTemplate.SetDefaultValue("MoveCode", "RF", false);
                    break;

                case "Earth Fall":
                    newTemplate.SetDefaultValue("MoveType", "Fall", false);
                    newTemplate.SetDefaultValue("MoveClass", "Earth Fall", false);
                    newTemplate.SetDefaultValue("MoveCode", "EF", false);
                    break;

                case "Debris Fall":
                    newTemplate.SetDefaultValue("MoveType", "Fall", false);
                    newTemplate.SetDefaultValue("MoveClass", "Debris Fall", false);
                    newTemplate.SetDefaultValue("MoveCode", "DF", false);
                    break;

                case "Rock Flow":
                    newTemplate.SetDefaultValue("MoveType", "Flow", false);
                    newTemplate.SetDefaultValue("MoveClass", "Rock Flow", false);
                    newTemplate.SetDefaultValue("MoveCode", "RFL", false);
                    break;

                case "Earth Flow":
                    newTemplate.SetDefaultValue("MoveType", "Flow", false);
                    newTemplate.SetDefaultValue("MoveClass", "Earth Flow", false);
                    newTemplate.SetDefaultValue("MoveCode", "EFL", false);
                    break;

                case "Debris Flow":
                    newTemplate.SetDefaultValue("MoveType", "Flow", false);
                    newTemplate.SetDefaultValue("MoveClass", "Debris Flow", false);
                    newTemplate.SetDefaultValue("MoveCode", "DFL", false);
                    break;

                case "Rock Topple":
                    newTemplate.SetDefaultValue("MoveType", "Topple", false);
                    newTemplate.SetDefaultValue("MoveClass", "Rock Topple", false);
                    newTemplate.SetDefaultValue("MoveCode", "RT", false);
                    break;

                case "Debris Topple":
                    newTemplate.SetDefaultValue("MoveType", "Topple", false);
                    newTemplate.SetDefaultValue("MoveClass", "Debris Topple", false);
                    newTemplate.SetDefaultValue("MoveCode", "ET", false);
                    break;

                case "Earth Topple":
                    newTemplate.SetDefaultValue("MoveType", "Topple", false);
                    newTemplate.SetDefaultValue("MoveClass", "Earth Topple", false);
                    newTemplate.SetDefaultValue("MoveCode", "ET", false);
                    break;

                case "Rock Slide-rotational":
                    newTemplate.SetDefaultValue("MoveType", "Slide-rotational", false);
                    newTemplate.SetDefaultValue("MoveClass", "Rock Slide-rotational", false);
                    newTemplate.SetDefaultValue("MoveCode", "RS-R", false);
                    break;

                case "Debris Slide-rotational":
                    newTemplate.SetDefaultValue("MoveType", "Slide-rotational", false);
                    newTemplate.SetDefaultValue("MoveClass", "Debris Slide-rotational", false);
                    newTemplate.SetDefaultValue("MoveCode", "DS-R", false);
                    break;

                case "Earth Slide-rotational":
                    newTemplate.SetDefaultValue("MoveType", "Slide-rotational", false);
                    newTemplate.SetDefaultValue("MoveClass", "Earth Slide-rotational", false);
                    newTemplate.SetDefaultValue("MoveCode", "ES-R", false);
                    break;

                case "Rock Slide-translational":
                    newTemplate.SetDefaultValue("MoveType", "Slide-translational", false);
                    newTemplate.SetDefaultValue("MoveClass", "Rock Slide-translational", false);
                    newTemplate.SetDefaultValue("MoveCode", "RS-T", false);
                    break;

                case "Debris Slide-translational":
                    newTemplate.SetDefaultValue("MoveType", "Slide-translational", false);
                    newTemplate.SetDefaultValue("MoveClass", "Debris Slide-translational", false);
                    newTemplate.SetDefaultValue("MoveCode", "DS-T", false);
                    break;

                case "Earth Slide-translational":
                    newTemplate.SetDefaultValue("MoveType", "Slide-translational", false);
                    newTemplate.SetDefaultValue("MoveClass", "Earth Slide-translational", false);
                    newTemplate.SetDefaultValue("MoveCode", "ES-T", false);
                    break;

                case "Complex":
                    newTemplate.SetDefaultValue("MoveType", "Complex", false);
                    newTemplate.SetDefaultValue("MoveClass", "Complex, see notes", false);
                    newTemplate.SetDefaultValue("MoveCode", "Complex", false);
                    break;

                case "Earth Slide-general":
                    newTemplate.SetDefaultValue("MoveType", "Slide-general", false);
                    newTemplate.SetDefaultValue("MoveClass", "Earth Slide-general", false);
                    newTemplate.SetDefaultValue("MoveCode", "ES-G", false);
                    break;
                }

                // Add the template to the array
                templateArray.Add(newTemplate);
            }

            // Add one "UNLABELED" template
            IEditTemplateFactory unlabeledTemplateFactory = new EditTemplateFactoryClass();
            IEditTemplate        unlabeledTemplate        = unlabeledTemplateFactory.Create("UNLABELED", (ILayer)theLayer);

            unlabeledTemplate.SetDefaultValue("MapUnit", "UNLABELED", false);
            unlabeledTemplate.SetDefaultValue("Label", "UNLABELED", false);
            templateArray.Add(unlabeledTemplate);

            // Add the templates to the editor
            templateEditor.AddTemplates(templateArray);

            // Update the doc?
            ArcMap.Document.UpdateContents();
        }
        public static void UpdateMapUnitPolysRenderer(IWorkspace theWorkspace)
        {
            // Get the MapUnitPolys Layer from the ToC
            IFeatureLayer theLayer = commonFunctions.FindFeatureLayer(theWorkspace, "MapUnitPolys");

            // If the layer was not found, don't try and update the renderer!
            if (theLayer == null)
            {
                return;
            }

            // Setup the renderer
            IUniqueValueRenderer theRenderer = new UniqueValueRendererClass();

            theRenderer.FieldCount = 1;
            theRenderer.Field[0]   = "MapUnit";

            // Setup a couple variables
            IColor nullColor = new RgbColorClass();

            nullColor.NullColor = true;

            // Setup a blank line
            ILineSymbol nullLine = new SimpleLineSymbolClass();

            nullLine.Color = nullColor;

            // Setup the "All Other Values" symbol
            ISimpleFillSymbol defaultSymbol = new SimpleFillSymbolClass();
            IColor            defaultColor  = new RgbColorClass();

            defaultColor.RGB      = 255;
            defaultSymbol.Color   = defaultColor;
            defaultSymbol.Outline = nullLine;

            // Apply the "All other values" symbol to the renderer
            theRenderer.DefaultSymbol    = defaultSymbol as ISymbol;
            theRenderer.UseDefaultSymbol = true;

            string theHeading = "Geologic Map Units";

            // Get the Legend Items
            var sortedDmu = GetDmuSortedByHierarchy(theWorkspace);

            // Loop through the legend items
            foreach (KeyValuePair <string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> legendEntry in sortedDmu)
            {
                DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisDmuEntry = legendEntry.Value;

                // If this is a heading, make it so
                if (thisDmuEntry.ParagraphStyle.Contains("Heading") == true)
                {
                    theHeading = thisDmuEntry.Name;
                    continue;
                }

                // Make a Simple Fill RuleID
                ISimpleFillSymbol theSymbol = new SimpleFillSymbolClass();
                //theRuleID.Style = esriSimpleFillStyle.esriSFSSolid;

                // Get the right color
                IColor   symbolColor = new RgbColorClass();
                string   rgbString   = thisDmuEntry.AreaFillRGB;
                string[] rgbValues   = rgbString.Split(';');

                // Long integer representations of RGB values are dumb: G*65536 + B*256 + R
                if (rgbValues.Length < 3)
                {
                    symbolColor.RGB = 16777215;
                }
                else
                {
                    symbolColor.RGB = int.Parse(rgbValues[0]) + int.Parse(rgbValues[1]) * 256 + int.Parse(rgbValues[2]) * 65536;
                }
                theSymbol.Color = symbolColor;

                theSymbol.Outline = nullLine;

                // Add it to the renderer
                theRenderer.AddValue(thisDmuEntry.MapUnit, theHeading, theSymbol as ISymbol);

                // Give it the right label
                theRenderer.Label[thisDmuEntry.MapUnit] = thisDmuEntry.MapUnit + " - " + thisDmuEntry.Name;
            }

            // Apply the renderer
            IGeoFeatureLayer geoFLayer = (IGeoFeatureLayer)theLayer;

            geoFLayer.Renderer = (IFeatureRenderer)theRenderer;

            // Minimizing the legend info in the Table of Contents is not trivial
            ILegendInfo layerLegendInfo = (ILegendInfo)theLayer;

            for (int i = 0; i < layerLegendInfo.LegendGroupCount; i++)
            {
                ILegendGroup layerLegendGroup = layerLegendInfo.get_LegendGroup(i);
                layerLegendGroup.Visible = false;
            }

            // Update the views
            ArcMap.Document.UpdateContents();
            ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, theLayer, null);
        }
        private static void DrawMapUnits(IEnvelope Envelope, bool showText, double ColumnX)
        {
            // BOX DIMENSIONS AND UNIFORM SYMBOL ITEMS
            double Text2BoxY = 0.2; //Y distance between the bottom of text and the next box
            double Text2BoxX = 0.1; //X distance between a box and the text that describes it
            double BoxX      = 0.4; //Width
            double BoxY      = 0.3; //Height

            // Setup a black color object, black outline
            IRgbColor BlackInsides = new ESRI.ArcGIS.Display.RgbColorClass();

            BlackInsides.Blue  = 0;
            BlackInsides.Red   = 0;
            BlackInsides.Green = 0;

            ILineSymbol BlackOutsides = new SimpleLineSymbolClass();

            BlackOutsides.Width = 1;
            BlackOutsides.Color = BlackInsides;

            // Whole bunch of variables to use while going through the loop below...
            #region Variables Galore!!!
            IMxDocument        Doc = ArcMap.Document;
            IPageLayout        pageLayout = Doc.ActiveView as IPageLayout;
            IGraphicsContainer GraphicsContainer = pageLayout as IGraphicsContainer;
            double             Xcoord, Ycoord;
            Xcoord = Envelope.XMin;
            Ycoord = Envelope.YMax;
            double                      IndentTerm   = 0;
            IPoint                      Point        = null;
            double                      StringLength = 0;
            string                      LegendText   = "";
            string                      ItemName     = "";
            string                      ItemDesc     = "";
            IElement                    Ele          = null;
            IEnvelope                   TempEnv      = null;
            IRgbColor                   BoxColr      = null;
            ISimpleFillSymbol           FillSym      = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            IFillShapeElement           FillEle      = null;
            IEnvelope                   FillEnv      = new EnvelopeClass();
            WKSEnvelope                 Patch        = new WKSEnvelope();
            IGeometry                   Geo          = null;
            string                      LabelText    = "";
            ESRI.ArcGIS.Geometry.IPoint LabelPoint   = new ESRI.ArcGIS.Geometry.PointClass();

            // Get the transparency of the MapUnitPolys Layer
            double transparency = 100;
            try
            {
                IFeatureLayer polyLayer    = commonFunctions.FindFeatureLayer(ArcMap.Editor.EditWorkspace, "MapUnitPolys");
                ILayerEffects layerEffects = polyLayer as ILayerEffects;
                transparency = layerEffects.Transparency;
            }
            catch { }

            #endregion

            // Get a reference to the DescriptionOfMapUnits entries
            var sortedDmuEntries = GetDmuSortedByHierarchy();

            // Loop through legend records
            foreach (KeyValuePair <string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> aDictionaryEntry in sortedDmuEntries)
            {
                // Grab the DMU entry itself
                DescriptionOfMapUnitsAccess.DescriptionOfMapUnit aDescription = aDictionaryEntry.Value;
                bool isHeading = (aDescription.ParagraphStyle.Contains("Heading"));


                // Find out how far to indent the legend item
                // Strip periods from the HierarchyKey, divide by 4, which is the length of a segment of the key
                IndentTerm = aDescription.HierarchyKey.Replace(".", "").Length / 4;

                // Get the coordinates of the text for the legend entry - upper left corner
                // Xcoord starts at Envelope.XMin, Ycoord is Envelope.YMax: Upper left corner
                Point = new PointClass();
                double xAdditions = 0;
                if (isHeading)
                {
                    // Xcoord plus (indentation), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1);
                }
                else
                {
                    //Xcoord plus (indentation) + (Box width and margin), Ycoord
                    xAdditions = 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX;
                }
                Point.PutCoords(Xcoord + xAdditions, Ycoord);

                // StringLength is the width remaining in the envelope in which the text has to fit IN PIXELS.
                StringLength = 72 * (Envelope.Width - xAdditions);

                // Fix a couple of special characters in the legend string.
                // Then amalgamate item name and description
                ItemName = FixLegendTextCharacters(aDescription.Name);
                if (!isHeading)
                {
                    LegendText = ItemName + " - " + FixLegendTextCharacters(aDescription.Description);
                }
                else
                {
                    LegendText = ItemName;
                }



                // Format the legend text if it is not a heading. If it is, we're fine.
                if (!isHeading)
                {
                    LegendText = GetFormattedString(LegendText, "Arial", 8, StringLength, 8);
                }

                // Boldify the ItemName
                LegendText = LegendText.Replace(ItemName, "<bol>" + ItemName + "</bol>");

                // If the StratCorDiagram is being drawn
                if (showText == false)
                {
                    LegendText   = ".";     // placeholder
                    StringLength = 1;
                }

                // See if this legend item should be placed on a new column
                Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;

                TempEnv = new EnvelopeClass();
                Ele.QueryBounds(Doc.ActiveView.ScreenDisplay, TempEnv);

                // If the height of the formatted text is larger than the box + space specified
                if (TempEnv.Height > BoxY + Text2BoxY)
                {
                    // If the text will spill out below the envelope drawn by the user
                    if (Ycoord - TempEnv.Height < Envelope.YMin)
                    {
                        // Move to a new column - the last number is a fudge factor, looks like it is in inches
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }
                else     // The height of the formatted text is not larger than the box + space defined
                {
                    // If the box itself will spill out below the envelope drawn by the user
                    if (Ycoord - (BoxY + Text2BoxY) < Envelope.YMin)
                    {
                        // Move to a new column
                        Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                        // Move to the top
                        Ycoord = Envelope.YMax;
                        // Recreate the text element
                        Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                        Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                    }
                }

                // Only write the legend text if the legend is being drawn (not the StratCorDiagram)
                if (showText == true)
                {
                    GraphicsContainer.AddElement(Ele, 0);
                }

                if (!isHeading)
                {
                    FillEnv = new EnvelopeClass();

                    Patch.XMin = Point.X - BoxX - Text2BoxX;
                    Patch.YMax = Point.Y;
                    Patch.XMax = Point.X - Text2BoxX;
                    Patch.YMin = Point.Y - BoxY;
                    FillEnv.PutCoords(Patch.XMin, Patch.YMin, Patch.XMax, Patch.YMax);
                    Geo = FillEnv as IGeometry;

                    // Get the color of the box
                    BoxColr = new RgbColorClass();
                    if (aDescription.AreaFillRGB == null)
                    {
                        BoxColr.Red   = 255;
                        BoxColr.Green = 0;
                        BoxColr.Blue  = 0;
                    }
                    else
                    {
                        BoxColr.Red   = int.Parse(aDescription.AreaFillRGB.Split(';')[0]);
                        BoxColr.Green = int.Parse(aDescription.AreaFillRGB.Split(';')[1]);
                        BoxColr.Blue  = int.Parse(aDescription.AreaFillRGB.Split(';')[2]);
                    }

                    // Set the transparency for the legend color boxes
                    BoxColr.Red   = (int)((255 - BoxColr.Red) * transparency / 100 + BoxColr.Red);
                    BoxColr.Green = (int)((255 - BoxColr.Green) * transparency / 100 + BoxColr.Green);
                    BoxColr.Blue  = (int)((255 - BoxColr.Blue) * transparency / 100 + BoxColr.Blue);

                    // Draw the fill
                    FillSym         = new SimpleFillSymbolClass();
                    FillSym.Color   = BoxColr;
                    FillSym.Style   = esriSimpleFillStyle.esriSFSSolid;
                    FillSym.Outline = BlackOutsides;

                    FillEle = CreateFillElement(Geo, FillSym) as IFillShapeElement;

                    // Label the box
                    LabelText = aDescription.Label;

                    // Subscripting!!

                    for (int i = 0; i < LabelText.Length; i++)
                    {
                        string thisBit = LabelText.Substring(i, 1);
                        int    num;
                        if (int.TryParse(thisBit, out num)) // Checks if the character is numeric
                        {
                            LabelText = LabelText.Replace(thisBit, "<sub>" + thisBit + "</sub>");
                            i         = i + 5;
                        }
                    }
                    LabelText = LabelText.Replace("ir", "i<sub>r</sub>");
                    LabelText = LabelText.Replace("yc", "y<sub>c</sub>");

                    // Center the label
                    LabelPoint   = new PointClass();
                    LabelPoint.X = Point.X - BoxX / 2 - Text2BoxX;
                    LabelPoint.Y = Point.Y - BoxY / 2;

                    //LabelText = GetFormattedString(LabelText, "FGDCGeoAge", 8, StringLength, 0);
                    Ele = MakeTextElement(LabelPoint, LabelText, "FGDCGeoAge", true) as IElement;

                    // Add the box and label
                    IGroupElement3 group = new GroupElementClass();
                    group.AddElement(FillEle as IElement);
                    group.AddElement(Ele);
                    GraphicsContainer.AddElement(group as IElement, 0);
                }

                // Do a partial refresh
                //Doc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                // Setup the Y coordinates for the next entry
                // if the height of this item's text is bigger than the minimum distance between text and box
                if (TempEnv.Height > Text2BoxY)
                {
                    // Subtract the box height and the text height to get the new ycoord
                    Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                }
                else
                {
                    if (isHeading)
                    {
                        Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                    }
                    else
                    {
                        Ycoord = Ycoord - (BoxY + Text2BoxY);
                    }
                }
            }

            // Done, refresh, turn off the tool
            Doc.ActiveView.Refresh();
            ArcMap.Application.CurrentTool = null;
        }