Exemple #1
0
 private void ReadMapLayer(ILayer layer)
 {
     if (layer is IGroupLayer)
     {
         ICompositeLayer comLayer = layer as ICompositeLayer;
         for (int i = 0; i < comLayer.Count; i++)
         {
             ILayer lyr = comLayer.get_Layer(i);
             ReadMapLayer(lyr);
         }
     }
     if (layer is IGeoFeatureLayer)
     {
         IGeoFeatureLayer geoFtLayer = layer as IGeoFeatureLayer;
         if (geoFtLayer == null)
         {
             return;
         }
         if (geoFtLayer.FeatureClass == null)
         {
             return;
         }
         geoFeatureLayer.Add(geoFtLayer);
     }
     if (layer is IAnnotationLayer)
     {
         IAnnotationLayer annotationLayer = layer as IAnnotationLayer;
         IFeatureLayer    featureLayer    = annotationLayer as IFeatureLayer;
         if (featureLayer != null && featureLayer.FeatureClass != null)
         {
             annoLayers.Add(annotationLayer);
         }
     }
 }
Exemple #2
0
        public static void SetReferenceScale(IAnnotationLayer annotationLayer, double scale)
        {
            IFeatureLayer    featureLayer    = annotationLayer as IFeatureLayer;
            IFeatureClass    featureClass    = featureLayer.FeatureClass;
            IAnnoClass       annoClass       = featureClass.Extension as IAnnoClass;
            IAnnoClassAdmin3 annoClassAdmin3 = annoClass as IAnnoClassAdmin3;

            annoClassAdmin3.ReferenceScale = scale;
        }
        protected override void OnClick()
        {
            ILayer           layer     = ArcMap.Document.SelectedLayer;
            IAnnotationLayer annoLayer = layer as IAnnotationLayer;

            if (annoLayer != null)
            {
                ProcessAnnotation(annoLayer);
            }
        }
Exemple #4
0
 private static void LoadMapLayer(ILayer layer, Dictionary <string, DF2DFeatureClass> dict, List <ILayer> loadlayer)
 {
     if (layer is ESRI.ArcGIS.Carto.IGroupLayer)              //如果是图层组
     {
         ICompositeLayer comLayer = layer as ICompositeLayer; //将图层转化为复合图层
         for (int i = 0; i < comLayer.Count; i++)
         {
             ILayer lyr = comLayer.get_Layer(i);
             LoadMapLayer(lyr, dict, loadlayer);
         }
     }
     if (layer is IAnnotationLayer)//如果是注记图层
     {
         IAnnotationLayer annotationLayer = layer as IAnnotationLayer;
         IFeatureLayer    featureLayer    = annotationLayer as IFeatureLayer;
         IFeatureClass    fc = featureLayer.FeatureClass;
         if (featureLayer != null && fc != null)
         {
             string fcID = fc.FeatureClassID.ToString();
             foreach (KeyValuePair <string, DF2DFeatureClass> v in dict)//在该MajorClass对应的要素类集中找到它的FeatureClassID,将图层添加到loadlayer中
             {
                 if (fcID == v.Key)
                 {
                     loadlayer.Add(layer);
                     v.Value.SetLayer(layer);
                     break;
                 }
             }
         }
     }
     if (layer is IGeoFeatureLayer)//如果是地理要素图层
     {
         IGeoFeatureLayer geoFtLayer = layer as IGeoFeatureLayer;
         if (geoFtLayer == null)
         {
             return;
         }
         if (geoFtLayer.FeatureClass == null)
         {
             return;
         }
         IFeatureClass fc   = geoFtLayer.FeatureClass;
         string        fcID = fc.FeatureClassID.ToString();
         foreach (KeyValuePair <string, DF2DFeatureClass> v in dict)//在该MajorClass对应的要素类集中找到它的FeatureClassID,将图层添加到loadlayer中
         {
             if (fcID == v.Key)
             {
                 loadlayer.Add(layer);
                 v.Value.SetLayer(layer);
                 break;
             }
         }
     }
 }
        protected override void OnUpdate()
        {
            ILayer           layer     = ArcMap.Document.SelectedLayer;
            IAnnotationLayer annoLayer = layer as IAnnotationLayer;

            if (annoLayer != null)
            {
                Enabled = true;
            }
            else
            {
                Enabled = false;
            }
        }
Exemple #6
0
        public static IAnnotationLayer GetAnnotationLayer(IFeatureWorkspace featWrk, IFeatureDataset featDS, string annolayerName)
        {
            IAnnotationLayer annoLayer = null;

            try
            {
                IAnnotationLayerFactory annoLayerFact = new FDOGraphicsLayerFactoryClass();
                annoLayer = annoLayerFact.OpenAnnotationLayer(featWrk, featDS, annolayerName);
            }
            catch (Exception ex)
            {
                LOG.Error(ex);
                return(null);
            }

            return(annoLayer);
        }
