Ejemplo n.º 1
0
        private IFeatureClass CreateFeatureClass(IFeatureWorkspace FeatureWorkspace, string LayerName, esriFeatureType featureType, esriGeometryType GeometryType)
        {
            IFields     fields = new FieldsClass();
            IFieldsEdit edit   = fields as IFieldsEdit;

            //创建OBJECTID字段
            IField     field3 = new FieldClass();
            IFieldEdit edit2  = field3 as IFieldEdit;

            edit2.Name_2      = "OBJECTID";
            edit2.AliasName_2 = "OBJECTID";
            edit2.Type_2      = esriFieldType.esriFieldTypeOID;
            edit.AddField(field3);

            //创建Shape字段
            IGeometryDef     def   = new GeometryDefClass();
            IGeometryDefEdit edit4 = def as IGeometryDefEdit;

            edit4.GeometryType_2 = GeometryType;
            edit4.GridCount_2    = 1;
            edit4.set_GridSize(0, 1000);
            edit4.AvgNumPoints_2     = 2;
            edit4.HasM_2             = false;
            edit4.HasZ_2             = false;
            edit4.SpatialReference_2 = this.ExportSpatialReference;

            IField     field4 = new FieldClass();
            IFieldEdit edit3  = field4 as IFieldEdit;

            edit3.Name_2        = "SHAPE";
            edit3.AliasName_2   = "SHAPE";
            edit3.Type_2        = esriFieldType.esriFieldTypeGeometry;
            edit3.GeometryDef_2 = def;
            edit.AddField(field4);

            string ShapeFiledName = field4.Name;

            UID uid  = null;
            UID uid2 = null;

            switch (featureType)
            {
            case esriFeatureType.esriFTSimple:       //FeatureClass
                IObjectClassDescription description4 = new FeatureClassDescriptionClass();
                uid  = description4.InstanceCLSID;
                uid2 = description4.ClassExtensionCLSID;
                break;

            case esriFeatureType.esriFTAnnotation:     //AnnotationFeatureClass
                IObjectClassDescription description = new AnnotationFeatureClassDescriptionClass();
                uid          = description.InstanceCLSID;
                uid2         = description.ClassExtensionCLSID;
                GeometryType = esriGeometryType.esriGeometryPolygon;
                break;
            }
            //创建要素对象
            IFeatureClass fc = FeatureWorkspace.CreateFeatureClass(LayerName, fields, uid, uid2, featureType, ShapeFiledName, null);

            return(fc);
        }
