/// <summary>
        /// 创建标注
        /// </summary>
        /// <param name="feaName"></param>
        /// <param name="featureDataset"></param>
        /// <param name="feaworkspace"></param>
        /// <param name="fsEditAnno"></param>
        /// <param name="intScale"></param>
        public void createAnnoFeatureClass(string feaName, IFeatureDataset featureDataset, IFeatureWorkspace feaworkspace, IFieldsEdit fsEditAnno, int intScale)
        {
            //创建注记的特殊字段
            try
            {
                //注记的workSpace
                IFeatureWorkspaceAnno pFWSAnno = feaworkspace as IFeatureWorkspaceAnno; //标注操作空间

                IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass();               //图形比例接口
                pGLS.Units          = esriUnits.esriMeters;                             //图形比例设定
                pGLS.ReferenceScale = Convert.ToDouble(intScale);                       //创建注记必须要设置比例尺

                IFormattedTextSymbol myTextSymbol = new TextSymbolClass();              //文本格式接口
                ISymbol pSymbol = (ISymbol)myTextSymbol;                                //标记
                //Anno要素类必须有的缺省符号
                ISymbolCollection2 pSymbolColl = new SymbolCollectionClass();
                ISymbolIdentifier2 pSymID      = new SymbolIdentifierClass();
                pSymbolColl.AddSymbol(pSymbol, "Default", out pSymID);

                //Anno要素类的必要属性
                IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();
                pAnnoProps.CreateUnplacedElements = true;
                pAnnoProps.CreateUnplacedElements = true;
                pAnnoProps.DisplayAnnotation      = true;
                pAnnoProps.UseOutput = true;

                ILabelEngineLayerProperties pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps;
                pLELayerProps.Symbol             = pSymbol as ITextSymbol;
                pLELayerProps.SymbolID           = 0;
                pLELayerProps.IsExpressionSimple = true;
                pLELayerProps.Offset             = 0;
                pLELayerProps.SymbolID           = 0;

                IAnnotationExpressionEngine aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();
                pLELayerProps.ExpressionParser = aAnnoVBScriptEngine;
                pLELayerProps.Expression       = "[DESCRIPTION]";
                IAnnotateLayerTransformationProperties pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
                pATP.ReferenceScale = pGLS.ReferenceScale;
                pATP.ScaleRatio     = 1;

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

                IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescription();
                IFields fields = pOCDesc.RequiredFields;
                IFeatureClassDescription pFDesc = pOCDesc as IFeatureClassDescription;

                for (int j = 0; j < pOCDesc.RequiredFields.FieldCount; j++)
                {
                    fsEditAnno.AddField(pOCDesc.RequiredFields.get_Field(j));
                }
                fields = fsEditAnno as IFields;
                pFWSAnno.CreateAnnotationClass(feaName, fields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, pFDesc.ShapeFieldName, "", featureDataset, null, pAnnoPropsColl, pGLS, pSymbolColl, true);
            }
            catch
            {
            }
        }
