欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

标注转注记图层

程序员文章站 2022-06-12 16:48:47
...
     /// <summary>
    /// 标注转注记图层(shp文件不支持标注)
    /// </summary>
    /// <param name="pMap">地图</param>
    /// <param name="pLayer">图层</param>
    /// <param name="featureLinked">是否festurelinked</param>
    /// <param name="sError">错误信息</param>
    /// <returns>是否成功</returns>
    private bool LabelConvertToAnnotation(IMap pMap, ILayer pLayer, bool featureLinked, out string sError)
    {
        sError = string.Empty;
        bool bIsSucceed = true;
        string sName = string.Empty;
        try
        {
            IConvertLabelsToAnnotation pConvertLabelsToAnnotation = new ConvertLabelsToAnnotationClass();
            ITrackCancel pTrackCancel = new CancelTrackerClass();

            pConvertLabelsToAnnotation.Initialize(pMap,
                esriAnnotationStorageType.esriDatabaseAnnotation,
                esriLabelWhichFeatures.esriAllFeatures, true, pTrackCancel, null);

            IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
            if (pGeoFeatureLayer == null)
            {
                sError = "图层为空";
                return false;
            }

            IFeatureClass pFeatureClass = pGeoFeatureLayer.FeatureClass;
            if (pFeatureClass == null)
            {
                sError = "图层要素为空";
                return false;
            }

            IDataset pDataset = pFeatureClass as IDataset;
            sName = GtMap.GxAEHelper.FeatureClass.GetPureName(pDataset.Name);
            IFeatureWorkspace pFeatureWorkspace = pDataset.Workspace as
                IFeatureWorkspace;

            pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer, sName + "ZJ", pFeatureWorkspace,
                pFeatureClass.FeatureDataset, featureLinked, false, false, true, true, "");
            //// true, true, true, true
            pConvertLabelsToAnnotation.ConvertLabels();

            string sErrorInfo = pConvertLabelsToAnnotation.ErrorInfo;
            if (!string.IsNullOrEmpty(sErrorInfo))
            {
                sError = sErrorInfo;
                bIsSucceed = false;
            }

            IEnumLayer pEnumLayer = pConvertLabelsToAnnotation.AnnoLayers;
            pGeoFeatureLayer.DisplayAnnotation = false;
            pMap.AddLayers(pEnumLayer, true);

            IActiveView pActiveView = pMap as IActiveView;
            pActiveView.Refresh();

        }
        catch (Exception ex)
        {
            sError = ex.Message;
            bIsSucceed = false;
        }

        return bIsSucceed;
    }
相关标签: AE二次开发