Ejemplo n.º 2
0
        private IFeatureClass method_2(IFeatureWorkspaceAnno ifeatureWorkspaceAnno_0, IFeatureDataset ifeatureDataset_0,
                                       IFeatureClass ifeatureClass_0, double double_1, esriUnits esriUnits_0,
                                       IAnnotateLayerPropertiesCollection iannotateLayerPropertiesCollection_0,
                                       ISymbolCollection isymbolCollection_0, string string_0)
        {
            IObjectClassDescription description = new AnnotationFeatureClassDescriptionClass();
            IFields requiredFields = description.RequiredFields;
            int     index          = requiredFields.FindField((description as IFeatureClassDescription).ShapeFieldName);

            if (index != -1)
            {
                IField            field            = requiredFields.get_Field(index);
                IGeometryDef      geometryDef      = field.GeometryDef;
                ISpatialReference spatialReference = geometryDef.SpatialReference;
                SpatialReferenctOperator.ChangeCoordinateSystem(ifeatureWorkspaceAnno_0 as IGeodatabaseRelease,
                                                                spatialReference, false);
                (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
                (field as IFieldEdit).GeometryDef_2 = geometryDef;
            }
            IFeatureClassDescription description2   = description as IFeatureClassDescription;
            IGraphicsLayerScale      referenceScale = new GraphicsLayerScaleClass
            {
                ReferenceScale = double_1,
                Units          = esriUnits_0
            };
            UID instanceCLSID       = description.InstanceCLSID;
            UID classExtensionCLSID = description.ClassExtensionCLSID;

            return(ifeatureWorkspaceAnno_0.CreateAnnotationClass(string_0, requiredFields, instanceCLSID,
                                                                 classExtensionCLSID, description2.ShapeFieldName, "", ifeatureDataset_0, ifeatureClass_0,
                                                                 iannotateLayerPropertiesCollection_0, referenceScale, isymbolCollection_0, true));
        }
Ejemplo n.º 3
0
        private IFeatureClass method_1(IFeatureWorkspace ifeatureWorkspace_0, string string_4, double double_0,
                                       ITextSymbol itextSymbol_0, IFields ifields_0)
        {
            IObjectClassDescription  description  = new AnnotationFeatureClassDescriptionClass();
            IFeatureClassDescription description2 = description as IFeatureClassDescription;
            IClone     requiredFields             = description.RequiredFields as IClone;
            IFields    fields = requiredFields.Clone() as IFields;
            IFieldEdit edit   = null;
            int        index  = fields.FindField(description2.ShapeFieldName);

            edit = fields.get_Field(index) as IFieldEdit;
            IGeometryDefEdit      geometryDef    = edit.GeometryDef as IGeometryDefEdit;
            IFeatureWorkspaceAnno anno           = ifeatureWorkspace_0 as IFeatureWorkspaceAnno;
            IGraphicsLayerScale   referenceScale = new GraphicsLayerScaleClass
            {
                ReferenceScale = double_0,
                Units          = esriUnits.esriMeters
            };
            UID instanceCLSID                  = description.InstanceCLSID;
            UID classExtensionCLSID            = description.ClassExtensionCLSID;
            ISymbolCollection symbolCollection = new SymbolCollectionClass();

            symbolCollection.set_Symbol(0, itextSymbol_0 as ISymbol);
            IAnnotateLayerPropertiesCollection2 annoProperties = new AnnotateLayerPropertiesCollectionClass();
            IAnnotateLayerProperties            item           = new LabelEngineLayerPropertiesClass
            {
                Class         = "要素类 1",
                FeatureLinked = false,
                AddUnplacedToGraphicsContainer = false,
                CreateUnplacedElements         = true,
                DisplayAnnotation = true,
                UseOutput         = true
            };
            ILabelEngineLayerProperties properties2 = item as ILabelEngineLayerProperties;

            properties2.Offset   = 0.0;
            properties2.SymbolID = 0;
            properties2.Symbol   = itextSymbol_0;
            annoProperties.Add(item);
            for (int i = 0; i < ifields_0.FieldCount; i++)
            {
                if (fields.FindField(ifields_0.get_Field(i).Name) == -1)
                {
                    (fields as IFieldsEdit).AddField(ifields_0.get_Field(i));
                }
            }
            try
            {
                return(anno.CreateAnnotationClass(string_4, fields, instanceCLSID, classExtensionCLSID,
                                                  description2.ShapeFieldName, "", null, null, annoProperties, referenceScale, symbolCollection, false));
            }
            catch (Exception exception)
            {
                Logger.Current.Error("", exception, "");
            }
            return(null);
        }
Ejemplo n.º 4
0
        public void InitFields()
        {
            IFields requiredFields;

            if (this.IsFeatureClass)
            {
                IFeatureClassDescription description;
                IGeometryDef             geometryDef;
                if (this.FeatureType == esriFeatureType.esriFTSimple)
                {
                    description    = new FeatureClassDescriptionClass();
                    requiredFields = (description as IObjectClassDescription).RequiredFields;
                    this.ifield_0  = requiredFields.get_Field(requiredFields.FindField(description.ShapeFieldName));
                    geometryDef    = (this.ifield_0 as IFieldEdit2).GeometryDef;
                    (geometryDef as IGeometryDefEdit).GeometryType_2 = m_pObjectClassHelper.ShapeType;
                    if (this.ispatialReference_0 != null)
                    {
                        (geometryDef as IGeometryDefEdit).SpatialReference_2 = this.ispatialReference_0;
                    }
                    (geometryDef as IGeometryDefEdit).HasZ_2    = this.bool_3;
                    (geometryDef as IGeometryDefEdit).HasM_2    = this.bool_4;
                    (this.ifield_0 as IFieldEdit).GeometryDef_2 = geometryDef as IGeometryDefEdit;
                    this.ifields_0 = requiredFields;
                }
                else if (this.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    description    = new AnnotationFeatureClassDescriptionClass();
                    requiredFields = (description as IObjectClassDescription).RequiredFields;
                    this.ifield_0  = requiredFields.get_Field(requiredFields.FindField(description.ShapeFieldName));
                    geometryDef    = (this.ifield_0 as IFieldEdit2).GeometryDef;
                    if (this.ispatialReference_0 != null)
                    {
                        (geometryDef as IGeometryDefEdit).SpatialReference_2 = this.ispatialReference_0;
                    }
                    this.ifields_0 = requiredFields;
                }
                else if (this.FeatureType == esriFeatureType.esriFTDimension)
                {
                    description    = new DimensionClassDescriptionClass();
                    requiredFields = (description as IObjectClassDescription).RequiredFields;
                    this.ifield_0  = requiredFields.get_Field(requiredFields.FindField(description.ShapeFieldName));
                    geometryDef    = (this.ifield_0 as IFieldEdit2).GeometryDef;
                    if (this.ispatialReference_0 != null)
                    {
                        (geometryDef as IGeometryDefEdit).SpatialReference_2 = this.ispatialReference_0;
                    }
                    this.ifields_0 = requiredFields;
                }
            }
            else
            {
                IObjectClassDescription description2 = new FeatureClassDescriptionClass();
                requiredFields = description2.RequiredFields;
                this.ifields_0 = requiredFields;
            }
        }
        private bool FeatureClassWellKnown(UID uid)
        {
            IObjectClassDescription ocDescription = new AnnotationFeatureClassDescriptionClass();

            if ((ocDescription.ClassExtensionCLSID.Value.ToString() == uid.Value.ToString()) && (ocDescription.ClassExtensionCLSID.SubType == uid.SubType))
            {
                return(true);
            }

            ocDescription = new DimensionClassDescriptionClass();
            if ((ocDescription.ClassExtensionCLSID.Value.ToString() == uid.Value.ToString()) && (ocDescription.ClassExtensionCLSID.SubType == uid.SubType))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        private IFields method_1()
        {
            if (NewObjectClassHelper.m_pObjectClassHelper.IsFeatureClass)
            {
                IFeatureClassDescription description;
                IFields      requiredFields;
                IGeometryDef geometryDef;
                if (NewObjectClassHelper.m_pObjectClassHelper.FeatureType == esriFeatureType.esriFTSimple)
                {
                    description    = new FeatureClassDescriptionClass();
                    requiredFields = (description as IObjectClassDescription).RequiredFields;
                    IField field = requiredFields.get_Field(requiredFields.FindField(description.ShapeFieldName));
                    geometryDef = (field as IFieldEdit2).GeometryDef;
                    (geometryDef as IGeometryDefEdit).GeometryType_2 =
                        NewObjectClassHelper.m_pObjectClassHelper.ShapeType;
                    (field as IFieldEdit).GeometryDef_2 = geometryDef as IGeometryDefEdit;
                    return(requiredFields);
                }
                if (NewObjectClassHelper.m_pObjectClassHelper.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    description    = new AnnotationFeatureClassDescriptionClass();
                    requiredFields = (description as IObjectClassDescription).RequiredFields;
                    geometryDef    =
                        (requiredFields.get_Field(requiredFields.FindField(description.ShapeFieldName)) as IFieldEdit2)
                        .GeometryDef;
                    return(requiredFields);
                }
                if (NewObjectClassHelper.m_pObjectClassHelper.FeatureType == esriFeatureType.esriFTDimension)
                {
                    description    = new DimensionClassDescriptionClass();
                    requiredFields = (description as IObjectClassDescription).RequiredFields;
                    geometryDef    =
                        (requiredFields.get_Field(requiredFields.FindField(description.ShapeFieldName)) as IFieldEdit2)
                        .GeometryDef;
                    return(requiredFields);
                }
                return(null);
            }
            IObjectClassDescription description2 = new FeatureClassDescriptionClass();

            return(description2.RequiredFields);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 根据参考注记层新建注记层
        /// </summary>
        /// <param name="targetName">创建注记图层的名称</param>
        /// <param name="pTargetWrksps">目标工作空间</param>
        /// <param name="pTargetDs">所属目标数据集</param>
        /// <param name="pRefAnnoFtCls">参考图层</param>
        /// <returns></returns>
        private static IFeatureClass CreateAnnotationClass(string targetName, IFeatureWorkspace pTargetWrksps, IFeatureDataset pTargetDs, IFeatureClass pRefAnnoFtCls, out string msg)
        {
            msg = "";
            try
            {
                IFeatureWorkspaceAnno pAnnoWrksps = pTargetWrksps as IFeatureWorkspaceAnno;
                if (pAnnoWrksps == null || pRefAnnoFtCls == null)
                {
                    return(null);
                }
                if (pRefAnnoFtCls.Extension is IAnnotationClassExtension pAnnoExten)
                {
                    IClone pClone = pAnnoExten.AnnoProperties as IClone;
                    IAnnotateLayerPropertiesCollection pAnnoProCol = (IAnnotateLayerPropertiesCollection)pClone.Clone();

                    esriUnits           eUnits    = pAnnoExten.ReferenceScaleUnits;
                    double              dbScale   = pAnnoExten.ReferenceScale;
                    IGraphicsLayerScale pGraScale = new GraphicsLayerScaleClass
                    {
                        ReferenceScale = dbScale,
                        Units          = eUnits
                    };
                    pClone = pAnnoExten.SymbolCollection as IClone;
                    ISymbolCollection pSymbolCol = (ISymbolCollection)pClone.Clone();

                    pClone = pRefAnnoFtCls.Fields as IClone;
                    IFields pFields = (IFields)pClone.Clone();

                    IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescriptionClass();

                    IDataset pDs = (IDataset)pRefAnnoFtCls;
                    return(pAnnoWrksps.CreateAnnotationClass(targetName, pFields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, pRefAnnoFtCls.ShapeFieldName,
                                                             null, pTargetDs, null, pAnnoProCol, pGraScale, pSymbolCol, false));
                }
                return(null);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(null);
            }
        }
Ejemplo n.º 9
0
        private bool CreateFeatCls(IFeatureDataset featureDataset, IFeatureClass sourceFeatCls, string strTagetName, out Exception err)
        {
            try
            {
                err = null;
                IFeatureWorkspace featureWorkspace = featureDataset.Workspace as IFeatureWorkspace;

                //取源图层字段,并添加字段FromDate(生效日期),ToDate(失效日期),SourceOID(现势库对应数据OID),State(更新变化状态)
                IFields     pFields     = (sourceFeatCls.Fields as IClone).Clone() as IFields;
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

                IField     newfield  = new FieldClass();           //字段对象
                IFieldEdit fieldEdit = newfield as IFieldEdit;     //字段编辑对象
                fieldEdit.Name_2      = "FromDate";
                fieldEdit.AliasName_2 = "生效日期";
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(newfield);

                newfield              = new FieldClass();       //字段对象
                fieldEdit             = newfield as IFieldEdit; //字段编辑对象
                fieldEdit.Name_2      = "ToDate";
                fieldEdit.AliasName_2 = "失效日期";
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(newfield);

                newfield              = new FieldClass();       //字段对象
                fieldEdit             = newfield as IFieldEdit; //字段编辑对象
                fieldEdit.Name_2      = "SourceOID";
                fieldEdit.AliasName_2 = "现势库对应数据OID";
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.AddField(newfield);

                newfield              = new FieldClass();       //字段对象
                fieldEdit             = newfield as IFieldEdit; //字段编辑对象
                fieldEdit.Name_2      = "State";
                fieldEdit.AliasName_2 = "更新变化状态";
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.AddField(newfield);

                newfield                 = new FieldClass();       //字段对象
                fieldEdit                = newfield as IFieldEdit; //字段编辑对象
                fieldEdit.Name_2         = "VERSION";
                fieldEdit.AliasName_2    = "更新版本号";
                fieldEdit.DefaultValue_2 = 0;
                fieldEdit.IsNullable_2   = false;
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.AddField(newfield);


                if (sourceFeatCls.FeatureType == esriFeatureType.esriFTSimple)
                {
                    featureDataset.CreateFeatureClass(strTagetName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                }
                else if (sourceFeatCls.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    IObjectClassDescription pObjectClassDesc = new AnnotationFeatureClassDescriptionClass();
                    UID pCLSID    = pObjectClassDesc.InstanceCLSID;
                    UID pExtCLSID = pObjectClassDesc.ClassExtensionCLSID;
                    IFeatureWorkspaceAnno pFeatWorkspaceAnno = (IFeatureWorkspaceAnno)featureWorkspace;
                    IAnnoClass            pAnnoCls           = (IAnnoClass)sourceFeatCls.Extension;
                    IGraphicsLayerScale   pRefScale          = new GraphicsLayerScaleClass();

                    // 设置参考比例尺的相关参数

                    pRefScale.ReferenceScale = pAnnoCls.ReferenceScale;
                    pRefScale.Units          = pAnnoCls.ReferenceScaleUnits;

                    pFeatWorkspaceAnno.CreateAnnotationClass(strTagetName, pFieldsEdit,
                                                             pCLSID, pExtCLSID, sourceFeatCls.ShapeFieldName,
                                                             "", featureDataset, null, pAnnoCls.AnnoProperties,
                                                             pRefScale, pAnnoCls.SymbolCollection, false);
                }
                return(true);
            }
            catch (Exception e)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                //********************************************************************
                err = e;
                return(false);
            }
        }
        protected override void OnClick()
        {
            try
            {
                if (this.pGxApp.Selection.Count != 1)
                {
                    return;
                }


                IGxObject pGxObject = this.pGxApp.SelectedObject;


                if (!(pGxObject is IGxDataset))
                {
                    return;
                }

                IGxDataset pGxDataset = pGxObject as IGxDataset;
                if (pGxDataset == null)
                {
                    return;
                }

                if (((pGxObject as IGxDataset).Type) != esriDatasetType.esriDTFeatureClass)
                {
                    return;
                }

                try
                {
                    IDataset a = pGxDataset.Dataset;
                }
                catch (COMException COMex)
                {
                    if (COMex.ErrorCode == -2147467259)
                    {
                        if (MessageBox.Show("Not found component register so I don't see the UID: do I have to remove class extension? Are you sure?", "Remove class extension", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            try
                            {
                                IGxObject gxObject = pGxObject.Parent;
                                if (!(gxObject is IGxDatabase2))
                                {
                                    gxObject = gxObject.Parent;
                                }

                                IFeatureWorkspaceSchemaEdit featureWorkspaceSchemaEdit = ((gxObject as IGxDatabase2).Workspace) as IFeatureWorkspaceSchemaEdit;
                                featureWorkspaceSchemaEdit.AlterClassExtensionCLSID(pGxDataset.DatasetName.Name, null, null);

                                IObjectClassDescription featureClassDescription = new FeatureClassDescriptionClass();
                                featureWorkspaceSchemaEdit.AlterInstanceCLSID(pGxDataset.DatasetName.Name, featureClassDescription.InstanceCLSID);

                                MessageBox.Show("Class extension removed: success! Restart ArcCatalog!", "Remove Class Extension", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Error " + ex.Message);
                                return;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error " + COMex.ErrorCode.ToString() + ": " + COMex.Message);
                    }

                    return;
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                    return;
                }


                if (!(pGxDataset.Dataset is IClass))
                {
                    return;
                }

                IClass pClass = pGxDataset.Dataset as IClass;

                if (pClass.EXTCLSID == null)
                {
                    MessageBox.Show("No class extension!");
                    return;
                }
                else
                {
                    IObjectClassDescription ocDescription = new AnnotationFeatureClassDescriptionClass();
                    if ((pClass.EXTCLSID.Value.ToString() == ocDescription.ClassExtensionCLSID.Value.ToString()) && (pClass.EXTCLSID.SubType == ocDescription.ClassExtensionCLSID.SubType))
                    {
                        MessageBox.Show("Class extension well-know: I don't remove it (annotation)!", "Remove Class Extension", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    ocDescription = new DimensionClassDescriptionClass();
                    if ((pClass.EXTCLSID.Value.ToString() == ocDescription.ClassExtensionCLSID.Value.ToString()) && (pClass.EXTCLSID.SubType == ocDescription.ClassExtensionCLSID.SubType))
                    {
                        MessageBox.Show("Class extension well-know: I don't remove it (dimension)!", "Remove Class Extension", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }



                    if (MessageBox.Show(string.Format("Class extension: {0}: do I have to remove class extension?", pClass.EXTCLSID.Value.ToString()), "Remove Class Extension", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        if (this.RemoveClsExt(pClass))
                        {
                            MessageBox.Show("Class extension removed: success!", "Remove Class Extension", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Class extension removed: error! I have problem with exclusive schema lock ", "Remove Class Extension", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message.ToString());
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 创建注记层
        /// </summary>
        /// <param name="strFeaClsName">注记层名称</param>
        /// <param name="destDataset">待创建的注记层所在的featuredataset</param>
        /// <param name="ipInputFields">注记层字段</param>
        public static IFeatureClass CreateAnnotation(IFeatureClass pInputCls, IFeatureDataset destDataset, IFields ipInputFields)
        {
            try
            {
                //要素类标识信息
                IObjectClassDescription  ipObjectClassDesc = new AnnotationFeatureClassDescription();
                IFeatureClassDescription ipFeatClassDesc   = (IFeatureClassDescription)ipObjectClassDesc;


                IAnnoClass pAnnoClass = pInputCls.Extension as IAnnoClass;
                double     scale      = pAnnoClass.ReferenceScale;


                IUID ipCLSID = ipObjectClassDesc.InstanceCLSID;
                ipCLSID.Value = "esriCore.AnnotationFeature";


                IUID ipExtCLSID = ipObjectClassDesc.ClassExtensionCLSID;
                ipExtCLSID.Value = "esriCore.AnnotationFeatureClassExtension";

                //IField ipField;
                IFields     ipFields     = ipObjectClassDesc.RequiredFields;
                IFieldsEdit ipFieldsEdit = (IFieldsEdit)ipFields;
                int         numFields    = ipInputFields.FieldCount;

                esriFieldType type;
                for (int i = 0; i < numFields; i++)
                {
                    IField ipField = ipInputFields.get_Field(i);
                    type = ipField.Type;
                    if (type != esriFieldType.esriFieldTypeOID && type != esriFieldType.esriFieldTypeGeometry)
                    {
                        string fldName  = ipField.Name;
                        int    fldIndex = ipFields.FindField(fldName);

                        if (fldIndex == -1)
                        {
                            ipFieldsEdit.AddField(ipField);
                        }
                    }
                }

                //工作空间
                IWorkspace            ipWorkspace            = destDataset.Workspace;
                IFeatureWorkspaceAnno ipFeatureWorkspaceAnno = (IFeatureWorkspaceAnno)ipWorkspace;


                //显示比例
                IGraphicsLayerScale ipGraphicsLayerScale = new GraphicsLayerScaleClass();
                ipGraphicsLayerScale.ReferenceScale = scale;
                ipGraphicsLayerScale.Units          = pAnnoClass.ReferenceScaleUnits;

                //符号信息
                //' set up symbol collection
                ISymbolCollection pSymbolColl = new SymbolCollectionClass();

                ITextSymbol myTxtSym = new TextSymbolClass();
                //Set the font for myTxtSym
                stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
                IFont            pFt    = (IFont)myFont;
                pFt.Name = "Courier New";

                myTxtSym.Font = myFont;

                // Set the Color for myTxtSym to be Dark Red
                IRgbColor myColor = new RgbColorClass();
                myColor.Red    = 150;
                myColor.Green  = 0;
                myColor.Blue   = 0;
                myTxtSym.Color = myColor;

                // Set other properties for myTxtSym
                myTxtSym.Angle               = 0;
                myTxtSym.RightToLeft         = false;
                myTxtSym.VerticalAlignment   = esriTextVerticalAlignment.esriTVABaseline;
                myTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;
                myTxtSym.Size = 9;

                ISymbol pSymbol = (ISymbol)myTxtSym;
                pSymbolColl.set_Symbol(0, pSymbol);


                //set up the annotation labeling properties including the expression
                IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();
                pAnnoProps.FeatureLinked = true;
                pAnnoProps.AddUnplacedToGraphicsContainer = false;
                pAnnoProps.CreateUnplacedElements         = true;
                pAnnoProps.DisplayAnnotation = true;
                pAnnoProps.UseOutput         = true;

                ILabelEngineLayerProperties pLELayerProps       = (ILabelEngineLayerProperties)pAnnoProps;
                IAnnotationExpressionEngine aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();
                pLELayerProps.ExpressionParser   = aAnnoVBScriptEngine;
                pLELayerProps.Expression         = "[DESCRIPTION]";
                pLELayerProps.IsExpressionSimple = true;
                pLELayerProps.Offset             = 0;
                pLELayerProps.SymbolID           = 0;
                pLELayerProps.Symbol             = myTxtSym;

                IAnnotateLayerTransformationProperties pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
                double dRefScale = ipGraphicsLayerScale.ReferenceScale;
                pATP.ReferenceScale = dRefScale;
                pATP.Units          = esriUnits.esriMeters;
                pATP.ScaleRatio     = 1;

                IAnnotateLayerPropertiesCollection pAnnoPropsColl = new AnnotateLayerPropertiesCollectionClass();
                pAnnoPropsColl.Add(pAnnoProps);

                //' use the AnnotationFeatureClassDescription co - class to get the list of required fields and the default name of the shape field
                IObjectClassDescription  pOCDesc = new AnnotationFeatureClassDescriptionClass();
                IFeatureClassDescription pFDesc  = (IFeatureClassDescription)pOCDesc;

                IFields pReqFields       = pOCDesc.RequiredFields;
                IUID    pInstCLSID       = pOCDesc.InstanceCLSID;
                IUID    pExtCLSID        = pOCDesc.ClassExtensionCLSID;
                string  bsShapeFieldName = pFDesc.ShapeFieldName;

                IDataset pDs = (IDataset)pInputCls;

                //创建
                string        bstName  = ipFeatClassDesc.ShapeFieldName;
                IFeatureClass pOutFcls =
                    ipFeatureWorkspaceAnno.CreateAnnotationClass(pDs.Name, ipFields, pOCDesc.InstanceCLSID,
                                                                 pOCDesc.ClassExtensionCLSID, pInputCls.ShapeFieldName, "", destDataset, null, pAnnoPropsColl,
                                                                 ipGraphicsLayerScale, pSymbolColl, true);
                return(pOutFcls);
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(null);
            }
            return(null);
        }
Ejemplo n.º 12
0
        //创建featureclass
        private IFeatureClass CreateFeatureClass(string name, IFeatureClass pFeaCls, IFeatureDataset pFeaDataset, IFeatureWorkspace pWks)
        {
            UID uidCLSID  = null;
            UID uidCLSEXT = null;


            try
            {
                IObjectClassDescription pObjCls = null;
                if (uidCLSID == null)
                {
                    //esriGeometryType GeometryType;
                    uidCLSID = new UIDClass();
                    switch (pFeaCls.FeatureType)
                    {
                    case (esriFeatureType.esriFTSimple):
                        uidCLSID.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
                        break;

                    case (esriFeatureType.esriFTSimpleJunction):
                        //GeometryType = esriGeometryType.esriGeometryPoint;
                        uidCLSID.Value = "{CEE8D6B8-55FE-11D1-AE55-0000F80372B4}";
                        break;

                    case (esriFeatureType.esriFTComplexJunction):
                        uidCLSID.Value = "{DF9D71F4-DA32-11D1-AEBA-0000F80372B4}";
                        break;

                    case (esriFeatureType.esriFTSimpleEdge):
                        //GeometryType = esriGeometryType.esriGeometryPolyline;
                        uidCLSID.Value = "{E7031C90-55FE-11D1-AE55-0000F80372B4}";
                        break;

                    case (esriFeatureType.esriFTComplexEdge):
                        //GeometryType = esriGeometryType.esriGeometryPolyline;
                        uidCLSID.Value = "{A30E8A2A-C50B-11D1-AEA9-0000F80372B4}";
                        break;

                    case (esriFeatureType.esriFTAnnotation):
                        //GeometryType = esriGeometryType.esriGeometryPolygon;
                        uidCLSID.Value = "{E3676993-C682-11D2-8A2A-006097AFF44E}";
                        break;

                    case (esriFeatureType.esriFTDimension):
                        //GeometryType = esriGeometryType.esriGeometryPolygon;
                        uidCLSID.Value = "{496764FC-E0C9-11D3-80CE-00C04F601565}";
                        break;
                    }
                }

                // 设置 uidCLSEXT (if Null)
                if (uidCLSEXT == null)
                {
                    switch (pFeaCls.FeatureType)
                    {
                    case (esriFeatureType.esriFTAnnotation):
                        uidCLSEXT       = new UIDClass();
                        uidCLSEXT.Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}";
                        pObjCls         = new AnnotationFeatureClassDescriptionClass();
                        break;

                    case (esriFeatureType.esriFTDimension):
                        uidCLSEXT       = new UIDClass();
                        uidCLSEXT.Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}";
                        break;
                    }
                }
                //IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                IFieldChecker fdCheker = new FieldCheckerClass();//yjl20110804 add
                pEnumFieldError            = null;
                pFixedField                = null;
                fdCheker.ValidateWorkspace = pWks as IWorkspace;
                fdCheker.Validate(pFeaCls.Fields, out pEnumFieldError, out pFixedField);

                //string strShapeFieldName = pfeaturelayer.FeatureClass.ShapeFieldName;//geometry字段名
                //string[] strShapeNames = strShapeFieldName.Split('.');
                //strShapeFieldName = strShapeNames[strShapeNames.GetLength(0) - 1];

                IFields pFields = new FieldsClass();
                if (pObjCls != null)
                {
                    IFeatureClassDescription pClsDes = pObjCls as IFeatureClassDescription;
                    pFields = pObjCls.RequiredFields;
                }

                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

                for (int i = 0; i < pFeaCls.Fields.FieldCount; i++)
                {
                    IField   pf            = pFeaCls.Fields.get_Field(i);
                    string   strFieldName  = pf.Name;
                    string[] strFieldNames = strFieldName.Split('.');

                    bool blnfind = false;
                    for (int j = 0; j < pFields.FieldCount; j++)
                    {
                        IField   pf2        = pFields.get_Field(j);
                        string[] strfields2 = pf2.Name.Split('.');
                        if (strfields2[strfields2.GetLength(0) - 1].ToUpper() == strFieldNames[strFieldNames.GetLength(0) - 1].ToUpper())
                        {
                            blnfind = true;
                            break;
                        }
                    }

                    if (blnfind)
                    {
                        continue;
                    }

                    if (pFeaCls.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        if (pFeaCls.ShapeFieldName == pf.Name)
                        {
                            continue;
                        }
                    }

                    if (pFeaCls.LengthField != null)
                    {
                        if (pFeaCls.LengthField.Name == pf.Name)
                        {
                            continue;
                        }
                    }
                    if (pFeaCls.AreaField != null)
                    {
                        if (pFeaCls.AreaField.Name == pf.Name)
                        {
                            continue;
                        }
                    }

                    IClone     pClone         = pFeaCls.Fields.get_Field(i) as IClone;
                    IField     pTempField     = pClone.Clone() as IField;
                    IFieldEdit pTempFieldEdit = pTempField as IFieldEdit;

                    if (pFieldsEdit.FindField(strFieldNames[strFieldNames.GetLength(0) - 1]) > -1)
                    {
                        continue;
                    }

                    pTempFieldEdit.Name_2 = strFieldNames[strFieldNames.GetLength(0) - 1];
                    pFieldsEdit.AddField(pTempField);
                }

                string   strShapeFieldName = pFeaCls.ShapeFieldName;
                string[] strShapeNames     = strShapeFieldName.Split('.');
                strShapeFieldName = strShapeNames[strShapeNames.GetLength(0) - 1];

                //修改geometrydef
                IField pFieldShape = pFeaCls.Fields.get_Field(pFeaCls.Fields.FindField(pFeaCls.ShapeFieldName));

                if (pFieldShape != null)
                {
                    IFieldEdit pFieldShapeEdit = pFields.get_Field(pFields.FindField(strShapeFieldName)) as IFieldEdit;
                    pFieldShapeEdit.GeometryDef_2 = pFieldShape.GeometryDef;
                }

                IGeometryDef pGeoDef  = pFieldShape.GeometryDef;
                double       dblIndex = pGeoDef.get_GridSize(0);

                //添加两个字段一个时间 一个名称
                if (pFields.FindField("ImportTime") < 0)
                {
                    IField     pNewField1 = new FieldClass();
                    IFieldEdit pNewEdit1  = pNewField1 as IFieldEdit;
                    pNewEdit1.Name_2      = "ImportTime";
                    pNewEdit1.AliasName_2 = "入库时间";
                    pNewEdit1.Type_2      = esriFieldType.esriFieldTypeDate;
                    pFieldsEdit.AddField(pNewField1);
                }

                if (pFields.FindField("ImportUser") < 0)
                {
                    IField     pNewField2 = new FieldClass();
                    IFieldEdit pNewEdit2  = pNewField2 as IFieldEdit;
                    pNewEdit2.Name_2      = "ImportUser";
                    pNewEdit2.AliasName_2 = "入库人";
                    pNewEdit2.Type_2      = esriFieldType.esriFieldTypeString;
                    pFieldsEdit.AddField(pNewField2);
                }

                IFeatureClass targetFeatureclass = null;


                if (pFeaCls.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    IAnnoClass pAnno = pFeaCls.Extension as IAnnoClass;

                    IFeatureWorkspaceAnno pWksAnno = pWks as IFeatureWorkspaceAnno;
                    IGraphicsLayerScale   pGl      = new GraphicsLayerScaleClass();
                    pGl.ReferenceScale = pAnno.ReferenceScale;
                    pGl.Units          = pAnno.ReferenceScaleUnits;
                    targetFeatureclass = pWksAnno.CreateAnnotationClass(name, pFields, pFeaCls.CLSID, pFeaCls.EXTCLSID, strShapeFieldName, "", pFeaDataset, null, pAnno.AnnoProperties, pGl, pAnno.SymbolCollection, false);
                }
                else
                {
                    if (pFeaDataset != null)
                    {
                        targetFeatureclass = pFeaDataset.CreateFeatureClass(name, pFixedField, uidCLSID, uidCLSEXT, pFeaCls.FeatureType, strShapeFieldName, "");
                    }
                    else
                    {
                        targetFeatureclass = pWks.CreateFeatureClass(name, pFixedField, uidCLSID, uidCLSEXT, pFeaCls.FeatureType, strShapeFieldName, "");
                    }
                }

                return(targetFeatureclass);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Cannot create a low precision dataset in a high precision database.")
                {
                    MessageBox.Show("数据必须是ArcGis9.2的数据,请将数据处理成ArcGis9.2的数据!");
                }
            }
            IFeatureClass featureclass = null;

            return(featureclass);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 创建注记层
        /// </summary>
        /// <param name="strFeaClsName">注记层名称</param>
        /// <param name="destDataset">待创建的注记层所在的featuredataset</param>
        /// <param name="ipInputFields">注记层字段</param>
        public static IFeatureClass CreateAnnotation(IFeatureClass pInputCls, IFeatureDataset destDataset, IFields ipInputFields)
        {
            try
            {
                //要素类标识信息
                IObjectClassDescription ipObjectClassDesc = new AnnotationFeatureClassDescription();
                IFeatureClassDescription ipFeatClassDesc = (IFeatureClassDescription)ipObjectClassDesc;

                IAnnoClass pAnnoClass = pInputCls.Extension as IAnnoClass;
                double scale = pAnnoClass.ReferenceScale;

                IUID ipCLSID = ipObjectClassDesc.InstanceCLSID;
                ipCLSID.Value = "esriCore.AnnotationFeature";

                IUID ipExtCLSID = ipObjectClassDesc.ClassExtensionCLSID;
                ipExtCLSID.Value = "esriCore.AnnotationFeatureClassExtension";

                //IField ipField;
                IFields ipFields = ipObjectClassDesc.RequiredFields;
                IFieldsEdit ipFieldsEdit = (IFieldsEdit)ipFields;
                int numFields = ipInputFields.FieldCount;

                esriFieldType type;
                for (int i = 0; i < numFields; i++)
                {
                    IField ipField = ipInputFields.get_Field(i);
                    type = ipField.Type;
                    if (type != esriFieldType.esriFieldTypeOID && type != esriFieldType.esriFieldTypeGeometry)
                    {
                        string fldName = ipField.Name;
                        int fldIndex = ipFields.FindField(fldName);

                        if (fldIndex == -1)
                            ipFieldsEdit.AddField(ipField);
                    }
                }

                //工作空间
                IWorkspace ipWorkspace = destDataset.Workspace;
                IFeatureWorkspaceAnno ipFeatureWorkspaceAnno = (IFeatureWorkspaceAnno)ipWorkspace;

                //显示比例
                IGraphicsLayerScale ipGraphicsLayerScale = new GraphicsLayerScaleClass();
                ipGraphicsLayerScale.ReferenceScale = scale;
                ipGraphicsLayerScale.Units = pAnnoClass.ReferenceScaleUnits;

                //符号信息
                //' set up symbol collection
                ISymbolCollection pSymbolColl = new SymbolCollectionClass();

                ITextSymbol myTxtSym = new TextSymbolClass();
                //Set the font for myTxtSym
                stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
                IFont pFt = (IFont)myFont;
                pFt.Name = "Courier New";

                myTxtSym.Font = myFont;

                // Set the Color for myTxtSym to be Dark Red
                IRgbColor myColor = new RgbColorClass();
                myColor.Red = 150;
                myColor.Green = 0;
                myColor.Blue = 0;
                myTxtSym.Color = myColor;

                // Set other properties for myTxtSym
                myTxtSym.Angle = 0;
                myTxtSym.RightToLeft = false;
                myTxtSym.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline;
                myTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;
                myTxtSym.Size = 9;

                ISymbol pSymbol = (ISymbol)myTxtSym;
                pSymbolColl.set_Symbol(0, pSymbol);

                //set up the annotation labeling properties including the expression
                IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();
                pAnnoProps.FeatureLinked = true;
                pAnnoProps.AddUnplacedToGraphicsContainer = false;
                pAnnoProps.CreateUnplacedElements = true;
                pAnnoProps.DisplayAnnotation = true;
                pAnnoProps.UseOutput = true;

                ILabelEngineLayerProperties pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps;
                IAnnotationExpressionEngine aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();
                pLELayerProps.ExpressionParser = aAnnoVBScriptEngine;
                pLELayerProps.Expression = "[DESCRIPTION]";
                pLELayerProps.IsExpressionSimple = true;
                pLELayerProps.Offset = 0;
                pLELayerProps.SymbolID = 0;
                pLELayerProps.Symbol = myTxtSym;

                IAnnotateLayerTransformationProperties pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
                double dRefScale = ipGraphicsLayerScale.ReferenceScale;
                pATP.ReferenceScale = dRefScale;
                pATP.Units = esriUnits.esriMeters;
                pATP.ScaleRatio = 1;

                IAnnotateLayerPropertiesCollection pAnnoPropsColl = new AnnotateLayerPropertiesCollectionClass();
                pAnnoPropsColl.Add(pAnnoProps);

                //' use the AnnotationFeatureClassDescription co - class to get the list of required fields and the default name of the shape field
                IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescriptionClass();
                IFeatureClassDescription pFDesc = (IFeatureClassDescription)pOCDesc;

                IFields pReqFields = pOCDesc.RequiredFields;
                IUID pInstCLSID = pOCDesc.InstanceCLSID;
                IUID pExtCLSID = pOCDesc.ClassExtensionCLSID;
                string bsShapeFieldName = pFDesc.ShapeFieldName;

                IDataset pDs = (IDataset)pInputCls;

                //创建
                string bstName = ipFeatClassDesc.ShapeFieldName;
                IFeatureClass pOutFcls =
                    ipFeatureWorkspaceAnno.CreateAnnotationClass(pDs.Name, ipFields, pOCDesc.InstanceCLSID,
                                                                 pOCDesc.ClassExtensionCLSID, pInputCls.ShapeFieldName, "", destDataset, null, pAnnoPropsColl,
                                                                 ipGraphicsLayerScale, pSymbolColl, true);
                return pOutFcls;
            }
            catch(Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return null;
            }
            return null;
        }
Ejemplo n.º 14
0
 public void InitFields()
 {
     if (this.m_IsFeatureClass)
     {
         IFeatureClassDescription description;
         IField            field;
         IGeometryDef      geometryDef;
         ISpatialReference spatialReference;
         if (this.m_FeatreType == esriFeatureType.esriFTSimple)
         {
             description         = new FeatureClassDescriptionClass();
             this.ShapeFieldName = description.ShapeFieldName;
             this.m_pFieds       = (description as IObjectClassDescription).RequiredFields;
             field       = this.m_pFieds.get_Field(this.m_pFieds.FindField(description.ShapeFieldName));
             geometryDef = field.GeometryDef;
             if (this.ifeatureDataset_0 != null)
             {
                 spatialReference = (this.ifeatureDataset_0 as IGeoDataset).SpatialReference;
             }
             else
             {
                 spatialReference = geometryDef.SpatialReference;
                 this.method_0(spatialReference);
             }
             (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
             (field as IFieldEdit).GeometryDef_2 = geometryDef;
         }
         else if (this.m_FeatreType == esriFeatureType.esriFTDimension)
         {
             description         = new DimensionClassDescriptionClass();
             this.ShapeFieldName = description.ShapeFieldName;
             this.m_pFieds       = (description as IObjectClassDescription).RequiredFields;
             field       = this.m_pFieds.get_Field(this.m_pFieds.FindField(description.ShapeFieldName));
             geometryDef = field.GeometryDef;
             if (this.ifeatureDataset_0 != null)
             {
                 spatialReference = (this.ifeatureDataset_0 as IGeoDataset).SpatialReference;
             }
             else
             {
                 spatialReference = geometryDef.SpatialReference;
                 this.method_0(spatialReference);
             }
             (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
             (field as IFieldEdit).GeometryDef_2 = geometryDef;
         }
         else if (this.m_FeatreType == esriFeatureType.esriFTAnnotation)
         {
             description         = new AnnotationFeatureClassDescriptionClass();
             this.ShapeFieldName = description.ShapeFieldName;
             this.m_pFieds       = (description as IObjectClassDescription).RequiredFields;
             field       = this.m_pFieds.get_Field(this.m_pFieds.FindField(description.ShapeFieldName));
             geometryDef = field.GeometryDef;
             if (this.ifeatureDataset_0 != null)
             {
                 spatialReference = (this.ifeatureDataset_0 as IGeoDataset).SpatialReference;
             }
             else
             {
                 spatialReference = geometryDef.SpatialReference;
                 this.method_0(spatialReference);
             }
             (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
             (field as IFieldEdit).GeometryDef_2 = geometryDef;
         }
     }
     else
     {
         IObjectClassDescription description2 = new ObjectClassDescriptionClass();
         this.m_pFieds = description2.RequiredFields;
     }
 }
Ejemplo n.º 15
0
        private bool CreateFeatCls(IFeatureWorkspace featureWorkspace, IFeatureClass sourceFeatCls, string strTagetName, out Exception err)
        {
            IFields pFields = null;
            IObjectClassDescription pObjectClassDesc = null;
            UID pCLSID    = null;
            UID pExtCLSID = null;
            IFeatureWorkspaceAnno pFeatWorkspaceAnno = null;
            IAnnoClass            pAnnoCls           = null;
            IGraphicsLayerScale   pRefScale          = null;

            try
            {
                err = null;
                //cyf 20110706 modify:提取数据时,创建本地数据库必须去掉用户名
                if (strTagetName.Contains("."))
                {
                    strTagetName = strTagetName.Substring(strTagetName.IndexOf('.') + 1);
                }
                //end
                //取源图层字段,并添加字段FromDate(生效日期),ToDate(失效日期),SourceOID(现势库对应数据OID),State(更新变化状态)
                pFields = (sourceFeatCls.Fields as IClone).Clone() as IFields;
                if (sourceFeatCls.FeatureType == esriFeatureType.esriFTSimple)
                {
                    featureWorkspace.CreateFeatureClass(strTagetName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                }
                else if (sourceFeatCls.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    pObjectClassDesc   = new AnnotationFeatureClassDescriptionClass();
                    pCLSID             = pObjectClassDesc.InstanceCLSID;
                    pExtCLSID          = pObjectClassDesc.ClassExtensionCLSID;
                    pFeatWorkspaceAnno = (IFeatureWorkspaceAnno)featureWorkspace;
                    pAnnoCls           = (IAnnoClass)sourceFeatCls.Extension;
                    pRefScale          = new GraphicsLayerScaleClass();

                    // 设置参考比例尺的相关参数

                    pRefScale.ReferenceScale = pAnnoCls.ReferenceScale;
                    pRefScale.Units          = pAnnoCls.ReferenceScaleUnits;
                    pFeatWorkspaceAnno.CreateAnnotationClass(strTagetName, pFields,
                                                             pCLSID, pExtCLSID, sourceFeatCls.ShapeFieldName,
                                                             "", null, null, pAnnoCls.AnnoProperties,
                                                             pRefScale, pAnnoCls.SymbolCollection, false);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pObjectClassDesc);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pRefScale);
                    pObjectClassDesc   = null;
                    pFeatWorkspaceAnno = null;
                    pAnnoCls           = null;
                    pRefScale          = null;
                    pCLSID             = null;
                    pExtCLSID          = null;
                }
                pFields = null;
                return(true);
            }
            catch (Exception e)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                //********************************************************************
                err = e;
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pObjectClassDesc);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pRefScale);
                pObjectClassDesc   = null;
                pFeatWorkspaceAnno = null;
                pAnnoCls           = null;
                pRefScale          = null;
                pCLSID             = null;
                pExtCLSID          = null;
                pFields            = null;
                return(false);
            }
        }
Ejemplo n.º 16
0
        protected override void OnClick()
        {
            try
            {
                if (this.pGxApp.Selection.Count != 1)
                {
                    return;
                }

                IGxObject pGxObject = this.pGxApp.SelectedObject;


                if (!(pGxObject is IGxDataset))
                {
                    return;
                }

                IGxDataset pGxDataset = pGxObject as IGxDataset;

                if (pGxDataset == null)
                {
                    return;
                }

                if (((pGxObject as IGxDataset).Type) != esriDatasetType.esriDTFeatureDataset)
                {
                    MessageBox.Show("Select a Feature Dataset!", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                IFeatureDataset   fDataset         = pGxDataset.Dataset as IFeatureDataset;
                IWorkspace2       workspace        = fDataset.Workspace as IWorkspace2;
                IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;


                DialogResult dialogResult =
                    MessageBox.Show($@"Remove custom extension for all Feature Classes in {fDataset.Name}", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dialogResult == DialogResult.Yes)
                {
                    IEnumDataset enumDataset = fDataset.Subsets;
                    IDataset     dataset     = enumDataset.Next();

                    IObjectClassDescription ocDescriptionAnnotation = new AnnotationFeatureClassDescriptionClass();
                    IObjectClassDescription ocDescriptionDimension  = new DimensionClassDescriptionClass();

                    while (dataset != null)
                    {
                        if (dataset is IClass)
                        {
                            IClass pClass = dataset as IClass;
                            if (pClass.EXTCLSID != null)
                            {
                                if ((pClass.EXTCLSID.Value.ToString().ToLower() != ocDescriptionAnnotation.ClassExtensionCLSID.Value.ToString().ToLower()) &&
                                    (pClass.EXTCLSID.SubType != ocDescriptionAnnotation.ClassExtensionCLSID.SubType) &&
                                    (pClass.EXTCLSID.Value.ToString().ToLower() != ocDescriptionDimension.ClassExtensionCLSID.Value.ToString().ToLower()) &&
                                    (pClass.EXTCLSID.SubType != ocDescriptionDimension.ClassExtensionCLSID.SubType))
                                {
                                    clsGenericStudioAT.RemoveClsExt(pClass);
                                }
                            }
                        }

                        dataset = enumDataset.Next();
                    }

                    MessageBox.Show("All Extension removed!", "Ok", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception errore)
            {
                MessageBox.Show(errore.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
Ejemplo n.º 17
0
        public void CreateAnnoFeatureClass(IFeatureDataset featureDs, string strObjNum)
        {
            //更换注记字体 用两个重要的属性
            //IAnnotateLayerPropertiesCollection,ISymbolCollection
            IFeatureWorkspace pFeatureWs = pAccessWorkSpace;

            IFeatureWorkspaceAnno pFeatureWorkspaceAnno;

            pFeatureWorkspaceAnno = (IFeatureWorkspaceAnno)pFeatureWs;

            //说明:要控制图层中的字体必须在图层建立的时候定义好字体
            ITextSymbol pTextSymbol, tTextSymbol;

            pTextSymbol = PublicFun.makeTextSymbol("Arial", 16);
            tTextSymbol = PublicFun.makeTextSymbol("宋体", 50);
            /////textsymbol

            IGraphicsLayerScale pGLS;

            pGLS                = new GraphicsLayerScaleClass();
            pGLS.Units          = esriUnits.esriMeters;
            pGLS.ReferenceScale = 500;

            IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();

            pAnnoProps.FeatureLinked = true;
            pAnnoProps.AddUnplacedToGraphicsContainer = false;
            pAnnoProps.CreateUnplacedElements         = false;
            pAnnoProps.DisplayAnnotation = true;
            pAnnoProps.UseOutput         = true;

            IAnnotationExpressionEngine aAnnoVBScriptEngine;

            aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();

            ILabelEngineLayerProperties pLELayerProps;

            pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps;
            pLELayerProps.ExpressionParser = aAnnoVBScriptEngine;
            pLELayerProps.Expression       = "[DESCRIPTION]";

            pLELayerProps.IsExpressionSimple = true;
            pLELayerProps.Offset             = 0;
            pLELayerProps.SymbolID           = 0;
            pLELayerProps.Symbol             = pTextSymbol;

            IAnnotateLayerTransformationProperties pATP;

            pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
            pATP.ReferenceScale = pGLS.ReferenceScale;
            pATP.Units          = esriUnits.esriMeters;
            pATP.ScaleRatio     = 300;

            IAnnotateLayerPropertiesCollection pAnnoPropsColl;

            pAnnoPropsColl = new AnnotateLayerPropertiesCollectionClass();
            pAnnoPropsColl.Add(pAnnoProps);

            IObjectClassDescription pOCDesc;

            pOCDesc = new AnnotationFeatureClassDescriptionClass();

            IFeatureClassDescription pFDesc;

            pFDesc = (IFeatureClassDescription)pOCDesc;

            ISymbolCollection pSymbolColl;

            pSymbolColl = new SymbolCollectionClass();
            pSymbolColl.set_Symbol(0, (ISymbol)pTextSymbol);
            pSymbolColl.set_Symbol(2, (ISymbol)tTextSymbol);

            IFields pFields = pOCDesc.RequiredFields;

            //添加注记类的附加字段
            this.addAnnoField(ref pFields, strObjNum);

            string          featureName = TableName;                    //注记要素集的名字
            IFeatureDataset pFeatureDataset;

            if (featureDs == null)
            {
                pFeatureDataset = pFeatureWs.CreateFeatureDataset(featureName + "_Anno", sPR);
            }
            else
            {
                pFeatureDataset = featureDs;
            }

            pFeatureWorkspaceAnno.CreateAnnotationClass(featureName, pFields, pOCDesc.InstanceCLSID,
                                                        pOCDesc.ClassExtensionCLSID, pFDesc.ShapeFieldName, "",
                                                        pFeatureDataset, null, pAnnoPropsColl, pGLS, pSymbolColl, true);
        }
Ejemplo n.º 18
0
 private void method_3(IMap imap_1, ILayer ilayer_0, string string_0, double double_1, IWorkspace iworkspace_1,
                       bool bool_0, bool bool_1, esriLabelWhichFeatures esriLabelWhichFeatures_1)
 {
     if ((iworkspace_1.Type != esriWorkspaceType.esriFileSystemWorkspace) && (ilayer_0 is IGeoFeatureLayer))
     {
         int num;
         IAnnotateLayerProperties     properties;
         IElementCollection           elements;
         IElementCollection           elements2;
         ILabelEngineLayerProperties2 properties2;
         IAnnotationLayer             layer2;
         IGeoFeatureLayer             layer = ilayer_0 as IGeoFeatureLayer;
         IFeatureClass                      featureClass         = layer.FeatureClass;
         IAnnotationLayerFactory            factory              = new FDOGraphicsLayerFactoryClass();
         ISymbolCollection2                 lcs                  = new SymbolCollectionClass();
         IAnnotateLayerPropertiesCollection propertiess          = new AnnotateLayerPropertiesCollectionClass();
         IAnnotateLayerPropertiesCollection annotationProperties = layer.AnnotationProperties;
         for (num = 0; num < annotationProperties.Count; num++)
         {
             annotationProperties.QueryItem(num, out properties, out elements, out elements2);
             if (properties != null)
             {
                 ISymbolIdentifier2 identifier;
                 propertiess.Add(properties);
                 properties2 = properties as ILabelEngineLayerProperties2;
                 IClone symbol = properties2.Symbol as IClone;
                 lcs.AddSymbol(symbol.Clone() as ISymbol, properties.Class + " " + num.ToString(), out identifier);
                 properties2.SymbolID = identifier.ID;
             }
         }
         properties  = null;
         properties2 = null;
         IGraphicsLayerScale scale = new GraphicsLayerScaleClass
         {
             ReferenceScale = double_1,
             Units          = imap_1.MapUnits
         };
         IFeatureClassDescription description  = new AnnotationFeatureClassDescriptionClass();
         IObjectClassDescription  description2 = description as IObjectClassDescription;
         IFields          requiredFields       = description2.RequiredFields;
         IGeometryDefEdit geometryDef          =
             requiredFields.get_Field(requiredFields.FindField(description.ShapeFieldName)).GeometryDef as
             IGeometryDefEdit;
         IGeoDataset dataset = featureClass as IGeoDataset;
         geometryDef.SpatialReference_2 = dataset.SpatialReference;
         IMapOverposter        overposter           = imap_1 as IMapOverposter;
         IOverposterProperties overposterProperties = overposter.OverposterProperties;
         if (bool_1)
         {
             this.method_2(iworkspace_1 as IFeatureWorkspaceAnno, featureClass.FeatureDataset, featureClass,
                           scale.ReferenceScale, scale.Units, propertiess, lcs as ISymbolCollection, string_0);
             layer2 = factory.OpenAnnotationLayer(iworkspace_1 as IFeatureWorkspace, featureClass.FeatureDataset,
                                                  string_0);
         }
         else
         {
             this.method_2(iworkspace_1 as IFeatureWorkspaceAnno, featureClass.FeatureDataset, null,
                           scale.ReferenceScale, scale.Units, propertiess, lcs as ISymbolCollection, string_0);
             layer2 = factory.OpenAnnotationLayer(iworkspace_1 as IFeatureWorkspace, featureClass.FeatureDataset,
                                                  string_0);
         }
         IActiveView    view          = imap_1 as IActiveView;
         IScreenDisplay screenDisplay = view.ScreenDisplay;
         (layer2 as IGraphicsLayer).Activate(screenDisplay);
         for (num = 0; num < propertiess.Count; num++)
         {
             propertiess.QueryItem(num, out properties, out elements, out elements2);
             if (properties != null)
             {
                 properties.FeatureLayer      = layer;
                 properties.GraphicsContainer = layer2 as IGraphicsContainer;
                 properties.AddUnplacedToGraphicsContainer = bool_0;
                 properties.CreateUnplacedElements         = true;
                 properties.DisplayAnnotation  = true;
                 properties.FeatureLinked      = bool_1;
                 properties.LabelWhichFeatures = esriLabelWhichFeatures_1;
                 properties.UseOutput          = true;
                 properties2                   = properties as ILabelEngineLayerProperties2;
                 properties2.SymbolID          = num;
                 properties2.AnnotationClassID = num;
                 IOverposterLayerProperties2 overposterLayerProperties =
                     properties2.OverposterLayerProperties as IOverposterLayerProperties2;
                 overposterLayerProperties.TagUnplaced = true;
             }
         }
         propertiess.Sort();
         IAnnotateMapProperties annoMapCmdProps = new AnnotateMapPropertiesClass
         {
             AnnotateLayerPropertiesCollection = propertiess
         };
         ITrackCancel trackCancel = new CancelTrackerClass();
         (imap_1.AnnotationEngine as IAnnotateMap2).Label(overposterProperties, annoMapCmdProps, imap_1,
                                                          trackCancel);
         for (num = 0; num < propertiess.Count; num++)
         {
             propertiess.QueryItem(num, out properties, out elements, out elements2);
             if (properties != null)
             {
                 properties.FeatureLayer = null;
             }
         }
         imap_1.AddLayer(layer2 as ILayer);
         layer.DisplayAnnotation = false;
         view.Refresh();
     }
 }