Ejemplo n.º 1
0
 //文字符号化
 private void CharacterMarkerSymbolToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         //获得点图层,要求当前地图文档第一个图层为点图层
         IFeatureLayer layer;
         layer = mainMapControl.get_Layer(0) as IFeatureLayer;
         //QI到IGeoFeatureLayer
         IGeoFeatureLayer       geoFeatureLayer        = layer as IGeoFeatureLayer;
         SimpleRenderer         simpleRender           = new SimpleRendererClass();
         ICharacterMarkerSymbol pCharacterMarkerSymbol = new CharacterMarkerSymbolClass();
         IColor pColor = new RgbColorClass();
         pColor.RGB = 2256;
         stdole.IFontDisp font = new stdole.StdFontClass() as stdole.IFontDisp;
         font.Name = "Arial"; font.Size = 30;
         font.Bold = true;
         pCharacterMarkerSymbol.Font           = font;
         pCharacterMarkerSymbol.Color          = pColor;
         pCharacterMarkerSymbol.Size           = 20;
         pCharacterMarkerSymbol.CharacterIndex = 55;
         //ASCII55对应数字7
         simpleRender.Symbol      = pCharacterMarkerSymbol as ISymbol;
         geoFeatureLayer.Renderer = simpleRender as IFeatureRenderer;
         mainMapControl.Refresh();
         axTOCControl1.Update();
     }
     catch
     {
         MessageBox.Show("没有可以实例化的图层");
     }
 }
