示例#1
0
        /// <summary>
        /// 将地图上指定图层的标注转注记,存储在地图中
        /// (保存在地图上的注记是IGraphicsLayer->IGraphicsContainer->IElement)
        /// </summary>
        /// <param name="map">执行标注转注记的地图</param>
        /// <param name="geoFeatureLayer">需要将标注转注记的图层(注意这些图层必须是map中的图层)</param>
        /// <param name="whichFeatures">标示将哪些要素生成注记的枚举(所有要素/当前范围的要素/选择的要素)</param>
        public static void ConvertLabelsToMapAnnotation(this IMap map, IGeoFeatureLayer[] geoFeatureLayer,
                                                        esriLabelWhichFeatures whichFeatures = esriLabelWhichFeatures.esriVisibleFeatures)
        {
            IConvertLabelsToAnnotation convertLabelsToAnnotation = new ConvertLabelsToAnnotationClass();
            ITrackCancel trackCancel = new CancelTrackerClass();

            //设置标注转注记的参数:①地图、②注记存储位置(数据库注记/地图注记)、③哪些要素生成注记(所有要素/当前范围的要素/选择的要素)
            //④是否生成地位注记、⑥取消操作、⑦异常事件处理
            convertLabelsToAnnotation.Initialize(map, esriAnnotationStorageType.esriMapAnnotation,
                                                 whichFeatures, true, trackCancel, null);

            //添加要进行转换的图层
            for (int i = 0; i < geoFeatureLayer.Length; i++)
            {
                convertLabelsToAnnotation.AddFeatureLayer(geoFeatureLayer[i],
                                                          geoFeatureLayer[i].Name + "_Anno", null, null, false, false, false, false, true, "");
            }
            //执行转换,生成注记
            convertLabelsToAnnotation.ConvertLabels();

            //隐藏标注
            for (int i = 0; i < geoFeatureLayer.Length; i++)
            {
                geoFeatureLayer[i].DisplayAnnotation = false;
            }

            //刷新地图
            IActiveView activeView = map as IActiveView;

            activeView.Refresh();
        }
示例#2
0
        /// <summary>
        ///  将地图上的标注转注记,生成注记图层存储在数据库中
        ///  (保存在数据库的注记图层是IFeatureClass/IFeatureLayer/IAnnotationLayer->IFeature as IAnnotationFeature.Annotation->IElement)
        /// </summary>
        /// <param name="map">执行标注转注记的地图</param>
        /// <param name="featureLinked">是否关联要素(关联要素的注记必须与其所关联的要素类存储在同一地理数据库中)</param>
        /// <param name="whichFeatures">标示哪些要素生成注记的枚举(所有要素/当前范围的要素/选择的要素)</param>
        /// <param name="outWorkspace">保存注记的工作空间</param>
        /// <param name="suffix">注记图层名称后缀</param>
        public static void ConvertLabelsToGdbAnnotationLayers(this IMap map, bool featureLinked    = false,
                                                              esriLabelWhichFeatures whichFeatures = esriLabelWhichFeatures.esriVisibleFeatures, IWorkspace outWorkspace = null, string suffix = "_Anno")
        {
            IConvertLabelsToAnnotation convertLabelsToAnnotation = new ConvertLabelsToAnnotationClass();
            ITrackCancel pTrackCancel = new CancelTrackerClass();

            //设置标注转注记的参数:①地图、②注记存储位置(数据库注记/地图注记)、③哪些要素生成注记(所有要素/当前范围的要素/选择的要素)
            //④是否生成地位注记、⑥取消操作、⑦异常事件处理
            convertLabelsToAnnotation.Initialize(map, esriAnnotationStorageType.esriDatabaseAnnotation,
                                                 whichFeatures, true, pTrackCancel, null);

            //添加要进行转换的图层
            IGeoFeatureLayer geoFeatureLayer;

            for (int i = 0; i < map.LayerCount; i++)
            {
                geoFeatureLayer = map.get_Layer(i) as IGeoFeatureLayer;
                if (geoFeatureLayer != null)
                {
                    IFeatureClass featureClass = geoFeatureLayer.FeatureClass;
                    IDataset      dataset      = featureClass as IDataset;

                    IFeatureWorkspace outFeatureWorkspace;
                    IFeatureDataset   featureDataset;
                    if (featureLinked)//关联要素时,生成的注记必须存储在原地理数据库数据集中
                    {
                        outFeatureWorkspace = dataset.Workspace as IFeatureWorkspace;
                        featureDataset      = featureClass.FeatureDataset;
                    }
                    else
                    {
                        outFeatureWorkspace = outWorkspace as IFeatureWorkspace;
                        featureDataset      = null;
                    }

                    convertLabelsToAnnotation.AddFeatureLayer(geoFeatureLayer, geoFeatureLayer.Name + suffix,
                                                              outFeatureWorkspace, featureDataset, featureLinked, false, false, true, true, "");
                }
            }

            //执行转换,生成注记
            convertLabelsToAnnotation.ConvertLabels();
            IEnumLayer enumLayer = convertLabelsToAnnotation.AnnoLayers;

            //隐藏标注
            for (int i = 0; i < map.LayerCount; i++)
            {
                geoFeatureLayer = map.get_Layer(i) as IGeoFeatureLayer;
                geoFeatureLayer.DisplayAnnotation = false;
            }

            //添加注记图层到地图中
            map.AddLayers(enumLayer, true);

            //刷新地图
            IActiveView pActiveView = map as IActiveView;

            pActiveView.Refresh();
        }