Exemple #7
0
 private static void  ReadMapLayer(ILayer layer, Dictionary <string, IFeatureClass> dicfc)
 {
     if (layer is ESRI.ArcGIS.Carto.IGroupLayer)
     {
         ICompositeLayer comLayer = layer as ICompositeLayer;
         for (int i = 0; i < comLayer.Count; i++)
         {
             ILayer lyr = comLayer.get_Layer(i);
             ReadMapLayer(lyr, dicfc);
         }
     }
     if (layer is IGeoFeatureLayer)
     {
         IGeoFeatureLayer geoFtLayer = layer as IGeoFeatureLayer;
         if (geoFtLayer == null)
         {
             return;
         }
         if (geoFtLayer.FeatureClass == null)
         {
             return;
         }
         IFeatureClass fc   = geoFtLayer.FeatureClass;
         string        fcID = fc.FeatureClassID.ToString();
         dicfc.Add(fcID, fc);
     }
     if (layer is IAnnotationLayer)
     {
         IAnnotationLayer annotationLayer = layer as IAnnotationLayer;
         IFeatureLayer    featureLayer    = annotationLayer as IFeatureLayer;
         IFeatureClass    fc = featureLayer.FeatureClass;
         if (featureLayer == null || fc == null)
         {
             return;
         }
         string fcID = fc.FeatureClassID.ToString();
         dicfc.Add(fcID, fc);
     }
 }
        private void ProcessAnnotation(IAnnotationLayer annoLayer)
        {
            //get unique values
            IFeatureLayer   featureLayer = annoLayer as IFeatureLayer;
            IDataStatistics dataStats    = new DataStatisticsClass();

            dataStats.Field      = "SymbolID";
            dataStats.SampleRate = -1; //all records
            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.SubFields = "SymbolID";
            dataStats.Cursor      = featureLayer.Search(queryFilter, true) as ICursor;

            object value   = null;
            var    enumVar = dataStats.UniqueValues;

            //now remove items
            IFeatureClass             featureClass     = featureLayer.FeatureClass;
            IAnnotationClassExtension annoClassExt     = featureClass.Extension as IAnnotationClassExtension;
            ISymbolCollection2        symbolCollection = annoClassExt.SymbolCollection as ISymbolCollection2;

            ISymbolCollection2 newSymColl = new SymbolCollectionClass();

            while (enumVar.MoveNext())
            {
                value = enumVar.Current;
                ISymbolIdentifier2 symbolIdent = null;
                symbolCollection.GetSymbolIdentifier(Convert.ToInt32(value), out symbolIdent);
                newSymColl.set_Symbol(symbolIdent.ID, symbolIdent.Symbol);
                newSymColl.RenameSymbol(symbolIdent.ID, symbolIdent.Name);
            }

            //update class extension with the new collection
            IAnnoClassAdmin3 annoClassAdmin = annoClassExt as IAnnoClassAdmin3;

            annoClassAdmin.SymbolCollection = (ISymbolCollection)newSymColl;
            annoClassAdmin.UpdateProperties();
        }
Exemple #9
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);
        }
