Exemple #1
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();
                }
            }
        }
Exemple #2
0
        public static void ConvertLabels2StandardAnno(IMap imap_0, ILayer ilayer_0, string string_0, double double_0,
                                                      IWorkspace iworkspace_0, bool bool_0, bool bool_1, esriLabelWhichFeatures esriLabelWhichFeatures_0)
        {
            int i;
            IAnnotateLayerProperties     bool0;
            IElementCollection           elementCollection;
            IElementCollection           elementCollection1;
            ILabelEngineLayerProperties2 d;
            ISymbolIdentifier2           symbolIdentifier2;
            IAnnotationLayer             annotationLayer;

            if (iworkspace_0.Type != esriWorkspaceType.esriFileSystemWorkspace && ilayer_0 is IGeoFeatureLayer)
            {
                IGeoFeatureLayer        ilayer0      = ilayer_0 as IGeoFeatureLayer;
                IFeatureClass           featureClass = ilayer0.FeatureClass;
                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 bool0, out elementCollection, out elementCollection1);
                    if (bool0 != null)
                    {
                        annotateLayerPropertiesCollectionClass.Add(bool0);
                        d = bool0 as ILabelEngineLayerProperties2;
                        IClone symbol = d.Symbol as IClone;
                        symbolCollectionClass.AddSymbol(symbol.Clone() as ISymbol,
                                                        string.Concat(bool0.Class, " ", i.ToString()), out symbolIdentifier2);
                        d.SymbolID = symbolIdentifier2.ID;
                    }
                }
                bool0 = null;
                d     = null;
                IGraphicsLayerScale graphicsLayerScaleClass = new GraphicsLayerScale()
                {
                    ReferenceScale = double_0,
                    Units          = imap_0.MapUnits
                };
                IFeatureClassDescription annotationFeatureClassDescriptionClass =
                    new AnnotationFeatureClassDescription() as IFeatureClassDescription;
                IFields requiredFields =
                    (annotationFeatureClassDescriptionClass as IObjectClassDescription).RequiredFields;
                IField field =
                    requiredFields.Field[requiredFields.FindField(annotationFeatureClassDescriptionClass.ShapeFieldName)
                    ];
                (field.GeometryDef as IGeometryDefEdit).SpatialReference_2 =
                    (featureClass as IGeoDataset).SpatialReference;
                IOverposterProperties overposterProperties = (imap_0 as IMapOverposter).OverposterProperties;
                if (!bool_1)
                {
                    LayerOp.CreateAnnoFeatureClass(iworkspace_0 as IFeatureWorkspaceAnno, featureClass.FeatureDataset,
                                                   null, graphicsLayerScaleClass.ReferenceScale, graphicsLayerScaleClass.Units,
                                                   annotateLayerPropertiesCollectionClass, symbolCollectionClass as ISymbolCollection, string_0);
                    annotationLayer = fDOGraphicsLayerFactoryClass.OpenAnnotationLayer(
                        iworkspace_0 as IFeatureWorkspace, featureClass.FeatureDataset, string_0);
                }
                else
                {
                    LayerOp.CreateAnnoFeatureClass(iworkspace_0 as IFeatureWorkspaceAnno, featureClass.FeatureDataset,
                                                   featureClass, graphicsLayerScaleClass.ReferenceScale, graphicsLayerScaleClass.Units,
                                                   annotateLayerPropertiesCollectionClass, symbolCollectionClass as ISymbolCollection, string_0);
                    annotationLayer = fDOGraphicsLayerFactoryClass.OpenAnnotationLayer(
                        iworkspace_0 as IFeatureWorkspace, featureClass.FeatureDataset, string_0);
                }
                IActiveView imap0 = imap_0 as IActiveView;
                (annotationLayer as IGraphicsLayer).Activate(imap0.ScreenDisplay);
                for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++)
                {
                    annotateLayerPropertiesCollectionClass.QueryItem(i, out bool0, out elementCollection,
                                                                     out elementCollection1);
                    if (bool0 != null)
                    {
                        bool0.FeatureLayer      = ilayer0;
                        bool0.GraphicsContainer = annotationLayer as IGraphicsContainer;
                        bool0.AddUnplacedToGraphicsContainer = bool_0;
                        bool0.CreateUnplacedElements         = true;
                        bool0.DisplayAnnotation  = true;
                        bool0.FeatureLinked      = bool_1;
                        bool0.LabelWhichFeatures = esriLabelWhichFeatures_0;
                        bool0.UseOutput          = true;
                        d                   = bool0 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 bool0, out elementCollection,
                                                                     out elementCollection1);
                    if (bool0 != null)
                    {
                        bool0.FeatureLayer = null;
                    }
                }
                imap_0.AddLayer(annotationLayer as ILayer);
                ilayer0.DisplayAnnotation = false;
                imap0.Refresh();
            }
        }