示例#3
0
        private void ConvertLabelsToAnnotationSingleLayerMapAnno(IMap pMap, int layerIndex)
        {
            //label features by OBJECTID FEILD

            IGeoFeatureLayer pGeoFeatLayer;

            pGeoFeatLayer = pMap.Layer[layerIndex] as IGeoFeatureLayer;
            IAnnotateLayerPropertiesCollection pAnnotationLayerProColl = pGeoFeatLayer.AnnotationProperties;

            pGeoFeatLayer.DisplayAnnotation = true;
            IAnnotateLayerProperties pAnnoLayPro;
            IElementCollection       pElecol1;
            IElementCollection       pElecol2;

            pAnnotationLayerProColl.QueryItem(0, out pAnnoLayPro, out pElecol1, out pElecol2);
            ILabelEngineLayerProperties pLabelEngineLayerPro;

            pLabelEngineLayerPro            = pAnnoLayPro as ILabelEngineLayerProperties;
            pLabelEngineLayerPro.Expression = "[OBJECTID]";
            pAnnoLayPro.DisplayAnnotation   = true;

            //convert to annotation

            IConvertLabelsToAnnotation pConvertLabelsToAnnotation = new
                                                                    ConvertLabelsToAnnotationClass();
            ITrackCancel pTrackCancel = new CancelTrackerClass();

            //Change global level options for the conversion by sending in different parameters to the next line.
            pConvertLabelsToAnnotation.Initialize(pMap,
                                                  esriAnnotationStorageType.esriMapAnnotation,
                                                  esriLabelWhichFeatures.esriVisibleFeatures, true, pTrackCancel, null);
            ILayer           pLayer           = pMap.get_Layer(layerIndex);
            IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;

            if (pGeoFeatureLayer != null)
            {
                IFeatureClass pFeatureClass = pGeoFeatureLayer.FeatureClass;
                //Add the layer information to the converter object. Specify the parameters of the output annotation feature class here as well.
                pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer,
                                                           pGeoFeatureLayer.Name + "_Anno", null, null, false, false, false, false,
                                                           false, "");
                //Do the conversion.
                pConvertLabelsToAnnotation.ConvertLabels();
                //Turn off labeling for the layer converted.
                pGeoFeatureLayer.DisplayAnnotation = false;
                //Refresh the map to update the display.
                IActiveView pActiveView = pMap as IActiveView;
                pActiveView.Refresh();
            }
        }