Exemple #2
0
        public void CreateAnnoFeatureClass(IFeatureDataset featureDs, string strObjNum)
        {
            //更换注记字体 用两个重要的属性
            //IAnnotateLayerPropertiesCollection,ISymbolCollection
            IFeatureWorkspace pFeatureWs = pAccessWorkSpace;

            IFeatureWorkspaceAnno pFeatureWorkspaceAnno;

            pFeatureWorkspaceAnno = (IFeatureWorkspaceAnno)pFeatureWs;

            //说明:要控制图层中的字体必须在图层建立的时候定义好字体
            ITextSymbol pTextSymbol, tTextSymbol;

            pTextSymbol = PublicFun.makeTextSymbol("Arial", 16);
            tTextSymbol = PublicFun.makeTextSymbol("宋体", 50);
            /////textsymbol

            IGraphicsLayerScale pGLS;

            pGLS                = new GraphicsLayerScaleClass();
            pGLS.Units          = esriUnits.esriMeters;
            pGLS.ReferenceScale = 500;

            IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();

            pAnnoProps.FeatureLinked = true;
            pAnnoProps.AddUnplacedToGraphicsContainer = false;
            pAnnoProps.CreateUnplacedElements         = false;
            pAnnoProps.DisplayAnnotation = true;
            pAnnoProps.UseOutput         = true;

            IAnnotationExpressionEngine aAnnoVBScriptEngine;

            aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();

            ILabelEngineLayerProperties pLELayerProps;

            pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps;
            pLELayerProps.ExpressionParser = aAnnoVBScriptEngine;
            pLELayerProps.Expression       = "[DESCRIPTION]";

            pLELayerProps.IsExpressionSimple = true;
            pLELayerProps.Offset             = 0;
            pLELayerProps.SymbolID           = 0;
            pLELayerProps.Symbol             = pTextSymbol;

            IAnnotateLayerTransformationProperties pATP;

            pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
            pATP.ReferenceScale = pGLS.ReferenceScale;
            pATP.Units          = esriUnits.esriMeters;
            pATP.ScaleRatio     = 300;

            IAnnotateLayerPropertiesCollection pAnnoPropsColl;

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

            IObjectClassDescription pOCDesc;

            pOCDesc = new AnnotationFeatureClassDescriptionClass();

            IFeatureClassDescription pFDesc;

            pFDesc = (IFeatureClassDescription)pOCDesc;

            ISymbolCollection pSymbolColl;

            pSymbolColl = new SymbolCollectionClass();
            pSymbolColl.set_Symbol(0, (ISymbol)pTextSymbol);
            pSymbolColl.set_Symbol(2, (ISymbol)tTextSymbol);

            IFields pFields = pOCDesc.RequiredFields;

            //添加注记类的附加字段
            this.addAnnoField(ref pFields, strObjNum);

            string          featureName = TableName;                    //注记要素集的名字
            IFeatureDataset pFeatureDataset;

            if (featureDs == null)
            {
                pFeatureDataset = pFeatureWs.CreateFeatureDataset(featureName + "_Anno", sPR);
            }
            else
            {
                pFeatureDataset = featureDs;
            }

            pFeatureWorkspaceAnno.CreateAnnotationClass(featureName, pFields, pOCDesc.InstanceCLSID,
                                                        pOCDesc.ClassExtensionCLSID, pFDesc.ShapeFieldName, "",
                                                        pFeatureDataset, null, pAnnoPropsColl, pGLS, pSymbolColl, true);
        }
