Beispiel #1
0
        public static int getSymbolIDByName(IFeatureClass Anno, string name)
        {
            IAnnoClass         aClas = (IAnnoClass)Anno.Extension;
            ISymbolCollection2 isc   = (ISymbolCollection2)aClas.SymbolCollection;

            isc.Reset();// very important to call Reset() if not you get no result from Next()
            ISymbolIdentifier2 sId = (ISymbolIdentifier2)isc.Next();

            while (sId != null)
            {
                if (sId.Name.ToUpper() == name.ToUpper())
                {
                    return(sId.ID);
                }
                sId = (ISymbolIdentifier2)isc.Next();
            }
            return(-1);
        }
Beispiel #2
0
        public static List <string> getSymbolNames(IFeatureClass Anno)
        {
            List <string>      names = new List <string>();
            IAnnoClass         aClas = (IAnnoClass)Anno.Extension;
            ISymbolCollection2 isc   = (ISymbolCollection2)aClas.SymbolCollection;

            isc.Reset();
            ISymbolIdentifier2 sId = (ISymbolIdentifier2)isc.Next();

            while (sId != null)
            {
                names.Add(sId.Name);
                sId = (ISymbolIdentifier2)aClas.SymbolCollection.Next();
            }

            names.Sort();
            return(names);
        }
Beispiel #3
0
        public static string getSymbolNameById(IFeatureClass Anno, int id)
        {
            IAnnoClass         aClas = (IAnnoClass)Anno.Extension;
            ISymbolCollection2 isc   = (ISymbolCollection2)aClas.SymbolCollection;

            isc.Reset();
            ISymbolIdentifier2 sId = (ISymbolIdentifier2)isc.Next();

            while (sId != null)
            {
                if (sId.ID == id)
                {
                    return(sId.Name);
                }
                sId = (ISymbolIdentifier2)isc.Next();
            }
            return(null);
        }
Beispiel #4
0
        private IFeatureClass method_1(string string_2, double double_0, IFields ifields_1,
                                       IFeatureDataset ifeatureDataset_1, IFeatureClass ifeatureClass_1,
                                       IFeatureWorkspaceAnno ifeatureWorkspaceAnno_0, esriUnits esriUnits_0,
                                       IAnnotateLayerPropertiesCollection2 iannotateLayerPropertiesCollection2_0,
                                       ISymbolCollection2 isymbolCollection2_0)
        {
            IObjectClassDescription description    = new AnnotationFeatureClassDescriptionClass();
            IGraphicsLayerScale     referenceScale = new GraphicsLayerScaleClass
            {
                ReferenceScale = double_0,
                Units          = esriUnits_0
            };
            UID instanceCLSID       = description.InstanceCLSID;
            UID classExtensionCLSID = description.ClassExtensionCLSID;

            return(ifeatureWorkspaceAnno_0.CreateAnnotationClass(string_2, ifields_1, instanceCLSID, classExtensionCLSID,
                                                                 "Shape", "", ifeatureDataset_1, ifeatureClass_1, iannotateLayerPropertiesCollection2_0, referenceScale,
                                                                 isymbolCollection2_0, true));
        }
        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();
        }
Beispiel #6
0
        private int method_4(ISymbolCollection2 isymbolCollection2_0)
        {
            isymbolCollection2_0.Reset();
            ISymbolIdentifier2 identifier = isymbolCollection2_0.Next() as ISymbolIdentifier2;
            IList list = new ArrayList();

            while (identifier != null)
            {
                list.Add(identifier.ID);
                identifier = isymbolCollection2_0.Next() as ISymbolIdentifier2;
            }
            int num = 0;

            if (list.Count != 0)
            {
                while (list.IndexOf(num) != -1)
                {
                    num++;
                }
                return(num);
            }
            return(num);
        }
Beispiel #7
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);
        }
Beispiel #8
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());
            }
        }