示例#4
0
        /// <summary>
        ///  将指定图层的标注转注记,生成注记图层存储在数据库中
        ///  (保存在数据库的注记图层是IFeatureClass/IFeatureLayer/IAnnotationLayer->IFeature as IAnnotationFeature.Annotation->IElement)
        /// </summary>
        /// <param name="map">执行标注转注记的地图</param>
        /// <param name="layer">执行标注转注记的图层</param>
        /// <param name="featureLinked">是否关联要素(关联要素的注记必须与其所关联的要素类存储在同一地理数据库中)</param>
        /// <param name="whichFeatures"></param>
        /// <parparam name="whichFeatures">标示哪些要素生成注记的枚举(所有要素/当前范围的要素/选择的要素)</parparam>
        public static void ConvertLabelsToGdbAnnotationSingleLayer(this IMap map, ILayer layer, bool featureLinked = false,
                                                                   esriLabelWhichFeatures whichFeatures            = esriLabelWhichFeatures.esriVisibleFeatures)
        {
            IConvertLabelsToAnnotation convertLabelsToAnnotation = new ConvertLabelsToAnnotationClass();
            ITrackCancel pTrackCancel = new CancelTrackerClass();

            //设置标注转注记的参数:①地图、②注记存储位置(数据库注记/地图注记)、③哪些要素生成注记(所有要素/当前范围的要素/选择的要素)
            //④是否生成地位注记、⑥取消操作、⑦异常事件处理
            convertLabelsToAnnotation.Initialize(map, esriAnnotationStorageType.esriDatabaseAnnotation,
                                                 whichFeatures, true, pTrackCancel, null);

            IGeoFeatureLayer geoFeatureLayer = layer as IGeoFeatureLayer;

            if (geoFeatureLayer != null)
            {
                IFeatureClass     featureClass     = geoFeatureLayer.FeatureClass;
                IDataset          dataset          = featureClass as IDataset;
                IFeatureWorkspace featureWorkspace = dataset.Workspace as IFeatureWorkspace;
                try
                {
                    convertLabelsToAnnotation.AddFeatureLayer(geoFeatureLayer, geoFeatureLayer.Name + "_Anno",
                                                              featureWorkspace, featureClass.FeatureDataset, featureLinked, false, false, true, true, "");
                }
                catch (Exception ex) { throw new Exception("标注转注记操作出错:" + ex.ToString()); }

                //执行转换,生成注记
                convertLabelsToAnnotation.ConvertLabels();
                IEnumLayer enumLayer = convertLabelsToAnnotation.AnnoLayers;

                //隐藏标注
                geoFeatureLayer.DisplayAnnotation = false;

                //添加注记图层到地图中
                map.AddLayers(enumLayer, true);

                //刷新地图
                IActiveView pActiveView = map as IActiveView;
                pActiveView.Refresh();
            }
        }
示例#5
0
        /// <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();
                pMap.ReferenceScale = 100000000;
                pConvertLabelsToAnnotation.Initialize(pMap, /*
                                                             * esriAnnotationStorageType.esriMapAnnotation*/esriAnnotationStorageType.esriDatabaseAnnotation,
                                                      esriLabelWhichFeatures.esriAllFeatures, true, pTrackCancel, null);

                IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
                pGeoFeatureLayer.DisplayField      = "Text_";
                pGeoFeatureLayer.DisplayAnnotation = true;



                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);

                sName = pLayer.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 = true;
                pMap.AddLayers(pEnumLayer, true);



                IActiveView pActiveView = pMap as IActiveView;
                pActiveView.Refresh();
            }
            catch (Exception ex)
            {
                sError     = ex.Message;
                bIsSucceed = false;
            }

            return(bIsSucceed);
        }
示例#6
0
        /// <summary>
        /// 标注转注记图层(shp文件不支持标注)
        /// </summary>
        /// <param name="pMap">地图</param>
        /// <param name="pLayer">图层</param>
        /// <param name="featureLinked">是否feasturelinked</param>
        /// <param name="sError">错误信息</param>
        /// <returns>是否成功</returns>
        public 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();
                IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
                pGeoFeatureLayer.DisplayField      = "Text_";//此处指定要转的字段
                pGeoFeatureLayer.DisplayAnnotation = true;
                // pGeoFeatureLayer.AnnotationProperties
                // pMap.MapUnits = esriUnits.esriMeters;

                //pMap.ReferenceScale = 12000;//设置缩放比例
                //pMap.ActiveGraphicsLayer.SpatialReference.

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

                if (pGeoFeatureLayer == null)
                {
                    sError = "图层为空";
                    //    pMap.MapUnits = esriUnits.esriUnknownUnits;
                    return(false);
                }

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

                IDataset pDataset = pFeatureClass as IDataset;


                sName = pLayer.Name;
                IFeatureWorkspace pFeatureWorkspace = pDataset.Workspace as IFeatureWorkspace;


                pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer,
                                                           sName + "ZJ", pFeatureWorkspace,
                                                           pFeatureClass.FeatureDataset,
                                                           featureLinked,
                                                           false, false, false, 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, false);//将注释层添加到arcmap显示

                IActiveView pActiveView = pMap as IActiveView;
                pActiveView.Refresh();
            }
            catch (Exception ex)
            {
                sError     = ex.Message;
                bIsSucceed = false;
            }
            // pMap.MapUnits = esriUnits.esriUnknownUnits;
            return(bIsSucceed);
        }