Exemple #3
0
        private IFeatureClass CreateFeatureClass(IFeatureDataset featureDataset,TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode) 
        {
            try
            {
                if (featureDataset != null)
                {
                    IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                    IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
         
                    ///创建数据表字段
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IEnumFieldError enumFieldError = null;
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///字段信息验证
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = featureDataset.Workspace;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ////创建FeatureClass
                    IFeatureClass featureClass = null;
                    if (tableStructureNode.IsGeometryTable)
                    {
                        ////创建非注记FeatureClass
                        if (featureCodeNode.GeometryType != "")
                        {
                            featureClass = featureDataset.CreateFeatureClass(featureCodeNode.TableName,
                               fixFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID,
                               esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");
                        }
                        else
                        {
                            ///创建注记
                            IFormattedTextSymbol pTxtSymbo=new TextSymbolClass();

                            IFeatureWorkspaceAnno pFeatureWorkspaceAnno = this.m_pIDataset.Workspace as IFeatureWorkspaceAnno;

                            IGraphicsLayerScale pGraphSacle = new GraphicsLayerScaleClass();
                            pGraphSacle.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            //pGraphSacle.ReferenceScale=1000;


                            ISymbolCollection pSymbolCollection = new SymbolCollectionClass();

                            IAnnotateLayerProperties pAnnoLayerProp = new LabelEngineLayerPropertiesClass();
                            pAnnoLayerProp.FeatureLinked = true;
                            pAnnoLayerProp.CreateUnplacedElements = false;
                            pAnnoLayerProp.DisplayAnnotation = true;
                            pAnnoLayerProp.UseOutput = true;

                            IAnnotationExpressionEngine pAnnoExpressionEngine =new AnnotationVBScriptEngineClass();
                            ILabelEngineLayerProperties pLabelEngineLayerProperties = pAnnoLayerProp as ILabelEngineLayerProperties;
                            pLabelEngineLayerProperties.ExpressionParser = pAnnoExpressionEngine;
                            pLabelEngineLayerProperties.Expression = "[DESCRIPTION]";
                            pLabelEngineLayerProperties.IsExpressionSimple = true;
                            pLabelEngineLayerProperties.Offset = 0;
                            pLabelEngineLayerProperties.SymbolID = 0;
                            pLabelEngineLayerProperties.Symbol = pTxtSymbo;

                            IAnnotateLayerTransformationProperties pAnnoLayerTransProp = pAnnoLayerProp as IAnnotateLayerTransformationProperties;
                            pAnnoLayerTransProp.ReferenceScale=200;
                            pAnnoLayerTransProp.Units= ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            pAnnoLayerTransProp.ScaleRatio=1;

                            IAnnotateLayerPropertiesCollection pAnnoLayerProptyCollection =new AnnotateLayerPropertiesCollectionClass();
                           pAnnoLayerProptyCollection.Add(pAnnoLayerProp);

                           featureClass= pFeatureWorkspaceAnno.CreateAnnotationClass(featureCodeNode.TableName,fixFields,ocDesc.InstanceCLSID
                               ,ocDesc.ClassExtensionCLSID,fcDesc.ShapeFieldName,"",featureDataset,null,
                               pAnnoLayerProptyCollection, pGraphSacle, pSymbolCollection,true);
                        }
                    }
                    else
                    {
                        ///创建非空间数据
                    }
                    return featureClass;
                }
                return null;
            }
            catch(Exception ex)
            {
                Logger.WriteErrorLog(ex);
                return null;
            }
        }
Exemple #4
0
        /// <summary>
        /// 从图层对应节点的XML中读取当前层的标注设置
        /// </summary>
        /// <param name="pAnnoLayerProper"></param>
        public static void ReadLabelConfigFromXML(ref IAnnotateLayerProperties pAnnoLayerProper, XmlNode nodeLayerXml, string pFeatureType)
        {
            //设置标注的相关信息             ;
            ILabelEngineLayerProperties pLabelEngineLayerProperties = null;

            if (pAnnoLayerProper == null)
            {
                pLabelEngineLayerProperties = new LabelEngineLayerProperties() as ILabelEngineLayerProperties;
                pAnnoLayerProper            = pLabelEngineLayerProperties as IAnnotateLayerProperties;
            }
            else
            {
                pLabelEngineLayerProperties = pAnnoLayerProper as ILabelEngineLayerProperties;
            }

            IAnnotationExpressionEngine pAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();

            pLabelEngineLayerProperties.ExpressionParser = pAnnoVBScriptEngine;

            IBasicOverposterLayerProperties4 pBasicOverposterLayerProperties = pLabelEngineLayerProperties.BasicOverposterLayerProperties as IBasicOverposterLayerProperties4;

            switch (pFeatureType)
            {
            case "esriGeometryPoint":
                pBasicOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
                break;

            case "esriGeometryPolyline":
                pBasicOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
                break;

            case "esriGeometryPolygon":
                pBasicOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
                break;
            }

            ITextSymbol pTextSymbol = pLabelEngineLayerProperties.Symbol;
            IFontDisp   pFont       = pTextSymbol.Font;

            foreach (XmlNode nd in nodeLayerXml)
            {
                if (nd.Name == "AttrLabel")
                {
                    //读取共同的标注设置信息
                    pFont.Name = nd.Attributes["FontName"].Value;
                    pFont.Size = Convert.ToDecimal(nd.Attributes["FontSize"].Value.ToLower());
                    if (nd.Attributes["FontBold"].Value != "")
                    {
                        pFont.Bold = Convert.ToBoolean(nd.Attributes["FontBold"].Value.ToLower());
                    }
                    if (nd.Attributes["FontItalic"].Value != "")
                    {
                        pFont.Italic = Convert.ToBoolean(nd.Attributes["FontItalic"].Value.ToLower());
                    }
                    if (nd.Attributes["FontUnderLine"].Value != "")
                    {
                        pFont.Underline = Convert.ToBoolean(nd.Attributes["FontUnderLine"].Value.ToLower());
                    }
                    pTextSymbol.Font = pFont;
                    IColor pColor = new RgbColorClass();
                    if (nd.Attributes["FontBoldColor"].Value != "")
                    {
                        pColor.RGB = Convert.ToInt32(nd.Attributes["FontBoldColor"].Value);
                    }
                    else
                    {
                        pColor.RGB = 36054566;
                        //pColor.Green = 0;
                        //pColor.Blue = 0;
                        pTextSymbol.Color = pColor as IColor;
                    }
                    pTextSymbol.Color = pColor;


                    if (nd.Attributes["Expression"].Value != "")
                    {
                        pLabelEngineLayerProperties.Expression = "[" + nd.Attributes["Expression"].Value + "]";
                    }

                    if (nd.Attributes["MaxScale"].Value != "" && nd.Attributes["MaxScale"].Value != null)
                    {
                        pAnnoLayerProper.AnnotationMaximumScale = Convert.ToDouble(nd.Attributes["MaxScale"].Value);
                    }
                    if (nd.Attributes["MinScale"].Value != "" && nd.Attributes["MinScale"].Value != null)
                    {
                        pAnnoLayerProper.AnnotationMinimumScale = Convert.ToDouble(nd.Attributes["MinScale"].Value);
                    }

                    if (nd.Attributes["NumLabelsOption"].Value == "esriOneLabelPerName")
                    {
                        pBasicOverposterLayerProperties.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerName;
                    }
                    else if (nd.Attributes["NumLabelsOption"].Value == "esriOneLabelPerPart")
                    {
                        pBasicOverposterLayerProperties.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerPart;
                    }
                    else if (nd.Attributes["NumLabelsOption"].Value == "esriOneLabelPerShape")
                    {
                        pBasicOverposterLayerProperties.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape;
                    }
                    //下面按不同要素类型读取不同的标注设置信息
                    //点要素
                    if (pBasicOverposterLayerProperties.FeatureType == esriBasicOverposterFeatureType.esriOverposterPoint)
                    {
                        pBasicOverposterLayerProperties.PointPlacementOnTop = Convert.ToBoolean(nd.Attributes["PointPlacementOnTop"].Value.ToLower());
                        if (nd.Attributes["PointPlacementMethod"].Value == "esriAroundPoint")
                        {
                            pBasicOverposterLayerProperties.PointPlacementMethod = esriOverposterPointPlacementMethod.esriAroundPoint;

                            IPointPlacementPriorities pPointPlacementPriorities = pBasicOverposterLayerProperties.PointPlacementPriorities;
                            string strPlacement;
                            try
                            {
                                //读取标注位置的设置
                                strPlacement = nd.Attributes["PointPlacementPriorities"].Value;
                                SetPlacementPriotities(pPointPlacementPriorities, strPlacement);
                                pBasicOverposterLayerProperties.PointPlacementPriorities = pPointPlacementPriorities;
                            }
                            catch
                            {
                                //MessageBox.Show("该图层XML中不存在PointPlacementPriorities属性!");
                            }
                        }
                        else if (nd.Attributes["PointPlacementMethod"].Value == "esriOnTopPoint")
                        {
                            pBasicOverposterLayerProperties.PointPlacementMethod = esriOverposterPointPlacementMethod.esriOnTopPoint;
                        }
                        else if (nd.Attributes["PointPlacementMethod"].Value == "esriSpecifiedAngles")
                        {
                            double[] dArray = new double[1];
                            string   sAngle = nd.Attributes["PointPlacementAngles"].Value;
                            if (sAngle.Contains(",") == false)
                            {
                                dArray[0] = Convert.ToDouble(sAngle);
                            }
                            else
                            {
                                string[] sAngles = sAngle.Split(new char[] { ',' });
                                dArray = new double[sAngles.Length];
                                for (int i = 0; i < sAngles.Length; i++)
                                {
                                    dArray[i] = Convert.ToDouble(sAngles[i]);
                                }
                            }
                            pBasicOverposterLayerProperties.PointPlacementAngles = dArray;
                        }
                        else if (nd.Attributes["PointPlacementMethod"].Value == "esriRotationField")
                        {
                            pBasicOverposterLayerProperties.PointPlacementMethod = esriOverposterPointPlacementMethod.esriRotationField;
                            pBasicOverposterLayerProperties.RotationField        = nd.Attributes["RotationField"].Value;
                            if (nd.Attributes["RotationType"].Value == "esriRotateLabelArithmetic")
                            {
                                pBasicOverposterLayerProperties.RotationType = esriLabelRotationType.esriRotateLabelArithmetic;
                            }
                            else if (nd.Attributes["RotationType"].Value == "esriRotateLabelGeographic")
                            {
                                pBasicOverposterLayerProperties.RotationType = esriLabelRotationType.esriRotateLabelGeographic;
                            }

                            pBasicOverposterLayerProperties.PerpendicularToAngle = Convert.ToBoolean(nd.Attributes["PerpendicularToAngle"].Value);
                        }
                    }
                    //线要素
                    else if (pBasicOverposterLayerProperties.FeatureType == esriBasicOverposterFeatureType.esriOverposterPolyline)
                    {
                        ILineLabelPosition pLineLabelPosition = pBasicOverposterLayerProperties.LineLabelPosition;
                        if (nd.Attributes["Above"] != null)
                        {
                            pLineLabelPosition.Above = Convert.ToBoolean(nd.Attributes["Above"].Value);
                        }
                        if (nd.Attributes["AtEnd"] != null)
                        {
                            pLineLabelPosition.AtEnd = Convert.ToBoolean(nd.Attributes["AtEnd"].Value);
                        }
                        if (nd.Attributes["AtStart"] != null)
                        {
                            pLineLabelPosition.AtStart = Convert.ToBoolean(nd.Attributes["AtStart"].Value);
                        }
                        if (nd.Attributes["Below"] != null)
                        {
                            pLineLabelPosition.Below = Convert.ToBoolean(nd.Attributes["Below"].Value);
                        }
                        if (nd.Attributes["Horizontal"] != null)
                        {
                            pLineLabelPosition.Horizontal = Convert.ToBoolean(nd.Attributes["Horizontal"].Value);
                        }
                        if (nd.Attributes["InLine"] != null)
                        {
                            pLineLabelPosition.InLine = Convert.ToBoolean(nd.Attributes["InLine"].Value);
                        }
                        if (nd.Attributes["Left"] != null)
                        {
                            pLineLabelPosition.Left = Convert.ToBoolean(nd.Attributes["Left"].Value);
                        }
                        if (nd.Attributes["Offset"] != null)
                        {
                            pLineLabelPosition.Offset = Convert.ToDouble(nd.Attributes["Offset"].Value);
                        }
                        if (nd.Attributes["OnTop"] != null)
                        {
                            pLineLabelPosition.OnTop = Convert.ToBoolean(nd.Attributes["OnTop"].Value);
                        }
                        if (nd.Attributes["Parallel"] != null)
                        {
                            pLineLabelPosition.Parallel = Convert.ToBoolean(nd.Attributes["Parallel"].Value);
                        }
                        if (nd.Attributes["Perpendicular"] != null)
                        {
                            pLineLabelPosition.Perpendicular = Convert.ToBoolean(nd.Attributes["Perpendicular"].Value);
                        }
                        if (nd.Attributes["ProduceCurvedLabels"] != null)
                        {
                            pLineLabelPosition.ProduceCurvedLabels = Convert.ToBoolean(nd.Attributes["ProduceCurvedLabels"].Value);
                        }
                        if (nd.Attributes["Right"] != null)
                        {
                            pLineLabelPosition.Right = Convert.ToBoolean(nd.Attributes["Right"].Value);
                        }
                    }
                    //面要素
                    else if (pBasicOverposterLayerProperties.FeatureType == esriBasicOverposterFeatureType.esriOverposterPolygon)
                    {
                        if (nd.Attributes["PolygonPlacementMethod"].Value == "esriAlwaysHorizontal")
                        {
                            pBasicOverposterLayerProperties.PolygonPlacementMethod = esriOverposterPolygonPlacementMethod.esriAlwaysHorizontal;
                        }
                        else if (nd.Attributes["PolygonPlacementMethod"].Value == "esriAlwaysStraight")
                        {
                            pBasicOverposterLayerProperties.PolygonPlacementMethod = esriOverposterPolygonPlacementMethod.esriAlwaysStraight;
                        }
                        else if (nd.Attributes["PolygonPlacementMethod"].Value == "esriMixedStrategy")
                        {
                            pBasicOverposterLayerProperties.PolygonPlacementMethod = esriOverposterPolygonPlacementMethod.esriMixedStrategy;
                        }

                        pBasicOverposterLayerProperties.PlaceOnlyInsidePolygon = Convert.ToBoolean(nd.Attributes["PlaceOnlyInsidePolygon"].Value);
                    }
                }
            }
        }
Exemple #5
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);
        }
