Ejemplo n.º 1
0
        /// <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
            {
            }
        }
Ejemplo n.º 2
0
        private IFeatureClass method_1(IFeatureWorkspace ifeatureWorkspace_0, string string_4, double double_0,
                                       ITextSymbol itextSymbol_0, IFields ifields_0)
        {
            IObjectClassDescription  description  = new AnnotationFeatureClassDescriptionClass();
            IFeatureClassDescription description2 = description as IFeatureClassDescription;
            IClone     requiredFields             = description.RequiredFields as IClone;
            IFields    fields = requiredFields.Clone() as IFields;
            IFieldEdit edit   = null;
            int        index  = fields.FindField(description2.ShapeFieldName);

            edit = fields.get_Field(index) as IFieldEdit;
            IGeometryDefEdit      geometryDef    = edit.GeometryDef as IGeometryDefEdit;
            IFeatureWorkspaceAnno anno           = ifeatureWorkspace_0 as IFeatureWorkspaceAnno;
            IGraphicsLayerScale   referenceScale = new GraphicsLayerScaleClass
            {
                ReferenceScale = double_0,
                Units          = esriUnits.esriMeters
            };
            UID instanceCLSID                  = description.InstanceCLSID;
            UID classExtensionCLSID            = description.ClassExtensionCLSID;
            ISymbolCollection symbolCollection = new SymbolCollectionClass();

            symbolCollection.set_Symbol(0, itextSymbol_0 as ISymbol);
            IAnnotateLayerPropertiesCollection2 annoProperties = new AnnotateLayerPropertiesCollectionClass();
            IAnnotateLayerProperties            item           = new LabelEngineLayerPropertiesClass
            {
                Class         = "要素类 1",
                FeatureLinked = false,
                AddUnplacedToGraphicsContainer = false,
                CreateUnplacedElements         = true,
                DisplayAnnotation = true,
                UseOutput         = true
            };
            ILabelEngineLayerProperties properties2 = item as ILabelEngineLayerProperties;

            properties2.Offset   = 0.0;
            properties2.SymbolID = 0;
            properties2.Symbol   = itextSymbol_0;
            annoProperties.Add(item);
            for (int i = 0; i < ifields_0.FieldCount; i++)
            {
                if (fields.FindField(ifields_0.get_Field(i).Name) == -1)
                {
                    (fields as IFieldsEdit).AddField(ifields_0.get_Field(i));
                }
            }
            try
            {
                return(anno.CreateAnnotationClass(string_4, fields, instanceCLSID, classExtensionCLSID,
                                                  description2.ShapeFieldName, "", null, null, annoProperties, referenceScale, symbolCollection, false));
            }
            catch (Exception exception)
            {
                Logger.Current.Error("", exception, "");
            }
            return(null);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public void showAnnotationByScale()
 {
     IMap pMap = axMapControl.Map;
     IFeatureLayer pFeaturelayer = pMap.get_Layer(0) as IFeatureLayer;
     IGeoFeatureLayer pGeoFeatureLayer = pFeaturelayer as IGeoFeatureLayer;
     //创建标注集接口,可以对标注进行添加、删除、查询、排序等操作
     IAnnotateLayerPropertiesCollection pAnnotateLayerPropertiesCollection = new AnnotateLayerPropertiesCollectionClass();
     pAnnotateLayerPropertiesCollection = pGeoFeatureLayer.AnnotationProperties;
     pAnnotateLayerPropertiesCollection.Clear();
     //创建标注的颜色
     IRgbColor pRgbColor = new RgbColorClass();
     pRgbColor.Red = 255;
     pRgbColor.Green = 0;
     pRgbColor.Blue = 0;
     //创建标注的字体样式
     ITextSymbol pTextSymbol = new TextSymbolClass();
     pTextSymbol.Color = pRgbColor;
     pTextSymbol.Size = 12;
     pTextSymbol.Font.Name = "宋体";
     //定义 ILineLabelPosition接口,用来管理line features的标注属性,指定标注和线要素的位置关系
     ILineLabelPosition pLineLabelPosition = new LineLabelPositionClass();
     pLineLabelPosition.Parallel = false;
     pLineLabelPosition.Perpendicular = true;
     pLineLabelPosition.InLine = true;
     //定义 ILineLabelPlacementPriorities接口用来控制标注冲突
     ILineLabelPlacementPriorities pLineLabelPlacementPriorities = new LineLabelPlacementPrioritiesClass();
     pLineLabelPlacementPriorities.AboveStart = 5;
     pLineLabelPlacementPriorities.BelowAfter = 4;
     //定义 IBasicOverposterLayerProperties 接口实现 LineLabelPosition 和 LineLabelPlacementPriorities对象的控制
     IBasicOverposterLayerProperties pBasicOverposterLayerProperties = new BasicOverposterLayerPropertiesClass();
     pBasicOverposterLayerProperties.LineLabelPlacementPriorities = pLineLabelPlacementPriorities;
     pBasicOverposterLayerProperties.LineLabelPosition = pLineLabelPosition;
     pBasicOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
     //创建标注对象
     ILabelEngineLayerProperties pLabelEngineLayerProperties = new LabelEngineLayerPropertiesClass();
     //设置标注符号
     pLabelEngineLayerProperties.Symbol = pTextSymbol;
     pLabelEngineLayerProperties.BasicOverposterLayerProperties = pBasicOverposterLayerProperties;
     //声明标注的Expression是否为Simple
     pLabelEngineLayerProperties.IsExpressionSimple = true;
     //设置标注字段
     pLabelEngineLayerProperties.Expression = "[DIQU]";
     //定义IAnnotateLayerTransformationProperties 接口用来控制feature layer的display of dynamic labels
     IAnnotateLayerTransformationProperties pAnnotateLayerTransformationProperties = pLabelEngineLayerProperties as IAnnotateLayerTransformationProperties;
     //设置标注参考比例尺
     pAnnotateLayerTransformationProperties.ReferenceScale = 500000;
     //定义IAnnotateLayerProperties接口,决定FeatureLayer动态标注信息
     IAnnotateLayerProperties pAnnotateLayerProperties = pLabelEngineLayerProperties as IAnnotateLayerProperties;
     //设置显示标注最大比例尺
     pAnnotateLayerProperties.AnnotationMaximumScale = 500000;
     //设置显示标注的最小比例
     pAnnotateLayerProperties.AnnotationMinimumScale = 25000000;
     //决定要标注的要素
     pAnnotateLayerProperties.WhereClause = "DIQU<>'宿州市'";
     //将创建好的标注对象添加到标注集对象中
     pAnnotateLayerPropertiesCollection.Add(pAnnotateLayerProperties);
     //声明标注是否显示
     pGeoFeatureLayer.DisplayAnnotation = true;
     //刷新视图
     this.axMapControl.Refresh();
 }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
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.º 7
0
        public IFeatureClass CreateStandardAnnotationClass(
            IFeatureWorkspace featureWorkspace,
            IFeatureDataset featureDataset,
            String className,
            ISpatialReference spatialReference,
            double referenceScale,
            esriUnits referenceScaleUnits,
            String configKeyword
            )
        {
            // Create an annotation class and provide it with a name.
            ILabelEngineLayerProperties labelEngineLayerProperties = new
                                                                     LabelEngineLayerPropertiesClass();
            IAnnotateLayerProperties annotateLayerProperties = (IAnnotateLayerProperties)
                                                               labelEngineLayerProperties;

            annotateLayerProperties.Class = className;

            // Get the symbol from the annotation class. Make any changes to its properties
            // here.
            ITextSymbol annotationTextSymbol = labelEngineLayerProperties.Symbol;
            ISymbol     annotationSymbol     = (ISymbol)annotationTextSymbol;

            // Create a symbol collection and add the default symbol from the
            // annotation class to the collection. Assign the resulting symbol ID
            // to the annotation class.
            ISymbolCollection  symbolCollection  = new SymbolCollectionClass();
            ISymbolCollection2 symbolCollection2 = (ISymbolCollection2)symbolCollection;
            ISymbolIdentifier2 symbolIdentifier2 = null;

            symbolCollection2.AddSymbol(annotationSymbol, className, out symbolIdentifier2);
            labelEngineLayerProperties.SymbolID = symbolIdentifier2.ID;

            // Add the annotation class to a collection.
            IAnnotateLayerPropertiesCollection annotateLayerPropsCollection = new
                                                                              AnnotateLayerPropertiesCollectionClass();

            annotateLayerPropsCollection.Add(annotateLayerProperties);

            // Create a graphics layer scale object.
            IGraphicsLayerScale graphicsLayerScale = new GraphicsLayerScaleClass();

            graphicsLayerScale.ReferenceScale = referenceScale;
            graphicsLayerScale.Units          = referenceScaleUnits;

            // Create the overposter properties for the standard label engine.
            IOverposterProperties overposterProperties = new BasicOverposterPropertiesClass()
            ;

            // Instantiate a class description object.
            //IObjectClassDescription ocDescription = new
            //    AnnotationFeatureClassDescriptionClass();
            //IFeatureClassDescription fcDescription = (IFeatureClassDescription)ocDescription;

            //// Get the shape field from the class description's required fields.
            //IFields requiredFields = ocDescription.RequiredFields;
            //int shapeFieldIndex = requiredFields.FindField(fcDescription.ShapeFieldName);
            //IField shapeField = requiredFields.get_Field(shapeFieldIndex);
            IFeatureLayer    layer           = (IFeatureLayer)mLayer;
            IFields          fields          = layer.FeatureClass.Fields;
            IField           shapeField      = fields.Field[fields.FindField(mField)];
            IGeometryDef     geometryDef     = shapeField.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.SpatialReference_2 = spatialReference;

            // Create the annotation layer factory.
            IAnnotationLayerFactory annotationLayerFactory = new
                                                             FDOGraphicsLayerFactoryClass();

            // Create the annotation feature class and an annotation layer for it.
            IAnnotationLayer annotationLayer = annotationLayerFactory.CreateAnnotationLayer
                                                   (featureWorkspace, featureDataset, className, geometryDef, null,
                                                   annotateLayerPropsCollection, graphicsLayerScale, symbolCollection, false,
                                                   false, false, true, overposterProperties, configKeyword);

            // Get the feature class from the feature layer.
            IFeatureLayer featureLayer = (IFeatureLayer)annotationLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;

            return(featureClass);
        }
Ejemplo n.º 8
0
 private void method_3(IMap imap_1, ILayer ilayer_0, string string_0, double double_1, IWorkspace iworkspace_1,
                       bool bool_0, bool bool_1, esriLabelWhichFeatures esriLabelWhichFeatures_1)
 {
     if ((iworkspace_1.Type != esriWorkspaceType.esriFileSystemWorkspace) && (ilayer_0 is IGeoFeatureLayer))
     {
         int num;
         IAnnotateLayerProperties     properties;
         IElementCollection           elements;
         IElementCollection           elements2;
         ILabelEngineLayerProperties2 properties2;
         IAnnotationLayer             layer2;
         IGeoFeatureLayer             layer = ilayer_0 as IGeoFeatureLayer;
         IFeatureClass                      featureClass         = layer.FeatureClass;
         IAnnotationLayerFactory            factory              = new FDOGraphicsLayerFactoryClass();
         ISymbolCollection2                 lcs                  = new SymbolCollectionClass();
         IAnnotateLayerPropertiesCollection propertiess          = new AnnotateLayerPropertiesCollectionClass();
         IAnnotateLayerPropertiesCollection annotationProperties = layer.AnnotationProperties;
         for (num = 0; num < annotationProperties.Count; num++)
         {
             annotationProperties.QueryItem(num, out properties, out elements, out elements2);
             if (properties != null)
             {
                 ISymbolIdentifier2 identifier;
                 propertiess.Add(properties);
                 properties2 = properties as ILabelEngineLayerProperties2;
                 IClone symbol = properties2.Symbol as IClone;
                 lcs.AddSymbol(symbol.Clone() as ISymbol, properties.Class + " " + num.ToString(), out identifier);
                 properties2.SymbolID = identifier.ID;
             }
         }
         properties  = null;
         properties2 = null;
         IGraphicsLayerScale scale = new GraphicsLayerScaleClass
         {
             ReferenceScale = double_1,
             Units          = imap_1.MapUnits
         };
         IFeatureClassDescription description  = new AnnotationFeatureClassDescriptionClass();
         IObjectClassDescription  description2 = description as IObjectClassDescription;
         IFields          requiredFields       = description2.RequiredFields;
         IGeometryDefEdit geometryDef          =
             requiredFields.get_Field(requiredFields.FindField(description.ShapeFieldName)).GeometryDef as
             IGeometryDefEdit;
         IGeoDataset dataset = featureClass as IGeoDataset;
         geometryDef.SpatialReference_2 = dataset.SpatialReference;
         IMapOverposter        overposter           = imap_1 as IMapOverposter;
         IOverposterProperties overposterProperties = overposter.OverposterProperties;
         if (bool_1)
         {
             this.method_2(iworkspace_1 as IFeatureWorkspaceAnno, featureClass.FeatureDataset, featureClass,
                           scale.ReferenceScale, scale.Units, propertiess, lcs as ISymbolCollection, string_0);
             layer2 = factory.OpenAnnotationLayer(iworkspace_1 as IFeatureWorkspace, featureClass.FeatureDataset,
                                                  string_0);
         }
         else
         {
             this.method_2(iworkspace_1 as IFeatureWorkspaceAnno, featureClass.FeatureDataset, null,
                           scale.ReferenceScale, scale.Units, propertiess, lcs as ISymbolCollection, string_0);
             layer2 = factory.OpenAnnotationLayer(iworkspace_1 as IFeatureWorkspace, featureClass.FeatureDataset,
                                                  string_0);
         }
         IActiveView    view          = imap_1 as IActiveView;
         IScreenDisplay screenDisplay = view.ScreenDisplay;
         (layer2 as IGraphicsLayer).Activate(screenDisplay);
         for (num = 0; num < propertiess.Count; num++)
         {
             propertiess.QueryItem(num, out properties, out elements, out elements2);
             if (properties != null)
             {
                 properties.FeatureLayer      = layer;
                 properties.GraphicsContainer = layer2 as IGraphicsContainer;
                 properties.AddUnplacedToGraphicsContainer = bool_0;
                 properties.CreateUnplacedElements         = true;
                 properties.DisplayAnnotation  = true;
                 properties.FeatureLinked      = bool_1;
                 properties.LabelWhichFeatures = esriLabelWhichFeatures_1;
                 properties.UseOutput          = true;
                 properties2                   = properties as ILabelEngineLayerProperties2;
                 properties2.SymbolID          = num;
                 properties2.AnnotationClassID = num;
                 IOverposterLayerProperties2 overposterLayerProperties =
                     properties2.OverposterLayerProperties as IOverposterLayerProperties2;
                 overposterLayerProperties.TagUnplaced = true;
             }
         }
         propertiess.Sort();
         IAnnotateMapProperties annoMapCmdProps = new AnnotateMapPropertiesClass
         {
             AnnotateLayerPropertiesCollection = propertiess
         };
         ITrackCancel trackCancel = new CancelTrackerClass();
         (imap_1.AnnotationEngine as IAnnotateMap2).Label(overposterProperties, annoMapCmdProps, imap_1,
                                                          trackCancel);
         for (num = 0; num < propertiess.Count; num++)
         {
             propertiess.QueryItem(num, out properties, out elements, out elements2);
             if (properties != null)
             {
                 properties.FeatureLayer = null;
             }
         }
         imap_1.AddLayer(layer2 as ILayer);
         layer.DisplayAnnotation = false;
         view.Refresh();
     }
 }
Ejemplo n.º 9
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.º 10
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)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
        }
