• 为图层增加注记表达式


    从注记表达式的文本文件中程序里读取并动态地增加注记。label expression 可以为简单的或vb脚本等

    /// <summary>
    
            /// 图层增加注记表达式
    
            /// </summary>
    
            /// <param name="map">The map.</param>
    
            /// <param name="tcname">The tcname.</param>
    
            public static void AddAnno(ILayer plyr , string tcname)
    
            {
    
                if (!System.IO.File.Exists(注记文件存储路径))
    
                    return;
    
                            IGeoFeatureLayer pGeoFeaLayer = (plyr as IFeatureLayer) as IGeoFeatureLayer;
    
                            IAnnotateLayerPropertiesCollection pAnoLayPC = pGeoFeaLayer.AnnotationProperties;
    
                            pAnoLayPC.Clear();
    
     
    
                            ILabelEngineLayerProperties pAnnoLayerProps = new LabelEngineLayerPropertiesClass();
    
                            (pAnnoLayerProps.BasicOverposterLayerProperties as IOverposterLayerProperties2).TagUnplaced = false;  ////是否覆盖,对应Arcmap:layer properties-》labels-》placement properties-》conflict detection ::place overlapping labels
    
                            pAnnoLayerProps.SymbolID = 0;
    
                            IBasicOverposterLayerProperties4 blp = pAnnoLayerProps.BasicOverposterLayerProperties as IBasicOverposterLayerProperties4;
    
                            //blp.PointPlacementMethod = esriOverposterPointPlacementMethod.esriAroundPoint;
    
                            
    
                            blp.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape; ////每个图形只标注一个  label properties--palcement properties--duplicate labels
    
                            blp.PolygonPlacementMethod = esriOverposterPolygonPlacementMethod.esriAlwaysHorizontal; //// label properties--palcement properties--polygon settings
    
                            // blp.PlaceOnlyInsidePolygon = true;  ////保证在图形内部  label properties--palcement properties--only place label inside polygon
    
     
    
     
    
                            string annoExpression = GetAnnoExpression(注记文件存储路径);
    
                            if (annoExpression.ToUpper().IndexOf("FUNCTION") >= 0)
    
                                pAnnoLayerProps.IsExpressionSimple = false;
    
                            else
    
                                pAnnoLayerProps.IsExpressionSimple = true; //对应aArcMap的advanced选项
    
                            pAnnoLayerProps.Expression = annoExpression;
    
     
    
                            pAnnoLayerProps.Symbol = CreateTextSymbol();
    
                            pGeoFeaLayer.DisplayAnnotation = true;
    
            }
    
     
    
    /// <summary>
    
            /// 根据注记文件存储路径获取标注表达式
    
            /// </summary>
    
            /// <param name="tcname">The tcname.</param>
    
            /// <returns></returns>
    
            public static string GetAnnoExpression(string注记文件存储路径)
    
            {
    
                StreamReader sr = new StreamReader(注记文件存储路径);
    
                string annoExpression = string.Empty;
    
                while (!sr.EndOfStream)
    
                {
    
                    string text = sr.ReadLine();
    
                    if (annoExpression == string.Empty)
    
                        annoExpression = text;
    
                    else
    
                        annoExpression = annoExpression + "
    " + text;
    
                }
    
                return annoExpression;
    
            }
  • 相关阅读:
    此生对我影响最大的三位老师
    介绍自己
    介绍自己
    第三周作业
    第二周作业
    PTA编程总结3
    PTA编程总结2
    PTA编程总结1
    2019年春季学期第七周作业.
    2019年春季学期第六周作业.
  • 原文地址:https://www.cnblogs.com/jhlong/p/5394340.html
Copyright © 2020-2023  润新知