Exemple #6
0
        //应用所有设置的标注的属性
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (cmbFieldName.Text.Trim() == "")
                {
                    return;
                }

                //设置显示的参考比例尺
                if (optUserDefined.Checked)
                {
                    m_pAnnoLayerProperties.AnnotationMaximumScale = Conversion.Val(txtMaxScale.Text);
                    m_pAnnoLayerProperties.AnnotationMinimumScale = Conversion.Val(txtMinScale.Text);
                }
                else if (optScaleNameWithLayer.Checked)
                {
                    m_pAnnoLayerProperties.AnnotationMaximumScale = m_pGeoFeatLayer.MaximumScale;
                    m_pAnnoLayerProperties.AnnotationMinimumScale = m_pGeoFeatLayer.MinimumScale;
                }

                ILabelEngineLayerProperties pLabelEngine;
                //获得解析表达式的解析器
                IAnnotationExpressionEngine pAnnoVBScriptEngine;
                pAnnoVBScriptEngine           = new AnnotationVBScriptEngineClass();
                pLabelEngine                  = (ILabelEngineLayerProperties)m_pAnnoLayerProperties;
                pLabelEngine.ExpressionParser = pAnnoVBScriptEngine;

                //设置显示的表达式
                string   sDisplayFieldName;
                string[] vFieldNameArray;

                if (cmbFieldName.Text.Contains("复杂表达式"))
                {
                    pLabelEngine.Expression = m_pNewLabelEngineLayerProperties.Expression;
                }
                else
                {
                    vFieldNameArray         = cmbFieldName.Text.Split(new char[] { '[' });
                    sDisplayFieldName       = vFieldNameArray[0];
                    pLabelEngine.Expression = "[" + sDisplayFieldName + "]";
                }

                //设置字体
                IFontDisp pFontDisp;
                pFontDisp           = m_pTextSymbol.Font;
                pFontDisp.Name      = lblText.Font.Name;
                pFontDisp.Size      = (decimal)lblText.Font.Size;
                pFontDisp.Bold      = lblText.Font.Bold;
                pFontDisp.Italic    = lblText.Font.Italic;
                pFontDisp.Underline = lblText.Font.Underline;

                m_pTextSymbol.Font = pFontDisp;

                //设置颜色
                IRgbColor pRgbColor = new RgbColorClass();
                Color     pForeColor;
                pForeColor      = lblText.ForeColor;
                pRgbColor.Red   = pForeColor.R;
                pRgbColor.Green = pForeColor.G;
                pRgbColor.Blue  = pForeColor.B;

                m_pTextSymbol.Color = pRgbColor;

                //设置位置及其它属性
                if (m_pNewBasicOverposterLayerProperties != null)
                {
                    pLabelEngine.BasicOverposterLayerProperties = (IBasicOverposterLayerProperties)m_pNewBasicOverposterLayerProperties;
                }

                //将属性设置写入XML
                m_XMLElement = WriteLabelInfoToXML(m_pAnnoLayerProperties);

                IActiveView pActiveView;
                //pActiveView = (IActiveView)ModDeclare.g_Sys.MapControl.Map;
                pActiveView = (IActiveView)m_pMapControl.Map;
                pActiveView.Refresh();

                m_bOK = true;
                this.Close();
            }
            catch (Exception)
            {
                //ModDeclare.g_ErrorHandler.DisplayInformation("在显示设置标注时候发生错误,请检查标注表达式!", false, null, "退出");
                MessageBox.Show("在显示设置标注时候发生错误,请检查标注表达式!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            }
        }
Exemple #7
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;
        }
        private IFeatureClass CreateFeatureClass(IFeatureDataset featureDataset,TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode)
        {
            try
            {
                if (featureDataset != null)
                {
                    IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                    IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;

                    ///�������ݱ��ֶ�
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IEnumFieldError enumFieldError = null;
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///�ֶ���Ϣ��֤
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = featureDataset.Workspace;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ////����FeatureClass
                    IFeatureClass featureClass = null;
                    if (tableStructureNode.IsGeometryTable)
                    {
                        ////������ע��FeatureClass
                        if (featureCodeNode.GeometryType != "")
                        {
                            featureClass = featureDataset.CreateFeatureClass(featureCodeNode.TableName,
                               fixFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID,
                               esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");
                        }
                        else
                        {
                            ///����ע��
                            IFormattedTextSymbol pTxtSymbo=new TextSymbolClass();

                            IFeatureWorkspaceAnno pFeatureWorkspaceAnno = this.m_pIDataset.Workspace as IFeatureWorkspaceAnno;

                            IGraphicsLayerScale pGraphSacle = new GraphicsLayerScaleClass();
                            pGraphSacle.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            //pGraphSacle.ReferenceScale=1000;

                            ISymbolCollection pSymbolCollection = new SymbolCollectionClass();

                            IAnnotateLayerProperties pAnnoLayerProp = new LabelEngineLayerPropertiesClass();
                            pAnnoLayerProp.FeatureLinked = true;
                            pAnnoLayerProp.CreateUnplacedElements = false;
                            pAnnoLayerProp.DisplayAnnotation = true;
                            pAnnoLayerProp.UseOutput = true;

                            IAnnotationExpressionEngine pAnnoExpressionEngine =new AnnotationVBScriptEngineClass();
                            ILabelEngineLayerProperties pLabelEngineLayerProperties = pAnnoLayerProp as ILabelEngineLayerProperties;
                            pLabelEngineLayerProperties.ExpressionParser = pAnnoExpressionEngine;
                            pLabelEngineLayerProperties.Expression = "[DESCRIPTION]";
                            pLabelEngineLayerProperties.IsExpressionSimple = true;
                            pLabelEngineLayerProperties.Offset = 0;
                            pLabelEngineLayerProperties.SymbolID = 0;
                            pLabelEngineLayerProperties.Symbol = pTxtSymbo;

                            IAnnotateLayerTransformationProperties pAnnoLayerTransProp = pAnnoLayerProp as IAnnotateLayerTransformationProperties;
                            pAnnoLayerTransProp.ReferenceScale=200;
                            pAnnoLayerTransProp.Units= ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            pAnnoLayerTransProp.ScaleRatio=1;

                            IAnnotateLayerPropertiesCollection pAnnoLayerProptyCollection =new AnnotateLayerPropertiesCollectionClass();
                           pAnnoLayerProptyCollection.Add(pAnnoLayerProp);

                           featureClass= pFeatureWorkspaceAnno.CreateAnnotationClass(featureCodeNode.TableName,fixFields,ocDesc.InstanceCLSID
                               ,ocDesc.ClassExtensionCLSID,fcDesc.ShapeFieldName,"",featureDataset,null,
                               pAnnoLayerProptyCollection, pGraphSacle, pSymbolCollection,true);
                        }
                    }
                    else
                    {
                        ///�����ǿռ�����
                    }
                    return featureClass;
                }
                return null;
            }
            catch(Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
        }