ラベルをアノテーションに変換


一括変換GUIなかったっけ。。。
とりあえず書く

        using (ComReleaser com = new ComReleaser())
        {
            IConvertLabelsToAnnotation lable2Anno = new ConvertLabelsToAnnotationClass();
            com.ManageLifetime(lable2Anno);
            ITrackCancel cancelTracker = new CancelTrackerClass();
            com.ManageLifetime(cancelTracker);

            lable2Anno.Initialize(map,
              esriAnnotationStorageType.esriDatabaseAnnotation,
              esriLabelWhichFeatures.esriAllFeatures, true, cancelTracker, null);

            IUID uid = new UIDClass();
            com.ManageLifetime(uid);

            uid.Value = "{" + typeof(IGeoFeatureLayer).GUID.ToString() + "}";
            //IGeoFeatureLayer Interface ID.
            IMapLayers mapLayers = map as IMapLayers;
            IEnumLayer enumLayers = mapLayers.get_Layers(uid as UIDClass, true);
            com.ManageLifetime(enumLayers);
            enumLayers.Reset();

            IGeoFeatureLayer geoLayer = null; //enumLayers.Next() as IGeoFeatureLayer;

            while ((geoLayer = enumLayers.Next() as IGeoFeatureLayer  )== null)
            {
                if (!geoLayer.Valid)
                    continue;
                /*
                if (!mapLayers.IsLayerVisible(geoLayer as ILayer))
                    continue;
                */
                if (!geoLayer.DisplayAnnotation)
                    continue;

                IFeatureClass fclass = geoLayer.FeatureClass;
                IFeatureWorkspace workspace = ((IDataset)fclass).Workspace as
                IFeatureWorkspace;
                IFeatureDataset fdataset = fclass.FeatureDataset;

                if (expWorkspace != null)
                {
                    workspace = expWorkspace;
                    fdataset = expDataset;
                    featureLinked = false;
                }
                string name = geoLayer.Name + "_Anno";
                ISQLSyntax syntax = (ISQLSyntax)workspace;
                string invChar = syntax.GetInvalidCharacters();

                char rep = invChar.Contains('_') ? 'A' : '_';
                foreach (char item in invChar)
                {
                    name = name.Replace(item, rep);
                }

                lable2Anno.AddFeatureLayer(geoLayer,
                    name, workspace,
                    fdataset, featureLinked, false, false, true,
                    true, "");                
            }
            //変換実行
            lable2Anno.ConvertLabels();

            IEnumLayer pAnnoEnumLayer = lable2Anno.AnnoLayers;
            com.ManageLifetime(pAnnoEnumLayer);

            enumLayers.Reset();
            geoLayer = enumLayers.Next() as IGeoFeatureLayer;
            while (geoLayer != null)
            {
                if (!geoLayer.Valid)
                    continue;
                //if (!mapLayers.IsLayerVisible(geoLayer as ILayer))
                //    continue;

                if (geoLayer.DisplayAnnotation)
                    geoLayer.DisplayAnnotation = false;

                geoLayer = enumLayers.Next() as IGeoFeatureLayer;
            }
            map.AddLayers(pAnnoEnumLayer, true);

            IActiveView actView = map as IActiveView;
            //actView.Refresh();
            IViewRefresh viewRefresh = (IViewRefresh)map;
            viewRefresh.AnimationRefresh(esriViewDrawPhase.esriViewAll, null, actView.Extent);

        }//end com
カテゴリー: 開発 タグ: パーマリンク