Exemple #3
0
        public void CopyAnnotationFeatures()
        {
            try
            {
                IMxDocument pMxDoc      = (IMxDocument)ArcMap.Application.Document;
                IMap        pMap        = pMxDoc.FocusMap;
                ILayer      SourceLayer = pMap.Layer[0];
                ILayer      TargetLayer = pMap.Layer[1];

                IFeatureLayer SourceFLayer = (IFeatureLayer)SourceLayer;
                IFeatureLayer TargetFLayer = (IFeatureLayer)TargetLayer;

                IFeatureClass SourceFeatureClass = SourceFLayer.FeatureClass;
                IFeatureClass TargetFeatureClass = TargetFLayer.FeatureClass;

                IFields TargetFields = TargetFeatureClass.Fields;
                IFields SourceFields = SourceFeatureClass.Fields;

                IDictionary <int, int> symbSourceTargIdXref = new Dictionary <int, int>();
                symbSourceTargIdXref.Add(4, 17);
                symbSourceTargIdXref.Add(5, 22);
                symbSourceTargIdXref.Add(43, 45);
                symbSourceTargIdXref.Add(45, 45);
                ISymbolCollection targetSymbolsColl = (TargetFeatureClass.Extension as IAnnoClass).SymbolCollection;

                IField pFld;

                int[] lSrcFlds;
                int[] lTarFlds;

                int lFld, lExFld, i;
                lExFld = 0;
                for (lFld = 0; lFld <= (SourceFields.FieldCount - 1); lFld++)
                {
                    pFld = SourceFields.Field[lFld];

                    if (pFld.Type != esriFieldType.esriFieldTypeOID && pFld.Type != esriFieldType.esriFieldTypeGeometry && pFld.Name.ToUpper() != "ELEMENT" && pFld.Name.ToUpper() != "ZORDER" && pFld.Editable == true)
                    {
                        lExFld = lExFld + 1;
                    }
                }


                lSrcFlds = new int[lExFld];
                lTarFlds = new int[lExFld];

                i = 0;

                for (lFld = 0; lFld <= (SourceFields.FieldCount - 1); lFld++)
                {
                    pFld = SourceFields.Field[lFld];
                    if (pFld.Type != esriFieldType.esriFieldTypeOID && pFld.Type != esriFieldType.esriFieldTypeGeometry && pFld.Name.ToUpper() != "ELEMENT" && pFld.Name.ToUpper() != "ZORDER" && pFld.Editable == true)
                    {
                        lSrcFlds[i] = lFld;
                        lTarFlds[i] = TargetFields.FindField(pFld.Name);
                        i           = i + 1;
                    }
                }


                IFeatureCursor pICursor;
                pICursor = SourceFeatureClass.Search(null, true);

                IFeature pIFeat;
                pIFeat = pICursor.NextFeature();

                IFDOGraphicsLayerFactory pGLF;
                pGLF = new FDOGraphicsLayerFactory();

                IDataset pDataset;
                pDataset = (IDataset)TargetFeatureClass;



                IAnnotationFeature pAnnoFeature;
                IClone             pAClone;
                IElement           pElement;


                IAnnoClass pTargetAnnoClass = (IAnnoClass)TargetFeatureClass.Extension;


                while (pIFeat != null)
                {
                    pAnnoFeature = (IAnnotationFeature)pIFeat;

                    if (pAnnoFeature.Annotation != null)
                    {
                        ITextElement sourceTextElement = pAnnoFeature.Annotation as ITextElement;
                        pAClone  = (IClone)sourceTextElement;
                        pElement = (IElement)pAClone.Clone();

                        ITextElement ptempTxt = (ITextElement)pAClone.Clone();
                        //set id
                        IFeature pTempFeat = TargetFeatureClass.CreateFeature();



                        ISymbolCollectionElement TargetSymbCollElem = (ISymbolCollectionElement)ptempTxt;

                        ISymbolCollectionElement sourceSymbCollElem = sourceTextElement as ISymbolCollectionElement;

                        int sourceSymbID = sourceSymbCollElem.SymbolID;

                        int symbolID = symbSourceTargIdXref[sourceSymbID];

                        ISymbolIdentifier2 pSymbI;
                        ISymbolCollection2 pSymbolColl2 = ( ISymbolCollection2 )pTargetAnnoClass.SymbolCollection;

                        pSymbolColl2.GetSymbolIdentifier(symbolID, out pSymbI);

                        //reset the desired symbol id

                        TargetSymbCollElem.set_SharedSymbol(pSymbI.ID, pSymbI.Symbol);


                        //save the annotation feature
                        IAnnotationFeature pAnnoFeat = (IAnnotationFeature)pTempFeat;

                        pAnnoFeat.Annotation = ptempTxt as IElement;
                        pTempFeat.Store();

                        //reset the over rided property by analysing the override code

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideXOffset) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.XOffset = sourceSymbCollElem.XOffset;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideYOffset) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.YOffset = sourceSymbCollElem.YOffset;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideHorzAlignment) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.HorizontalAlignment = sourceSymbCollElem.HorizontalAlignment;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideVertAlignment) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.VerticalAlignment = sourceSymbCollElem.VerticalAlignment;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideFlipAngle) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.FlipAngle = TargetSymbCollElem.FlipAngle;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideSize) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.Size = sourceSymbCollElem.Size;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideColor) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.Color = sourceSymbCollElem.Color;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideCharSpacing) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.CharacterSpacing = sourceSymbCollElem.CharacterSpacing;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideCharWidth) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.CharacterWidth = sourceSymbCollElem.CharacterWidth;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideWordSpacing) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.WordSpacing = sourceSymbCollElem.WordSpacing;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideLeading) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.Leading = sourceSymbCollElem.Leading;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideBold) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.Bold = sourceSymbCollElem.Bold;
                        }
                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideItalic) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.Italic = sourceSymbCollElem.Italic;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideUnderline) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.Underline = sourceSymbCollElem.Underline;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideBackground) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.Background = sourceSymbCollElem.Background;
                        }

                        if ((sourceSymbCollElem.OverriddenProperties ^ (int)esriSymbolOverrideEnum.esriSymbolOverrideFontName) <= sourceSymbCollElem.OverriddenProperties)
                        {
                            TargetSymbCollElem.FontName = sourceSymbCollElem.FontName;
                        }

                        //save the feature again
                        pAnnoFeat.Annotation = ptempTxt as IElement;
                        pTempFeat.Store();
                    }
                    pIFeat = pICursor.NextFeature();
                }


                pMxDoc.UpdateContents();
                pMxDoc.ActiveView.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }