示例#1
0
        public IFeatureClass CreateStandAloneAnnotationClass(IWorkspace ws, string annoname)
        {
            #region 创建Anno图层
            IFeatureClass featureClass = null;
            try
            {
                //ILayer pLayer = m_pmap.get_Layer(0);
                //IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                //ILayer pSrcLayer = pLayer;
                //IFeatureClass featureClass = pFeatureLayer.FeatureClass;

                //IDataset dataset = (IDataset)featureClass;//cast for the feature workspace from the workspace
                //IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)dataset.Workspace;
                IFeatureWorkspaceAnno featureWorkspaceAnno = (IFeatureWorkspaceAnno)ws;//set up the reference scale
                ESRI.ArcGIS.Carto.IGraphicsLayerScale graphicLayerScale = new ESRI.ArcGIS.Carto.GraphicsLayerScaleClass();
                //IGeoDataset geoDataset = (IGeoDataset)dataset;
                graphicLayerScale.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters;
                graphicLayerScale.ReferenceScale = 500;//set up symbol collection
                ESRI.ArcGIS.Display.ISymbolCollection symbolCollection = new ESRI.ArcGIS.Display.SymbolCollectionClass();
                #region "MakeText"
                ESRI.ArcGIS.Display.IFormattedTextSymbol myTextSymbol = new ESRI.ArcGIS.Display.TextSymbolClass();        //set the font for myTextSymbol
                stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
                myFont.Name = "Courier New";
                myFont.Size = 9;
                myTextSymbol.Font = myFont;//set the Color for myTextSymbol to be Dark Red
                ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
                rgbColor.Red = 150;
                rgbColor.Green = 0;
                rgbColor.Blue = 0;
                myTextSymbol.Color = (ESRI.ArcGIS.Display.IColor)rgbColor;//Set other properties for myTextSymbol
                myTextSymbol.Angle = 0;
                myTextSymbol.RightToLeft = false;
                myTextSymbol.VerticalAlignment = ESRI.ArcGIS.Display.esriTextVerticalAlignment.esriTVABaseline;
                myTextSymbol.HorizontalAlignment = ESRI.ArcGIS.Display.esriTextHorizontalAlignment.esriTHAFull;
                myTextSymbol.CharacterSpacing = 200;
                myTextSymbol.Case = ESRI.ArcGIS.Display.esriTextCase.esriTCNormal;
                #endregion
                symbolCollection.set_Symbol(0, (ESRI.ArcGIS.Display.ISymbol)myTextSymbol);//set up the annotation labeling properties including the expression
                ESRI.ArcGIS.Carto.IAnnotateLayerProperties annoProps = new ESRI.ArcGIS.Carto.LabelEngineLayerPropertiesClass();
                annoProps.FeatureLinked = false;//这里控制是不是关联的注记层
                annoProps.AddUnplacedToGraphicsContainer = false;
                annoProps.CreateUnplacedElements = true;
                annoProps.DisplayAnnotation = true;
                annoProps.UseOutput = true;
                ESRI.ArcGIS.Carto.ILabelEngineLayerProperties layerEngineLayerProps = (ESRI.ArcGIS.Carto.ILabelEngineLayerProperties)annoProps;
                ESRI.ArcGIS.Carto.IAnnotationExpressionEngine annoExpressionEngine = new ESRI.ArcGIS.Carto.AnnotationVBScriptEngineClass();
                layerEngineLayerProps.ExpressionParser = annoExpressionEngine;
                layerEngineLayerProps.Expression = "[RefName]";
                layerEngineLayerProps.IsExpressionSimple = true;
                layerEngineLayerProps.Offset = 0;
                layerEngineLayerProps.SymbolID = 0;
                layerEngineLayerProps.Symbol = myTextSymbol;
                ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties annoLayerTransProp =
                    (ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties)annoProps;
                annoLayerTransProp.ReferenceScale = graphicLayerScale.ReferenceScale;
                annoLayerTransProp.Units = graphicLayerScale.Units;
                annoLayerTransProp.ScaleRatio = 1;
                ESRI.ArcGIS.Carto.IAnnotateLayerPropertiesCollection annoPropsColl = new ESRI.ArcGIS.Carto.AnnotateLayerPropertiesCollectionClass();
                annoPropsColl.Add(annoProps);//use the AnnotationFeatureClassDescription to get the list of required
                //fields and the default name of the shape field
                IObjectClassDescription oCDesc = new ESRI.ArcGIS.Carto.AnnotationFeatureClassDescriptionClass();
                IFeatureClassDescription fCDesc = (IFeatureClassDescription)oCDesc;//create the new class

                featureClass = featureWorkspaceAnno.CreateAnnotationClass(annoname, oCDesc.RequiredFields, oCDesc.InstanceCLSID, oCDesc.ClassExtensionCLSID,
                    fCDesc.ShapeFieldName, "", null, null, annoPropsColl, graphicLayerScale, symbolCollection, true);
                //给新建的图层添加子层
                ISubtypes subtypes = (ISubtypes)featureClass;
                subtypes.SubtypeFieldName = "AnnotationClassID";
                subtypes.AddSubtype(1, "GCD");
                subtypes.AddSubtype(2, "DLDW");
                subtypes.AddSubtype(3, "JMD");
                subtypes.AddSubtype(4, "SXSS");
                subtypes.AddSubtype(5, "DLSS");
                subtypes.AddSubtype(6, "ZBTZ");
                subtypes.AddSubtype(7, "TK");
                subtypes.DefaultSubtypeCode = 1;
                return featureClass;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return featureClass;
            }
            #endregion
        }
示例#2
0
        public IFeatureClass CreateStandAloneAnnotationClass(IWorkspace ws, string annoname)
        {
            #region 创建Anno图层
            IFeatureClass featureClass = null;
            try
            {
                //ILayer pLayer = m_pmap.get_Layer(0);
                //IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                //ILayer pSrcLayer = pLayer;
                //IFeatureClass featureClass = pFeatureLayer.FeatureClass;

                //IDataset dataset = (IDataset)featureClass;//cast for the feature workspace from the workspace
                //IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)dataset.Workspace;
                IFeatureWorkspaceAnno featureWorkspaceAnno = (IFeatureWorkspaceAnno)ws;//set up the reference scale
                ESRI.ArcGIS.Carto.IGraphicsLayerScale graphicLayerScale = new ESRI.ArcGIS.Carto.GraphicsLayerScaleClass();
                //IGeoDataset geoDataset = (IGeoDataset)dataset;
                graphicLayerScale.Units          = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters;
                graphicLayerScale.ReferenceScale = 500;//set up symbol collection
                ESRI.ArcGIS.Display.ISymbolCollection symbolCollection = new ESRI.ArcGIS.Display.SymbolCollectionClass();
                #region "MakeText"
                ESRI.ArcGIS.Display.IFormattedTextSymbol myTextSymbol = new ESRI.ArcGIS.Display.TextSymbolClass();        //set the font for myTextSymbol
                stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
                myFont.Name       = "Courier New";
                myFont.Size       = 9;
                myTextSymbol.Font = myFont;//set the Color for myTextSymbol to be Dark Red
                ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
                rgbColor.Red                     = 150;
                rgbColor.Green                   = 0;
                rgbColor.Blue                    = 0;
                myTextSymbol.Color               = (ESRI.ArcGIS.Display.IColor)rgbColor;//Set other properties for myTextSymbol
                myTextSymbol.Angle               = 0;
                myTextSymbol.RightToLeft         = false;
                myTextSymbol.VerticalAlignment   = ESRI.ArcGIS.Display.esriTextVerticalAlignment.esriTVABaseline;
                myTextSymbol.HorizontalAlignment = ESRI.ArcGIS.Display.esriTextHorizontalAlignment.esriTHAFull;
                myTextSymbol.CharacterSpacing    = 200;
                myTextSymbol.Case                = ESRI.ArcGIS.Display.esriTextCase.esriTCNormal;
                #endregion
                symbolCollection.set_Symbol(0, (ESRI.ArcGIS.Display.ISymbol)myTextSymbol); //set up the annotation labeling properties including the expression
                ESRI.ArcGIS.Carto.IAnnotateLayerProperties annoProps = new ESRI.ArcGIS.Carto.LabelEngineLayerPropertiesClass();
                annoProps.FeatureLinked = false;                                           //这里控制是不是关联的注记层
                annoProps.AddUnplacedToGraphicsContainer = false;
                annoProps.CreateUnplacedElements         = true;
                annoProps.DisplayAnnotation = true;
                annoProps.UseOutput         = true;
                ESRI.ArcGIS.Carto.ILabelEngineLayerProperties layerEngineLayerProps = (ESRI.ArcGIS.Carto.ILabelEngineLayerProperties)annoProps;
                ESRI.ArcGIS.Carto.IAnnotationExpressionEngine annoExpressionEngine  = new ESRI.ArcGIS.Carto.AnnotationVBScriptEngineClass();
                layerEngineLayerProps.ExpressionParser   = annoExpressionEngine;
                layerEngineLayerProps.Expression         = "[RefName]";
                layerEngineLayerProps.IsExpressionSimple = true;
                layerEngineLayerProps.Offset             = 0;
                layerEngineLayerProps.SymbolID           = 0;
                layerEngineLayerProps.Symbol             = myTextSymbol;
                ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties annoLayerTransProp =
                    (ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties)annoProps;
                annoLayerTransProp.ReferenceScale = graphicLayerScale.ReferenceScale;
                annoLayerTransProp.Units          = graphicLayerScale.Units;
                annoLayerTransProp.ScaleRatio     = 1;
                ESRI.ArcGIS.Carto.IAnnotateLayerPropertiesCollection annoPropsColl = new ESRI.ArcGIS.Carto.AnnotateLayerPropertiesCollectionClass();
                annoPropsColl.Add(annoProps);//use the AnnotationFeatureClassDescription to get the list of required
                //fields and the default name of the shape field
                IObjectClassDescription  oCDesc = new ESRI.ArcGIS.Carto.AnnotationFeatureClassDescriptionClass();
                IFeatureClassDescription fCDesc = (IFeatureClassDescription)oCDesc;//create the new class

                featureClass = featureWorkspaceAnno.CreateAnnotationClass(annoname, oCDesc.RequiredFields, oCDesc.InstanceCLSID, oCDesc.ClassExtensionCLSID,
                                                                          fCDesc.ShapeFieldName, "", null, null, annoPropsColl, graphicLayerScale, symbolCollection, true);
                //给新建的图层添加子层
                ISubtypes subtypes = (ISubtypes)featureClass;
                subtypes.SubtypeFieldName = "AnnotationClassID";
                subtypes.AddSubtype(1, "GCD");
                subtypes.AddSubtype(2, "DLDW");
                subtypes.AddSubtype(3, "JMD");
                subtypes.AddSubtype(4, "SXSS");
                subtypes.AddSubtype(5, "DLSS");
                subtypes.AddSubtype(6, "ZBTZ");
                subtypes.AddSubtype(7, "TK");
                subtypes.DefaultSubtypeCode = 1;
                return(featureClass);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(featureClass);
            }
            #endregion
        }