Ejemplo n.º 2
0
        public InsertTextForm()
        {
            InitializeComponent();
            ////变量初始化
            //_textAngle = 0;
            //_textColor = ColorImp.GetRGBColor(Color.Red.R, Color.Red.G, Color.Red.B) as IColor;
            //_textFont = new stdole.StdFontClass() as stdole.IFontDisp;
            //_textFont.Name = FontType.宋体.ToString();
            //_textSize = 20;

            ////控件初始化
            //txbxInsertText.Text = "未知文本";
            //txbxInsertText.SelectAll();
            //cmbxFont.DataSource = System.Enum.GetNames(typeof(FontType));
            //cmbxFont.SelectedIndex = 0;
            //cmbxSize.DataSource = _sizeArr;
            //cmbxSize.SelectedIndex = this.cmbxSize.FindString("20");
            //btnColor.BackColor = Color.Red;

            IColor    textColor = ElementPropetyImp.GetRGBColor(0, 0, 0) as IColor;
            IFontDisp textFont  = new stdole.StdFontClass() as stdole.IFontDisp;

            textFont.Name = FontType.宋体.ToString();
            InitVariablesAndControls(0, textColor, textFont, 20, "未知文本");
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 文字符号大小变化时触发事件
 /// </summary>
 /// <param name="sender">文字符号大小组合框控件</param>
 /// <param name="e">TextEdit选择值变化事件参数</param>
 private void comTextSymbolsFontSize_SelectedValueChanged(object sender, EventArgs e)
 {
     stdole.Font pFont = new stdole.StdFontClass();
     pFont.Name                   = pTextSymbol.Font.Name;
     pFont.Underline              = pTextSymbol.Font.Underline;
     pFont.Strikethrough          = pTextSymbol.Font.Strikethrough;
     pFont.Italic                 = pTextSymbol.Font.Italic;
     pFont.Bold                   = pTextSymbol.Font.Bold;
     pFont.Size                   = Convert.ToDecimal(comTextSymbolsFontSize.EditValue);
     pTextSymbol.Font             = pFont as IFontDisp;
     currentStyleGalleryItem.Item = pTextSymbol;
     PreviewImage();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 字体删除状态变化时触发事件
 /// </summary>
 /// <param name="sender">字体按钮</param>
 /// <param name="e">Button单击事件参数</param>
 private void btnTextSymbolsStrikethrough_CheckedChanged(object sender, EventArgs e)
 {
     stdole.Font pFont = new stdole.StdFontClass();
     pFont.Name                   = pTextSymbol.Font.Name;
     pFont.Size                   = pTextSymbol.Font.Size;
     pFont.Bold                   = pTextSymbol.Font.Bold;
     pFont.Italic                 = pTextSymbol.Font.Italic;
     pFont.Underline              = pTextSymbol.Font.Underline;
     pFont.Strikethrough          = btnTextSymbolsStrikethrough.Checked;
     pTextSymbol.Font             = pFont as IFontDisp;
     currentStyleGalleryItem.Item = pTextSymbol;
     PreviewImage();
 }
Ejemplo n.º 5
0
        private static ITextElement MakeTextElement(IPoint pPoint, string strText, string sFontName, bool Centered = false, long FontSize = 8)
        {
            // Setup a color
            IRgbColor pRGBColor = new RgbColorClass();

            pRGBColor.Blue  = 0;
            pRGBColor.Red   = 0;
            pRGBColor.Green = 0;

            // Set text element at the right place
            ITextElement pTextElement = new TextElementClass();
            IElement     pElement     = pTextElement as IElement;

            pElement.Geometry = pPoint;

            try
            {
                // Setup a Font
                IFontDisp pFontDisp = new stdole.StdFontClass() as IFontDisp;
                pFontDisp.Name = sFontName;

                // Setup a TextSymbol that the TextElement will draw with
                ITextSymbol pTextSymbol = new TextSymbolClass();
                pTextSymbol.Font  = pFontDisp;
                pTextSymbol.Color = pRGBColor;
                pTextSymbol.Size  = FontSize;

                // Center if appropriate
                if (Centered == true)
                {
                    pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
                    pTextSymbol.VerticalAlignment   = esriTextVerticalAlignment.esriTVACenter;
                }
                else
                {
                    pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                    pTextSymbol.VerticalAlignment   = esriTextVerticalAlignment.esriTVATop;
                }

                // Give the TextSymbol and string to the TextElement
                pTextElement.Symbol = pTextSymbol;
                pTextElement.Text   = strText;
            }
            catch (Exception e)
            {
                MessageBox.Show("Make Text Element : " + strText + " " + sFontName + " Error: " + e.StackTrace);
            }
            return(pTextElement);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// CJK字符变化时触发事件
        /// </summary>
        /// <param name="sender">CJK字符状态按钮</param>
        /// <param name="e">TextEdit状态变化事件参数</param>
        private void chkTextSymbolsCJK_CheckedChanged(object sender, EventArgs e)
        {
            stdole.Font pFont = new stdole.StdFontClass();
            pFont.Name          = pTextSymbol.Font.Name;
            pFont.Size          = pTextSymbol.Font.Size;
            pFont.Bold          = pTextSymbol.Font.Bold;
            pFont.Italic        = pTextSymbol.Font.Italic;
            pFont.Underline     = pTextSymbol.Font.Underline;
            pFont.Strikethrough = pTextSymbol.Font.Strikethrough;
            pTextSymbol.Font    = pFont as IFontDisp;
            ICharacterOrientation pCharacterOrientation = pTextSymbol as ICharacterOrientation;

            pCharacterOrientation.CJKCharactersRotation = chkTextSymbolsCJK.Checked;
            currentStyleGalleryItem.Item = pTextSymbol;
            PreviewImage();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Symbol Render
        /// </summary>
        /// <param name="currentLayer"></param>
        /// <param name="breakCount"></param>
        /// <author>Shen Yongyuan</author>
        /// <date>20091114</date>
        public static void SymbolRender(ILayer currentLayer, string fieldName)
        {
            IGeoFeatureLayer pGeoFeatureL = currentLayer as IGeoFeatureLayer;

            pGeoFeatureL.ScaleSymbols = true;

            //Use the statistics objects to calculate the max value and the min value
            IFeatureCursor  pCursor         = pGeoFeatureL.DisplayFeatureClass.Search(null, true);
            IDataStatistics pDataStatistics = new DataStatisticsClass();

            pDataStatistics.Cursor = pCursor as ICursor;
            pDataStatistics.Field  = fieldName;
            IStatisticsResults pStatisticsResult = pDataStatistics.Statistics;


            IFillSymbol pFillSymbol = new SimpleFillSymbolClass();

            pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(239, 228, 190));
            ICharacterMarkerSymbol pCharaterMarkerS = new CharacterMarkerSymbolClass();

            stdole.StdFont pFontDisp = new stdole.StdFontClass();
            pFontDisp.Name                  = "ESRI Default Marker";
            pFontDisp.Size                  = 30;
            pCharaterMarkerS.Font           = (IFontDisp)pFontDisp;
            pCharaterMarkerS.CharacterIndex = 81;
            pCharaterMarkerS.Color          = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(255, 0, 0));
            pCharaterMarkerS.Size           = 30;

            IProportionalSymbolRenderer pProportionalSymbolR = new ProportionalSymbolRendererClass();

            pProportionalSymbolR.ValueUnit            = esriUnits.esriUnknownUnits;
            pProportionalSymbolR.Field                = fieldName;
            pProportionalSymbolR.FlanneryCompensation = false;
            pProportionalSymbolR.MinDataValue         = pStatisticsResult.Minimum;
            pProportionalSymbolR.MaxDataValue         = pStatisticsResult.Maximum;
            pProportionalSymbolR.BackgroundSymbol     = pFillSymbol;
            pProportionalSymbolR.MinSymbol            = (ISymbol)pCharaterMarkerS;
            pProportionalSymbolR.LegendSymbolCount    = 12;
            pProportionalSymbolR.CreateLegendSymbols();

            pGeoFeatureL.Renderer = (IFeatureRenderer)pProportionalSymbolR;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// ÉèÖÃÊôÐÔ±ê×¢
        /// </summary>
        /// <param name="pGeoFeatureLayer">ͼ²ã</param>
        /// <param name="vLabelField">ÊôÐÔ×Ö¶Î</param>
        /// <param name="vMapFrameScale">ͼ²ã±ÈÀý³ß</param>
        /// <param name="vMapRefrenceScale">²Î¿¼±ÈÀý³ß</param>
        private void SetLableToGeoFeatureLayer(IGeoFeatureLayer pGeoFeatureLayer, string vLabelField, int vMapFrameScale, double vMapRefrenceScale)
        {
            IAnnotateLayerPropertiesCollection pAnnoLayerProperCol = pGeoFeatureLayer.AnnotationProperties;
            IAnnotateLayerProperties           pAnnoLayerProper;
            IElementCollection placedElements;
            IElementCollection unplacedElements;

            //µÃµ½µ±Ç°²ãµÄµ±Ç°±ê×¢ÊôÐÔ
            pAnnoLayerProperCol.QueryItem(0, out pAnnoLayerProper, out placedElements, out unplacedElements);
            ILabelEngineLayerProperties      pLabelEngineLayerProper     = (ILabelEngineLayerProperties)pAnnoLayerProper;
            IBasicOverposterLayerProperties4 pBasicOverposterLayerProper = (IBasicOverposterLayerProperties4)pLabelEngineLayerProper.BasicOverposterLayerProperties;
            //±ê×¢µÄ×ÖÌå
            ITextSymbol pTextSymbol = pLabelEngineLayerProper.Symbol;
            IRgbColor   pRGBColor   = new RgbColorClass();

            pRGBColor.Red     = 0;
            pRGBColor.Blue    = 255;
            pRGBColor.Green   = 0;
            pTextSymbol.Color = pRGBColor;
            stdole.StdFont pStdFont = new stdole.StdFontClass();
            IFontDisp      pFont    = (IFontDisp)pStdFont;

            pFont.Name = "ËÎÌå";
            if (vMapRefrenceScale != 0)
            {
                double size = (vMapFrameScale / 3) * vMapFrameScale / vMapRefrenceScale;
                pFont.Size = (decimal)size;
            }
            pTextSymbol.Font = pFont;
            //±ê×¢ÄÚÈÝ
            pLabelEngineLayerProper.Expression          = "[" + vLabelField + "]";
            pBasicOverposterLayerProper.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerPart;
            //±ê×¢µÄ·½ÏòÐÅÏ¢
            pBasicOverposterLayerProper.PolygonPlacementMethod = esriOverposterPolygonPlacementMethod.esriAlwaysHorizontal;
            //±ê×¢µÄÓ뼸ºÎͼÐεĴóС¹Øϵ
            pBasicOverposterLayerProper.PlaceOnlyInsidePolygon = false;
            //¿ªÆô±ê×¢
            pGeoFeatureLayer.DisplayAnnotation = true;
        }
Ejemplo n.º 9
0
        private void CharacterpointToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFeatureLayer layer;

            layer = axMapControl1.get_Layer(0) as IFeatureLayer;                       //QI到IGeoFeatureLayer
            IGeoFeatureLayer       geoFeatureLayer        = layer as IGeoFeatureLayer; //新建SimpleRendererClass对象
            SimpleRenderer         simpleRender           = new SimpleRendererClass();
            ICharacterMarkerSymbol pCharacterMarkerSymbol = new CharacterMarkerSymbolClass();
            IColor pColor = new RgbColorClass();

            pColor.RGB = 2256;
            stdole.IFontDisp font = new stdole.StdFontClass() as stdole.IFontDisp;
            font.Name = "Arial"; font.Size = 30;
            font.Bold = true;
            pCharacterMarkerSymbol.Font           = font;
            pCharacterMarkerSymbol.Color          = pColor;
            pCharacterMarkerSymbol.Size           = 20;
            pCharacterMarkerSymbol.CharacterIndex = 55; //ASCII55对应数字7
            simpleRender.Symbol      = pCharacterMarkerSymbol as ISymbol;
            geoFeatureLayer.Renderer = simpleRender as IFeatureRenderer;
            axMapControl1.Refresh();
            axTOCControl1.Update();
        }
Ejemplo n.º 10
0
        private string GetFormattedString(string strTextContent, string strFontName, Single sngFontSizeInPoints, double sngMaxWidthInPoints, long hanging)
        {
            System.Array varWordArray;
            IMxApplication pMxApp = ArcMap.Application as IMxApplication;
            IAppDisplay pAppDisplay = pMxApp.Display;
            IDisplayTransformation pTransformation = pAppDisplay.DisplayTransformation;
            IFontDisp pTextFont = new stdole.StdFontClass() as IFontDisp;
            ITextSymbol pTextSymbol = new TextSymbolClass();
            double dblXSize;
            double dblYSize;
            string strGoodWidth = "";
            string strFinalString = "";
            string strTestString = "";
            int i;

            // Split the string into an array of words
            varWordArray = strTextContent.Split(' ') as System.Array;

            // Set up the Font
            pTextFont.Name = strFontName;
            pTextFont.Size = decimal.Parse(sngFontSizeInPoints.ToString());

            // Setup the Text Symbol
            pTextSymbol.Font = pTextFont;

            // Setup spacing string for hanging indent
            int pSpaces, i3;
            string hangingIndent;
            pAppDisplay.StartDrawing(pAppDisplay.hDC, 0);
            hangingIndent = ""; //minimum hanging indent
            if (hanging > 0)
            {
                pTextSymbol.GetTextSize(pAppDisplay.hDC, pTransformation, " ", out dblXSize, out dblYSize);
                pSpaces = (int)System.Math.Round(hanging / dblXSize);
                for (i3 = 0; i3 == pSpaces; i3++)
                {
                    hangingIndent = hangingIndent + " ";
                }
            } // do nothing if hanging is 0
            pAppDisplay.FinishDrawing(); // done setting up the hanging indent

            // Add each word into the test string and test for width
            pAppDisplay.StartDrawing(pAppDisplay.hDC, 0);
            long linesAdded = 0;

            for (i = 0; i <= (int)varWordArray.GetUpperBound(0); i++)
            {
                if (strGoodWidth != "")
                {
                    strTestString = strGoodWidth + " " + varWordArray.GetValue(i);
                }
                else
                {
                    strTestString = varWordArray.GetValue(i).ToString();
                }

                // Get the TextSize
                if (linesAdded == 0)
                {
                    pTextSymbol.GetTextSize(pAppDisplay.hDC, pTransformation, strTestString, out dblXSize, out dblYSize);
                }
                else
                {
                    pTextSymbol.GetTextSize(pAppDisplay.hDC, pTransformation, "    " + strTestString, out dblXSize, out dblYSize);
                }

                // If the word added is < max width keep adding to the line, else make a new one
                if (dblXSize < sngMaxWidthInPoints)
                {
                    strGoodWidth = strTestString;
                }
                else
                {
                    if (linesAdded == 0)
                    {
                        strFinalString = hangingIndent + strGoodWidth;
                    }
                    else
                    {
                        strFinalString = strFinalString + Environment.NewLine + hangingIndent + "    " + strGoodWidth;
                    }
                    linesAdded = linesAdded + 1;
                    strGoodWidth = varWordArray.GetValue(i).ToString();
                }
            }

            strFinalString = strFinalString + Environment.NewLine + hangingIndent + "    " + strGoodWidth;
            pAppDisplay.FinishDrawing();

            //return strFinalString.Substring(2);
            return strFinalString;
        }
        private static string GetFormattedString(string strTextContent, string strFontName, Single sngFontSizeInPoints, double sngMaxWidthInPoints, long hanging)
        {
            System.Array           varWordArray;
            IMxApplication         pMxApp          = ArcMap.Application as IMxApplication;
            IAppDisplay            pAppDisplay     = pMxApp.Display;
            IDisplayTransformation pTransformation = pAppDisplay.DisplayTransformation;
            IFontDisp   pTextFont   = new stdole.StdFontClass() as IFontDisp;
            ITextSymbol pTextSymbol = new TextSymbolClass();
            double      dblXSize;
            double      dblYSize;
            string      strGoodWidth   = "";
            string      strFinalString = "";
            string      strTestString  = "";
            int         i;

            // Split the string into an array of words
            varWordArray = strTextContent.Split(' ') as System.Array;

            // Set up the Font
            pTextFont.Name = strFontName;
            pTextFont.Size = decimal.Parse(sngFontSizeInPoints.ToString());

            // Setup the Text Symbol
            pTextSymbol.Font = pTextFont;

            // Add each word into the test string and test for width
            pAppDisplay.StartDrawing(pAppDisplay.hDC, 0);
            long linesAdded = 0;

            for (i = 0; i <= (int)varWordArray.GetUpperBound(0); i++)
            {
                if (strGoodWidth != "")
                {
                    strTestString = strGoodWidth + " " + varWordArray.GetValue(i);
                }
                else
                {
                    strTestString = varWordArray.GetValue(i).ToString();
                }

                // Get the TextSize
                pTextSymbol.GetTextSize(pAppDisplay.hDC, pTransformation, strTestString, out dblXSize, out dblYSize);

                // If the word added is < max width keep adding to the line, else make a new one
                if (dblXSize < sngMaxWidthInPoints)
                {
                    strGoodWidth = strTestString;
                }
                else
                {
                    if (linesAdded == 0)
                    {
                        strFinalString = strGoodWidth;
                    }
                    else
                    {
                        strFinalString = strFinalString + Environment.NewLine + strGoodWidth;
                    }
                    linesAdded   = linesAdded + 1;
                    strGoodWidth = varWordArray.GetValue(i).ToString();
                }
            }

            strFinalString = strFinalString + Environment.NewLine + strGoodWidth;
            pAppDisplay.FinishDrawing();

            return(strFinalString);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 创建注记层
        /// </summary>
        /// <param name="strFeaClsName">注记层名称</param>
        /// <param name="destDataset">待创建的注记层所在的featuredataset</param>
        /// <param name="ipInputFields">注记层字段</param>
        public static IFeatureClass CreateAnnotation(IFeatureClass pInputCls, IFeatureDataset destDataset, IFields ipInputFields)
        {
            try
            {
                //要素类标识信息
                IObjectClassDescription  ipObjectClassDesc = new AnnotationFeatureClassDescription();
                IFeatureClassDescription ipFeatClassDesc   = (IFeatureClassDescription)ipObjectClassDesc;


                IAnnoClass pAnnoClass = pInputCls.Extension as IAnnoClass;
                double     scale      = pAnnoClass.ReferenceScale;


                IUID ipCLSID = ipObjectClassDesc.InstanceCLSID;
                ipCLSID.Value = "esriCore.AnnotationFeature";


                IUID ipExtCLSID = ipObjectClassDesc.ClassExtensionCLSID;
                ipExtCLSID.Value = "esriCore.AnnotationFeatureClassExtension";

                //IField ipField;
                IFields     ipFields     = ipObjectClassDesc.RequiredFields;
                IFieldsEdit ipFieldsEdit = (IFieldsEdit)ipFields;
                int         numFields    = ipInputFields.FieldCount;

                esriFieldType type;
                for (int i = 0; i < numFields; i++)
                {
                    IField ipField = ipInputFields.get_Field(i);
                    type = ipField.Type;
                    if (type != esriFieldType.esriFieldTypeOID && type != esriFieldType.esriFieldTypeGeometry)
                    {
                        string fldName  = ipField.Name;
                        int    fldIndex = ipFields.FindField(fldName);

                        if (fldIndex == -1)
                        {
                            ipFieldsEdit.AddField(ipField);
                        }
                    }
                }

                //工作空间
                IWorkspace            ipWorkspace            = destDataset.Workspace;
                IFeatureWorkspaceAnno ipFeatureWorkspaceAnno = (IFeatureWorkspaceAnno)ipWorkspace;


                //显示比例
                IGraphicsLayerScale ipGraphicsLayerScale = new GraphicsLayerScaleClass();
                ipGraphicsLayerScale.ReferenceScale = scale;
                ipGraphicsLayerScale.Units          = pAnnoClass.ReferenceScaleUnits;

                //符号信息
                //' set up symbol collection
                ISymbolCollection pSymbolColl = new SymbolCollectionClass();

                ITextSymbol myTxtSym = new TextSymbolClass();
                //Set the font for myTxtSym
                stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
                IFont            pFt    = (IFont)myFont;
                pFt.Name = "Courier New";

                myTxtSym.Font = myFont;

                // Set the Color for myTxtSym to be Dark Red
                IRgbColor myColor = new RgbColorClass();
                myColor.Red    = 150;
                myColor.Green  = 0;
                myColor.Blue   = 0;
                myTxtSym.Color = myColor;

                // Set other properties for myTxtSym
                myTxtSym.Angle               = 0;
                myTxtSym.RightToLeft         = false;
                myTxtSym.VerticalAlignment   = esriTextVerticalAlignment.esriTVABaseline;
                myTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;
                myTxtSym.Size = 9;

                ISymbol pSymbol = (ISymbol)myTxtSym;
                pSymbolColl.set_Symbol(0, pSymbol);


                //set up the annotation labeling properties including the expression
                IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();
                pAnnoProps.FeatureLinked = true;
                pAnnoProps.AddUnplacedToGraphicsContainer = false;
                pAnnoProps.CreateUnplacedElements         = true;
                pAnnoProps.DisplayAnnotation = true;
                pAnnoProps.UseOutput         = true;

                ILabelEngineLayerProperties pLELayerProps       = (ILabelEngineLayerProperties)pAnnoProps;
                IAnnotationExpressionEngine aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();
                pLELayerProps.ExpressionParser   = aAnnoVBScriptEngine;
                pLELayerProps.Expression         = "[DESCRIPTION]";
                pLELayerProps.IsExpressionSimple = true;
                pLELayerProps.Offset             = 0;
                pLELayerProps.SymbolID           = 0;
                pLELayerProps.Symbol             = myTxtSym;

                IAnnotateLayerTransformationProperties pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
                double dRefScale = ipGraphicsLayerScale.ReferenceScale;
                pATP.ReferenceScale = dRefScale;
                pATP.Units          = esriUnits.esriMeters;
                pATP.ScaleRatio     = 1;

                IAnnotateLayerPropertiesCollection pAnnoPropsColl = new AnnotateLayerPropertiesCollectionClass();
                pAnnoPropsColl.Add(pAnnoProps);

                //' use the AnnotationFeatureClassDescription co - class to get the list of required fields and the default name of the shape field
                IObjectClassDescription  pOCDesc = new AnnotationFeatureClassDescriptionClass();
                IFeatureClassDescription pFDesc  = (IFeatureClassDescription)pOCDesc;

                IFields pReqFields       = pOCDesc.RequiredFields;
                IUID    pInstCLSID       = pOCDesc.InstanceCLSID;
                IUID    pExtCLSID        = pOCDesc.ClassExtensionCLSID;
                string  bsShapeFieldName = pFDesc.ShapeFieldName;

                IDataset pDs = (IDataset)pInputCls;

                //创建
                string        bstName  = ipFeatClassDesc.ShapeFieldName;
                IFeatureClass pOutFcls =
                    ipFeatureWorkspaceAnno.CreateAnnotationClass(pDs.Name, ipFields, pOCDesc.InstanceCLSID,
                                                                 pOCDesc.ClassExtensionCLSID, pInputCls.ShapeFieldName, "", destDataset, null, pAnnoPropsColl,
                                                                 ipGraphicsLayerScale, pSymbolColl, true);
                return(pOutFcls);
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(null);
            }
            return(null);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 比例符号法渲染器(ProportionalSymbolRenderer)——用不同大小的符号绘制要素, 其大小对应某一字段值的比例。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 比例符号法渲染ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //声明IGeoFeatureLayer变量, 提供一个要素图层对成员控制地理特征的入口
            IGeoFeatureLayer geoFeatureLayer;
            //声明要素图层
            IFeatureLayer pFtLayer;
            //声明专题图变量
            //在利用该方法进行着色时, 需获得最大和最小标识符号所代表的字段及其各个数值, 还需要确定每个字段数值所匹配的着色符号。
            IProportionalSymbolRenderer proportionalSymbolRenderer;
            //声明表格
            ITable table;
            //声明游标
            ICursor cursor;
            //用于统计变量
            IDataStatistics dataStatistics;
            //用于存放统计结果
            IStatisticsResults statisticsResults;

            //声明一个字体对象
            stdole.IFontDisp fontDisp;
            //获取图层
            geoFeatureLayer = getGeoLayer("北部湾");
            //强转为要素图层
            pFtLayer = geoFeatureLayer as IFeatureLayer;
            //图层类型转换成表
            table = geoFeatureLayer as ITable;
            //获取游标
            cursor = table.Search(null, true);
            //实例化数据统计对象
            dataStatistics = new DataStatisticsClass();
            //赋游标给数据统计对象的游标
            dataStatistics.Cursor = cursor;
            //获取图层要素中进行专题地图制图的字段名称, 此实例中所用的数据中字段名为"年"(2010年GDP增长速率)
            dataStatistics.Field = "年";
            //存放统计结果为统计对象的统计数据
            statisticsResults = dataStatistics.Statistics;
            //如果统计结果不为空
            if (statisticsResults != null)
            {
                //简单填充符号
                IFillSymbol fillSymbol = new SimpleFillSymbolClass();
                //设置颜色
                fillSymbol.Color = getRGB(195, 255, 255);
                //设置简单线型符号
                ISimpleLineSymbol SLS = new SimpleLineSymbolClass();
                SLS.Color          = getRGB(196, 196, 196); //颜色
                SLS.Width          = 1.5;                   //宽度
                fillSymbol.Outline = SLS;                   //外边界线
                //利用ESRI特殊符号调用成员进行填充
                ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass();
                fontDisp = new stdole.StdFontClass() as stdole.IFontDisp;
                //调用指定子库(ESRI Default Marker是子库名称)
                fontDisp.Name = "ESRI Default Marker";

                //对characterMarkerSymbol的font属性
                characterMarkerSymbol.Font = fontDisp;
                //特征标记符号(Character Marker Symbol)的索引值
                //0xB6是C#特殊的16进制表示方法, 换算为十进制值182
                characterMarkerSymbol.CharacterIndex = 0xB6;
                //特征标记符号的颜色
                characterMarkerSymbol.Color = getRGB(253, 191, 110);
                //设计特征标记符号的尺寸
                characterMarkerSymbol.Size = 18;
                //实例化一个比例符号渲染器
                proportionalSymbolRenderer           = new ProportionalSymbolRendererClass();
                proportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits;
                //获取渲染字段
                proportionalSymbolRenderer.Field = "年";
                //是否启用颜色补偿(默认为否)
                proportionalSymbolRenderer.FlanneryCompensation = false;
                //赋值统计数据(比例符号渲染器)
                //MinDataValue获取数据中最小值
                proportionalSymbolRenderer.MinDataValue = statisticsResults.Minimum;
                //获取数据中最大值
                proportionalSymbolRenderer.MaxDataValue = statisticsResults.Maximum;
                //在多边形特征上绘制比例标记符号时使用的背景填充符号
                proportionalSymbolRenderer.BackgroundSymbol = fillSymbol;
                //用于绘制具有规格化最小数据值的特征的符号。
                proportionalSymbolRenderer.MinSymbol = characterMarkerSymbol as ISymbol;
                //目录和图例中显示的符号数为3
                proportionalSymbolRenderer.LegendSymbolCount = 3;
                //创建图例, 设置完所有属性后调用。
                proportionalSymbolRenderer.CreateLegendSymbols();
                //赋值目标图层的渲染器属性
                geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer;
            }
            axMapControl1.Refresh(); //刷新axMapControl1
            axTOCControl1.Update();  //更新axTOCControl1
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 创建注记层
        /// </summary>
        /// <param name="strFeaClsName">注记层名称</param>
        /// <param name="destDataset">待创建的注记层所在的featuredataset</param>
        /// <param name="ipInputFields">注记层字段</param>
        public static IFeatureClass CreateAnnotation(IFeatureClass pInputCls, IFeatureDataset destDataset, IFields ipInputFields)
        {
            try
            {
                //要素类标识信息
                IObjectClassDescription ipObjectClassDesc = new AnnotationFeatureClassDescription();
                IFeatureClassDescription ipFeatClassDesc = (IFeatureClassDescription)ipObjectClassDesc;

                IAnnoClass pAnnoClass = pInputCls.Extension as IAnnoClass;
                double scale = pAnnoClass.ReferenceScale;

                IUID ipCLSID = ipObjectClassDesc.InstanceCLSID;
                ipCLSID.Value = "esriCore.AnnotationFeature";

                IUID ipExtCLSID = ipObjectClassDesc.ClassExtensionCLSID;
                ipExtCLSID.Value = "esriCore.AnnotationFeatureClassExtension";

                //IField ipField;
                IFields ipFields = ipObjectClassDesc.RequiredFields;
                IFieldsEdit ipFieldsEdit = (IFieldsEdit)ipFields;
                int numFields = ipInputFields.FieldCount;

                esriFieldType type;
                for (int i = 0; i < numFields; i++)
                {
                    IField ipField = ipInputFields.get_Field(i);
                    type = ipField.Type;
                    if (type != esriFieldType.esriFieldTypeOID && type != esriFieldType.esriFieldTypeGeometry)
                    {
                        string fldName = ipField.Name;
                        int fldIndex = ipFields.FindField(fldName);

                        if (fldIndex == -1)
                            ipFieldsEdit.AddField(ipField);
                    }
                }

                //工作空间
                IWorkspace ipWorkspace = destDataset.Workspace;
                IFeatureWorkspaceAnno ipFeatureWorkspaceAnno = (IFeatureWorkspaceAnno)ipWorkspace;

                //显示比例
                IGraphicsLayerScale ipGraphicsLayerScale = new GraphicsLayerScaleClass();
                ipGraphicsLayerScale.ReferenceScale = scale;
                ipGraphicsLayerScale.Units = pAnnoClass.ReferenceScaleUnits;

                //符号信息
                //' set up symbol collection
                ISymbolCollection pSymbolColl = new SymbolCollectionClass();

                ITextSymbol myTxtSym = new TextSymbolClass();
                //Set the font for myTxtSym
                stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
                IFont pFt = (IFont)myFont;
                pFt.Name = "Courier New";

                myTxtSym.Font = myFont;

                // Set the Color for myTxtSym to be Dark Red
                IRgbColor myColor = new RgbColorClass();
                myColor.Red = 150;
                myColor.Green = 0;
                myColor.Blue = 0;
                myTxtSym.Color = myColor;

                // Set other properties for myTxtSym
                myTxtSym.Angle = 0;
                myTxtSym.RightToLeft = false;
                myTxtSym.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline;
                myTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;
                myTxtSym.Size = 9;

                ISymbol pSymbol = (ISymbol)myTxtSym;
                pSymbolColl.set_Symbol(0, pSymbol);

                //set up the annotation labeling properties including the expression
                IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();
                pAnnoProps.FeatureLinked = true;
                pAnnoProps.AddUnplacedToGraphicsContainer = false;
                pAnnoProps.CreateUnplacedElements = true;
                pAnnoProps.DisplayAnnotation = true;
                pAnnoProps.UseOutput = true;

                ILabelEngineLayerProperties pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps;
                IAnnotationExpressionEngine aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();
                pLELayerProps.ExpressionParser = aAnnoVBScriptEngine;
                pLELayerProps.Expression = "[DESCRIPTION]";
                pLELayerProps.IsExpressionSimple = true;
                pLELayerProps.Offset = 0;
                pLELayerProps.SymbolID = 0;
                pLELayerProps.Symbol = myTxtSym;

                IAnnotateLayerTransformationProperties pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
                double dRefScale = ipGraphicsLayerScale.ReferenceScale;
                pATP.ReferenceScale = dRefScale;
                pATP.Units = esriUnits.esriMeters;
                pATP.ScaleRatio = 1;

                IAnnotateLayerPropertiesCollection pAnnoPropsColl = new AnnotateLayerPropertiesCollectionClass();
                pAnnoPropsColl.Add(pAnnoProps);

                //' use the AnnotationFeatureClassDescription co - class to get the list of required fields and the default name of the shape field
                IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescriptionClass();
                IFeatureClassDescription pFDesc = (IFeatureClassDescription)pOCDesc;

                IFields pReqFields = pOCDesc.RequiredFields;
                IUID pInstCLSID = pOCDesc.InstanceCLSID;
                IUID pExtCLSID = pOCDesc.ClassExtensionCLSID;
                string bsShapeFieldName = pFDesc.ShapeFieldName;

                IDataset pDs = (IDataset)pInputCls;

                //创建
                string bstName = ipFeatClassDesc.ShapeFieldName;
                IFeatureClass pOutFcls =
                    ipFeatureWorkspaceAnno.CreateAnnotationClass(pDs.Name, ipFields, pOCDesc.InstanceCLSID,
                                                                 pOCDesc.ClassExtensionCLSID, pInputCls.ShapeFieldName, "", destDataset, null, pAnnoPropsColl,
                                                                 ipGraphicsLayerScale, pSymbolColl, true);
                return pOutFcls;
            }
            catch(Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return null;
            }
            return null;
        }
Ejemplo n.º 15
0
        private ITextElement MakeTextElement(IPoint pPoint, string strText, string sFontName, bool Centered = false, long FontSize = 8)
        {
            // Setup a color
            IRgbColor pRGBColor = new RgbColorClass();
            pRGBColor.Blue = 0;
            pRGBColor.Red = 0;
            pRGBColor.Green = 0;

            // Set text element at the right place
            ITextElement pTextElement = new TextElementClass();
            IElement pElement = pTextElement as IElement;
            pElement.Geometry = pPoint;

            // Setup a Font
            IFontDisp pFontDisp = new stdole.StdFontClass() as IFontDisp;
            pFontDisp.Name = sFontName;

            // Setup a TextSymbol that the TextElement will draw with
            ITextSymbol pTextSymbol = new TextSymbolClass();
            pTextSymbol.Font = pFontDisp;
            pTextSymbol.Color = pRGBColor;
            pTextSymbol.Size = FontSize;

            // Center if appropriate
            if (Centered == true)
            {
                pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
                pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
            }
            else
            {
                pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
            }

            // Give the TextSymbol and string to the TextElement
            pTextElement.Symbol = pTextSymbol;
            pTextElement.Text = strText;

            return pTextElement;
        }
Ejemplo n.º 16
0
        //拉框选择
        private void mainMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (flag == 1)
            {
                baseOrder.box_select(e);
            }
            //屏幕坐标点转化为地图坐标点
            pPointPt = (mainMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

            if (e.button == 1)
            {
                IActiveView pActiveView = mainMapControl.ActiveView;
                IEnvelope   pEnvelope   = new EnvelopeClass();
                if (pMouseOperate == "MeasureLength")
                {
                    //判断追踪线对象是否为空,若是则实例化并设置当前鼠标点为起始点
                    if (pNewLineFeedback == null)
                    {
                        //实例化追踪线对象
                        pNewLineFeedback         = new NewLineFeedbackClass();
                        pNewLineFeedback.Display = (mainMapControl.Map as IActiveView).ScreenDisplay;
                        //设置起点,开始动态线绘制
                        pNewLineFeedback.Start(pPointPt);
                        dToltalLength = 0;
                    }
                    else //如果追踪线对象不为空,则添加当前鼠标点
                    {
                        pNewLineFeedback.AddPoint(pPointPt);
                    }
                    //pGeometry = m_PointPt;
                    if (dSegmentLength != 0)
                    {
                        dToltalLength = dToltalLength + dSegmentLength;
                    }
                }
                else if (pMouseOperate == "MeasureArea")
                {
                    if (pNewPolygonFeedback == null)
                    {
                        //实例化追踪面对象
                        pNewPolygonFeedback         = new NewPolygonFeedback();
                        pNewPolygonFeedback.Display = (mainMapControl.Map as IActiveView).ScreenDisplay;
                        ;
                        pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount);
                        //开始绘制多边形
                        pNewPolygonFeedback.Start(pPointPt);
                        pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing);
                    }
                    else
                    {
                        pNewPolygonFeedback.AddPoint(pPointPt);
                        pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing);
                    }
                }
            }
            else if (e.button == 2)
            {
                pMouseOperate = "";
                mainMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
            }

            if (flag == 0)
            {
                mainMapControl.CurrentTool = null;
                if (e.button != 2)
                {
                    flag = 999;
                    return;
                }
                IPoint point = new PointClass();
                point = mainMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
                //设置文本格式
                ITextSymbol textSymbol = new TextSymbolClass();
                StdFont     stdFont    = new stdole.StdFontClass();
                stdFont.Name           = "宋体";
                stdFont.Size           = 24;
                textSymbol.Font        = (IFontDisp)stdFont;
                textSymbol.Angle       = 0;
                textSymbol.RightToLeft = false;
                //垂直方向基线对齐
                textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline;
                //文本两端对齐
                textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;
                textSymbol.Text = C.Text;
                ITextElement textElement = new TextElementClass();
                textElement.Symbol = textSymbol;
                textElement.Text   = textSymbol.Text;
                //获取坐标,添加文本
                IElement element = (IElement)textElement;
                element.Geometry = point;
                mainMapControl.ActiveView.GraphicsContainer.AddElement(element, 0);
                mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, element, null);
            }

            if (flag == 66)
            {//画线
                IGeometry pGeom;
                pGeom = (IGeometry)mainMapControl.TrackLine();
                IGraphicsContainer pGraphicsContainer = mainMapControl.Map as IGraphicsContainer;
                baseOrder.AddLineElement(pGeom, pGraphicsContainer);
            }

            if (flag == 77)
            {//闪
                IMap                 pMap        = mainMapControl.Map;
                IActiveView          pActiveView = pMap as IActiveView;
                IPoint               pt          = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
                ITopologicalOperator pTopo       = pt as ITopologicalOperator;
                IGeometry            pGeo        = pTopo.Buffer(100);
                IColor               pColor      = new RgbColorClass();
                pColor.RGB = 2556;
                SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
                simpleFillSymbol.Color = pColor; ISymbol symbol = simpleFillSymbol as ISymbol;
                pActiveView.ScreenDisplay.SetSymbol(symbol);
                pActiveView.ScreenDisplay.DrawPolygon(pGeo);
                pMap.SelectByShape(pGeo, null, false);
                mainMapControl.FlashShape(pGeo, 25, 200, symbol);
                mainMapControl.ActiveView.Refresh();
            }
        }