Ejemplo n.º 11
0
        public void showAnnotationByScale()
        {
            IMap             pMap             = axMapControl.Map;
            IFeatureLayer    pFeaturelayer    = pMap.get_Layer(1) as IFeatureLayer;
            IGeoFeatureLayer pGeoFeatureLayer = pFeaturelayer as IGeoFeatureLayer;
            //创建标注集接口,可以对标注进行添加、删除、查询、排序等操作
            IAnnotateLayerPropertiesCollection pAnnotateLayerPropertiesCollection = new AnnotateLayerPropertiesCollectionClass();

            pAnnotateLayerPropertiesCollection = pGeoFeatureLayer.AnnotationProperties;
            pAnnotateLayerPropertiesCollection.Clear();
            //创建标注的颜色
            IRgbColor pRgbColor = new RgbColorClass();

            pRgbColor.Red   = 255;
            pRgbColor.Green = 0;
            pRgbColor.Blue  = 0;
            //创建标注的字体样式
            ITextSymbol pTextSymbol = new TextSymbolClass();

            pTextSymbol.Color     = pRgbColor;
            pTextSymbol.Size      = 12;
            pTextSymbol.Font.Name = "宋体";
            //定义 ILineLabelPosition接口,用来管理line features的标注属性,指定标注和线要素的位置关系
            ILineLabelPosition pLineLabelPosition = new LineLabelPositionClass();

            pLineLabelPosition.Parallel      = false;
            pLineLabelPosition.Perpendicular = true;
            pLineLabelPosition.InLine        = true;
            //定义 ILineLabelPlacementPriorities接口用来控制标注冲突
            ILineLabelPlacementPriorities pLineLabelPlacementPriorities = new LineLabelPlacementPrioritiesClass();

            pLineLabelPlacementPriorities.AboveStart = 5;
            pLineLabelPlacementPriorities.BelowAfter = 4;
            //定义 IBasicOverposterLayerProperties 接口实现 LineLabelPosition 和 LineLabelPlacementPriorities对象的控制
            IBasicOverposterLayerProperties pBasicOverposterLayerProperties = new BasicOverposterLayerPropertiesClass();

            pBasicOverposterLayerProperties.LineLabelPlacementPriorities = pLineLabelPlacementPriorities;
            pBasicOverposterLayerProperties.LineLabelPosition            = pLineLabelPosition;
            pBasicOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
            //创建标注对象
            ILabelEngineLayerProperties pLabelEngineLayerProperties = new LabelEngineLayerPropertiesClass();

            //设置标注符号
            pLabelEngineLayerProperties.Symbol = pTextSymbol;
            pLabelEngineLayerProperties.BasicOverposterLayerProperties = pBasicOverposterLayerProperties;
            //声明标注的Expression是否为Simple
            pLabelEngineLayerProperties.IsExpressionSimple = true;
            //设置标注字段
            pLabelEngineLayerProperties.Expression = "[DIQU]";
            //定义IAnnotateLayerTransformationProperties 接口用来控制feature layer的display of dynamic labels
            IAnnotateLayerTransformationProperties pAnnotateLayerTransformationProperties = pLabelEngineLayerProperties as IAnnotateLayerTransformationProperties;

            //设置标注参考比例尺
            pAnnotateLayerTransformationProperties.ReferenceScale = 500000;
            //定义IAnnotateLayerProperties接口,决定FeatureLayer动态标注信息
            IAnnotateLayerProperties pAnnotateLayerProperties = pLabelEngineLayerProperties as IAnnotateLayerProperties;

            //设置显示标注最大比例尺
            pAnnotateLayerProperties.AnnotationMaximumScale = 500000;
            //设置显示标注的最小比例
            pAnnotateLayerProperties.AnnotationMinimumScale = 25000000;
            //决定要标注的要素
            pAnnotateLayerProperties.WhereClause = "DIQU<>'宿州市'";
            //将创建好的标注对象添加到标注集对象中
            pAnnotateLayerPropertiesCollection.Add(pAnnotateLayerProperties);
            //声明标注是否显示
            pGeoFeatureLayer.DisplayAnnotation = true;
            //刷新视图
            this.axMapControl.Refresh();
        }