Exemple #10
0
        public static void ConvertLabels2StandardAnno(IMap imap_0, ILayer ilayer_0, string string_0)
        {
            int i;
            IAnnotateLayerProperties     annotateLayerProperty;
            IElementCollection           elementCollection;
            IElementCollection           elementCollection1;
            ILabelEngineLayerProperties2 d;
            ISymbolIdentifier2           symbolIdentifier2;
            IActiveView imap0 = imap_0 as IActiveView;

            if (ilayer_0 is IGeoFeatureLayer)
            {
                IGeoFeatureLayer ilayer0   = ilayer_0 as IGeoFeatureLayer;
                IWorkspace       workspace = (ilayer0 as IDataset).Workspace;
                if (workspace.Type != esriWorkspaceType.esriFileSystemWorkspace)
                {
                    IFeatureClass           featureClass = ilayer0.FeatureClass;
                    IGeoDataset             geoDataset   = featureClass as IGeoDataset;
                    IAnnotationLayerFactory fDOGraphicsLayerFactoryClass =
                        new FDOGraphicsLayerFactory() as IAnnotationLayerFactory;
                    ISymbolCollection2 symbolCollectionClass = new SymbolCollection() as ISymbolCollection2;
                    IAnnotateLayerPropertiesCollection annotateLayerPropertiesCollectionClass =
                        new AnnotateLayerPropertiesCollection();
                    IAnnotateLayerPropertiesCollection annotationProperties = ilayer0.AnnotationProperties;
                    for (i = 0; i < annotationProperties.Count; i++)
                    {
                        annotationProperties.QueryItem(i, out annotateLayerProperty, out elementCollection,
                                                       out elementCollection1);
                        if (annotateLayerProperty != null)
                        {
                            annotateLayerPropertiesCollectionClass.Add(annotateLayerProperty);
                            d = annotateLayerProperty as ILabelEngineLayerProperties2;
                            IClone symbol = d.Symbol as IClone;
                            symbolCollectionClass.AddSymbol(symbol.Clone() as ISymbol,
                                                            string.Concat(annotateLayerProperty.Class, " ", i.ToString()), out symbolIdentifier2);
                            d.SymbolID = symbolIdentifier2.ID;
                        }
                    }
                    annotateLayerProperty = null;
                    d = null;
                    IGraphicsLayerScale graphicsLayerScaleClass = new GraphicsLayerScale();
                    if (imap_0.ReferenceScale != 0)
                    {
                        graphicsLayerScaleClass.ReferenceScale = imap_0.ReferenceScale;
                    }
                    else
                    {
                        try
                        {
                            graphicsLayerScaleClass.ReferenceScale = imap_0.MapScale;
                        }
                        catch (Exception exception)
                        {
                            Logger.Current.Error("", exception, null);
                        }
                    }
                    graphicsLayerScaleClass.Units = imap_0.MapUnits;
                    IFeatureClassDescription annotationFeatureClassDescriptionClass =
                        new AnnotationFeatureClassDescription() as IFeatureClassDescription;
                    IFields requiredFields =
                        (annotationFeatureClassDescriptionClass as IObjectClassDescription).RequiredFields;
                    IField field =
                        requiredFields.Field[
                            requiredFields.FindField(annotationFeatureClassDescriptionClass.ShapeFieldName)];
                    IGeometryDefEdit geometryDef = field.GeometryDef as IGeometryDefEdit;
                    geometryDef.SpatialReference_2 = geoDataset.SpatialReference;
                    IOverposterProperties overposterProperties = (imap_0 as IMapOverposter).OverposterProperties;
                    IAnnotationLayer      annotationLayer      =
                        fDOGraphicsLayerFactoryClass.CreateAnnotationLayer(workspace as IFeatureWorkspace,
                                                                           featureClass.FeatureDataset, string_0, geometryDef, null,
                                                                           annotateLayerPropertiesCollectionClass, graphicsLayerScaleClass,
                                                                           symbolCollectionClass as ISymbolCollection, true, true, false, true, overposterProperties,
                                                                           "");
                    (annotationLayer as IGraphicsLayer).Activate(imap0.ScreenDisplay);
                    for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++)
                    {
                        annotateLayerPropertiesCollectionClass.QueryItem(i, out annotateLayerProperty,
                                                                         out elementCollection, out elementCollection1);
                        if (annotateLayerProperty != null)
                        {
                            annotateLayerProperty.FeatureLayer      = ilayer0;
                            annotateLayerProperty.GraphicsContainer = annotationLayer as IGraphicsContainer;
                            annotateLayerProperty.AddUnplacedToGraphicsContainer = true;
                            annotateLayerProperty.CreateUnplacedElements         = true;
                            annotateLayerProperty.DisplayAnnotation  = true;
                            annotateLayerProperty.FeatureLinked      = true;
                            annotateLayerProperty.LabelWhichFeatures = esriLabelWhichFeatures.esriAllFeatures;
                            annotateLayerProperty.UseOutput          = true;
                            d                   = annotateLayerProperty as ILabelEngineLayerProperties2;
                            d.SymbolID          = i;
                            d.AnnotationClassID = i;
                            (d.OverposterLayerProperties as IOverposterLayerProperties2).TagUnplaced = true;
                        }
                    }
                    annotateLayerPropertiesCollectionClass.Sort();
                    IAnnotateMapProperties annotateMapPropertiesClass = new AnnotateMapProperties()
                    {
                        AnnotateLayerPropertiesCollection = annotateLayerPropertiesCollectionClass
                    };
                    ITrackCancel cancelTrackerClass = new CancelTracker();
                    (imap_0.AnnotationEngine as IAnnotateMap2).Label(overposterProperties, annotateMapPropertiesClass,
                                                                     imap_0, cancelTrackerClass);
                    for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++)
                    {
                        annotateLayerPropertiesCollectionClass.QueryItem(i, out annotateLayerProperty,
                                                                         out elementCollection, out elementCollection1);
                        if (annotateLayerProperty != null)
                        {
                            annotateLayerProperty.FeatureLayer = null;
                        }
                    }
                    imap_0.AddLayer(annotationLayer as ILayer);
                    ilayer0.DisplayAnnotation = false;
                    imap0.Refresh();
                }
            }
        }
        private void ConvertAnnotation(IMap map, ILayer featureLayer, string annotationFeatureClassName, double scale,
                                       IWorkspace workspace, ILineLabelPosition lineLabelPosition,
                                       IPointPlacementPriorities pointPlacementPriorities,
                                       esriBasicOverposterWeight labelWeight, esriBasicOverposterWeight featureWeight, bool tagUnplaced,
                                       string fontName, double fontSize, IRgbColor rgbColor, string expression, bool featureLinked,
                                       esriLabelWhichFeatures labelWhichFeatures)
        {
            if (workspace.Type != esriWorkspaceType.esriFileSystemWorkspace && featureLayer is IGeoFeatureLayer)
            {
                IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
                IAnnotateLayerPropertiesCollection annotateLayerPropertiesCollectionClass =
                    geoFeatureLayer.AnnotationProperties;
                annotateLayerPropertiesCollectionClass.Clear();
                ILabelEngineLayerProperties     labelEngineLayerProperties     = new LabelEngineLayerPropertiesClass();
                IBasicOverposterLayerProperties basicOverposterLayerProperties =
                    new BasicOverposterLayerPropertiesClass();
                if (lineLabelPosition != null)
                {
                    basicOverposterLayerProperties.LineLabelPosition = lineLabelPosition;
                }
                else if (pointPlacementPriorities != null)
                {
                    basicOverposterLayerProperties.PointPlacementPriorities = pointPlacementPriorities;
                }
                basicOverposterLayerProperties.LabelWeight   = labelWeight;
                basicOverposterLayerProperties.FeatureWeight = featureWeight;

                IOverposterLayerProperties2 overposterLayerProperties2 =
                    basicOverposterLayerProperties as IOverposterLayerProperties2;
                overposterLayerProperties2.TagUnplaced = tagUnplaced;

                labelEngineLayerProperties.BasicOverposterLayerProperties = basicOverposterLayerProperties;
                stdole.IFontDisp pFont = new stdole.StdFontClass() as stdole.IFontDisp;
                pFont.Name = fontName;
                ITextSymbol pTextSymbol = new TextSymbolClass();
                pTextSymbol.Size  = fontSize;
                pTextSymbol.Font  = pFont;
                pTextSymbol.Color = rgbColor;
                labelEngineLayerProperties.Symbol     = pTextSymbol;
                labelEngineLayerProperties.Expression = expression;

                IAnnotateLayerProperties annotateLayerProperties =
                    labelEngineLayerProperties as IAnnotateLayerProperties;
                annotateLayerProperties.DisplayAnnotation = true;

                IAnnotationLayer annotationLayer =
                    CommonHelper.GetLayerByFeatureClassName(_context.FocusMap, annotationFeatureClassName) as
                    IAnnotationLayer;
                CommonHelper.SetReferenceScale(annotationLayer, scale);
                annotateLayerProperties.FeatureLayer      = geoFeatureLayer;
                annotateLayerProperties.GraphicsContainer = annotationLayer as IGraphicsContainer;
                annotateLayerProperties.AddUnplacedToGraphicsContainer = true;
                annotateLayerProperties.CreateUnplacedElements         = true;
                annotateLayerProperties.DisplayAnnotation  = true;
                annotateLayerProperties.FeatureLinked      = featureLinked;
                annotateLayerProperties.LabelWhichFeatures = labelWhichFeatures;
                annotateLayerProperties.UseOutput          = true;
                annotateLayerPropertiesCollectionClass.Add(annotateLayerProperties);

                annotateLayerPropertiesCollectionClass.Sort();
                IAnnotateMapProperties annotateMapPropertiesClass = new AnnotateMapPropertiesClass()
                {
                    AnnotateLayerPropertiesCollection = annotateLayerPropertiesCollectionClass
                };
                ITrackCancel          cancelTrackerClass   = new CancelTrackerClass();
                IAnnotateMap2         annotateMap2         = map.AnnotationEngine as IAnnotateMap2;
                IOverposterProperties overposterProperties = (map as IMapOverposter).OverposterProperties;
                annotateMap2.Label(overposterProperties, annotateMapPropertiesClass, map, cancelTrackerClass);
                map.AddLayer(annotationLayer as ILayer);
                geoFeatureLayer.DisplayAnnotation = false;
                map.ReferenceScale = scale;
                map.MapScale       = scale;
                IActiveView activeView = map as IActiveView;
                activeView.Refresh();
            }
        }