Ejemplo n.º 17
0
        private void ConvertAnnotation(IMap map, ILayer featureLayer, string annotationFeatureClassName, double scale,
                                       IWorkspace workspace, ILineLabelPosition lineLabelPosition,
                                       IPointPlacementPriorities pointPlacementPriorities,
                                       esriBasicOverposterWeight labelWeight, esriBasicOverposterWeight featureWeight, bool tagUnplaced,
                                       string fontName, double fontSize, IRgbColor rgbColor, string expression, bool featureLinked,
                                       esriLabelWhichFeatures labelWhichFeatures)
        {
            if (workspace.Type != esriWorkspaceType.esriFileSystemWorkspace && featureLayer is IGeoFeatureLayer)
            {
                IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
                IAnnotateLayerPropertiesCollection annotateLayerPropertiesCollectionClass =
                    geoFeatureLayer.AnnotationProperties;
                annotateLayerPropertiesCollectionClass.Clear();
                ILabelEngineLayerProperties     labelEngineLayerProperties     = new LabelEngineLayerPropertiesClass();
                IBasicOverposterLayerProperties basicOverposterLayerProperties =
                    new BasicOverposterLayerPropertiesClass();
                if (lineLabelPosition != null)
                {
                    basicOverposterLayerProperties.LineLabelPosition = lineLabelPosition;
                }
                else if (pointPlacementPriorities != null)
                {
                    basicOverposterLayerProperties.PointPlacementPriorities = pointPlacementPriorities;
                }
                basicOverposterLayerProperties.LabelWeight   = labelWeight;
                basicOverposterLayerProperties.FeatureWeight = featureWeight;

                IOverposterLayerProperties2 overposterLayerProperties2 =
                    basicOverposterLayerProperties as IOverposterLayerProperties2;
                overposterLayerProperties2.TagUnplaced = tagUnplaced;

                labelEngineLayerProperties.BasicOverposterLayerProperties = basicOverposterLayerProperties;
                stdole.IFontDisp pFont = new stdole.StdFontClass() as stdole.IFontDisp;
                pFont.Name = fontName;
                ITextSymbol pTextSymbol = new TextSymbolClass();
                pTextSymbol.Size  = fontSize;
                pTextSymbol.Font  = pFont;
                pTextSymbol.Color = rgbColor;
                labelEngineLayerProperties.Symbol     = pTextSymbol;
                labelEngineLayerProperties.Expression = expression;

                IAnnotateLayerProperties annotateLayerProperties =
                    labelEngineLayerProperties as IAnnotateLayerProperties;
                annotateLayerProperties.DisplayAnnotation = true;

                IAnnotationLayer annotationLayer =
                    CommonHelper.GetLayerByFeatureClassName(_context.FocusMap, annotationFeatureClassName) as
                    IAnnotationLayer;
                CommonHelper.SetReferenceScale(annotationLayer, scale);
                annotateLayerProperties.FeatureLayer      = geoFeatureLayer;
                annotateLayerProperties.GraphicsContainer = annotationLayer as IGraphicsContainer;
                annotateLayerProperties.AddUnplacedToGraphicsContainer = true;
                annotateLayerProperties.CreateUnplacedElements         = true;
                annotateLayerProperties.DisplayAnnotation  = true;
                annotateLayerProperties.FeatureLinked      = featureLinked;
                annotateLayerProperties.LabelWhichFeatures = labelWhichFeatures;
                annotateLayerProperties.UseOutput          = true;
                annotateLayerPropertiesCollectionClass.Add(annotateLayerProperties);

                annotateLayerPropertiesCollectionClass.Sort();
                IAnnotateMapProperties annotateMapPropertiesClass = new AnnotateMapPropertiesClass()
                {
                    AnnotateLayerPropertiesCollection = annotateLayerPropertiesCollectionClass
                };
                ITrackCancel          cancelTrackerClass   = new CancelTrackerClass();
                IAnnotateMap2         annotateMap2         = map.AnnotationEngine as IAnnotateMap2;
                IOverposterProperties overposterProperties = (map as IMapOverposter).OverposterProperties;
                annotateMap2.Label(overposterProperties, annotateMapPropertiesClass, map, cancelTrackerClass);
                map.AddLayer(annotationLayer as ILayer);
                geoFeatureLayer.DisplayAnnotation = false;
                map.ReferenceScale = scale;
                map.MapScale       = scale;
                IActiveView activeView = map as IActiveView;
                activeView.Refresh();
            }
        }