示例#7
0
        //public IFeatureDataset CreateFeatureDataset_Example(IWorkspace workspace, string fdsName, ISpatialReference fdsSR)
        //{
        //    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
        //    return featureWorkspace.CreateFeatureDataset(fdsName, fdsSR);
        //}

        public void ConvertLabelsToGDBAnnotationSingleLayer(IMap pMap, bool featureLinked)  //(IMap pMap, int layerIndex, bool   featureLinked)
        {
            try
            {
                IConvertLabelsToAnnotation pConvertLabelsToAnnotation = new
                                                                        ConvertLabelsToAnnotationClass();
                ITrackCancel pTrackCancel = new CancelTrackerClass();
                //Change global level options for the conversion by sending in different parameters to the next line.
                pConvertLabelsToAnnotation.Initialize(pMap,
                                                      esriAnnotationStorageType.esriDatabaseAnnotation,
                                                      esriLabelWhichFeatures.esriAllFeatures, true, pTrackCancel, null);

                //ILayer pLayer = pMap.get_Layer(layerIndex);
                IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
                if (pGeoFeatureLayer != null)
                {
                    IFeatureClass pFeatureClass = pGeoFeatureLayer.FeatureClass;
                    IDataset      pDataset      = pFeatureClass as IDataset;

                    IFeatureWorkspace pFeatureWorkspace = pDataset.Workspace as
                                                          IFeatureWorkspace;
                    //Add the layer information to the converter object. Specify the parameters of the output annotation feature class here as well.
                    //if (pFeatureClass.FeatureDataset != null)
                    //{
                    //    pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer,
                    //    pGeoFeatureLayer.Name + "_Anno", pFeatureWorkspace,
                    //    pFeatureClass.FeatureDataset, featureLinked, false, false, true, true, "");
                    //}
                    //else
                    //{
                    //必须指定路径,默认存放到原有GDB中会造成无法第二次创建的问题
                    if (MessageBox.Show("请指定一个位置生成GeoDatabase存放注记图层", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        SaveFileDialog saveFileDlg = new SaveFileDialog();
                        saveFileDlg.DefaultExt = "gdb";
                        saveFileDlg.Filter     = "(文件型数据库)*.gdb|*.gdb";
                        if (saveFileDlg.ShowDialog() == DialogResult.OK)
                        {
                            string strFileGDB = saveFileDlg.FileName;

                            string strPath = System.IO.Path.GetDirectoryName(strFileGDB);
                            string strName = System.IO.Path.GetFileName(strFileGDB);

                            ClsGDBDataCommon com = new ClsGDBDataCommon();
                            com.Create_FileGDB(strPath, strName);
                            string          strfile  = strPath + "\\" + strName;
                            IWorkspace      pws      = com.OpenFromFileGDB(strfile);
                            IFeatureDataset pdataset = creatdataset(pws, pLayer.Name + "Anno", pMap.SpatialReference);
                            pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer,
                                                                       pGeoFeatureLayer.Name + "_Anno", (IFeatureWorkspace)pws,
                                                                       pdataset, featureLinked, false, false, true, true, "");
                        }
                    }
                    //}
                    //Do the conversion.
                    pConvertLabelsToAnnotation.ConvertLabels();
                    IEnumLayer pEnumLayer = pConvertLabelsToAnnotation.AnnoLayers;
                    //Turn off labeling for the layer converted.
                    pGeoFeatureLayer.DisplayAnnotation = false;

                    //Add the result annotation layer to the map.
                    pMap.AddLayers(pEnumLayer, true);

                    //Refresh the map to update the display.
                    IActiveView pActiveView = pMap as IActiveView;
                    pActiveView.Refresh();
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("该图层已存在注记图层", "提示", MessageBoxButtons.OK);
            }
        }