Example #1
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));
        }
        /// <summary>
        /// 创建标注
        /// </summary>
        /// <param name="feaName"></param>
        /// <param name="featureDataset"></param>
        /// <param name="feaworkspace"></param>
        /// <param name="fsEditAnno"></param>
        /// <param name="intScale"></param>
        public void createAnnoFeatureClass(string feaName, IFeatureDataset featureDataset, IFeatureWorkspace feaworkspace, IFieldsEdit fsEditAnno, int intScale)
        {
            //创建注记的特殊字段
            try
            {
                //注记的workSpace
                IFeatureWorkspaceAnno pFWSAnno = feaworkspace as IFeatureWorkspaceAnno; //标注操作空间

                IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass();               //图形比例接口
                pGLS.Units          = esriUnits.esriMeters;                             //图形比例设定
                pGLS.ReferenceScale = Convert.ToDouble(intScale);                       //创建注记必须要设置比例尺

                IFormattedTextSymbol myTextSymbol = new TextSymbolClass();              //文本格式接口
                ISymbol pSymbol = (ISymbol)myTextSymbol;                                //标记
                //Anno要素类必须有的缺省符号
                ISymbolCollection2 pSymbolColl = new SymbolCollectionClass();
                ISymbolIdentifier2 pSymID      = new SymbolIdentifierClass();
                pSymbolColl.AddSymbol(pSymbol, "Default", out pSymID);

                //Anno要素类的必要属性
                IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();
                pAnnoProps.CreateUnplacedElements = true;
                pAnnoProps.CreateUnplacedElements = true;
                pAnnoProps.DisplayAnnotation      = true;
                pAnnoProps.UseOutput = true;

                ILabelEngineLayerProperties pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps;
                pLELayerProps.Symbol             = pSymbol as ITextSymbol;
                pLELayerProps.SymbolID           = 0;
                pLELayerProps.IsExpressionSimple = true;
                pLELayerProps.Offset             = 0;
                pLELayerProps.SymbolID           = 0;

                IAnnotationExpressionEngine aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();
                pLELayerProps.ExpressionParser = aAnnoVBScriptEngine;
                pLELayerProps.Expression       = "[DESCRIPTION]";
                IAnnotateLayerTransformationProperties pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
                pATP.ReferenceScale = pGLS.ReferenceScale;
                pATP.ScaleRatio     = 1;

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

                IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescription();
                IFields fields = pOCDesc.RequiredFields;
                IFeatureClassDescription pFDesc = pOCDesc as IFeatureClassDescription;

                for (int j = 0; j < pOCDesc.RequiredFields.FieldCount; j++)
                {
                    fsEditAnno.AddField(pOCDesc.RequiredFields.get_Field(j));
                }
                fields = fsEditAnno as IFields;
                pFWSAnno.CreateAnnotationClass(feaName, fields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, pFDesc.ShapeFieldName, "", featureDataset, null, pAnnoPropsColl, pGLS, pSymbolColl, true);
            }
            catch
            {
            }
        }
Example #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);
        }
Example #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));
        }
Example #5
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);
            }
        }
Example #6
0
        //转换要素类
        private void CoordConvertFeatureClass(IFeatureClass fc, ISpatialReference spatialReference, out IFeatureClass outfc)
        {
            WaitForm.SetCaption("正在转换" + fc.AliasName + ",请稍后...");
            outfc = null;
            IWorkspaceFactory pWsF    = new AccessWorkspaceFactoryClass();
            IFeatureWorkspace pFWs    = null;
            IFeatureClass     pTempFc = null;

            try
            {
                IFields pFields = new FieldsClass();
                pFields = GetFieldsFromFeatureClass(fc, spatialReference);

                pFWs = pWsF.OpenFromFile(m_Path + @"\" + m_Name, 0) as IFeatureWorkspace;

                IDataset pDataset  = fc as IDataset;
                string   strFCName = pDataset.Name;
                try
                {
                    pTempFc = pFWs.OpenFeatureClass(strFCName);
                }
                catch (System.Exception ex)
                {
                    IFeatureDataset pFeatureDataset    = fc.FeatureDataset;
                    IFeatureDataset pFeatureDatasetNew = null;
                    if (pFeatureDataset != null)
                    {
                        try
                        {
                            pFeatureDatasetNew = pFWs.OpenFeatureDataset(pFeatureDataset.Name);
                            pTempFc            = pFeatureDatasetNew.CreateFeatureClass(strFCName, pFields, fc.CLSID, fc.EXTCLSID, fc.FeatureType, fc.ShapeFieldName, null);
                            (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                        }
                        catch
                        {
                            pFeatureDatasetNew = pFWs.CreateFeatureDataset(pFeatureDataset.Name, spatialReference);

                            //若为注记
                            if (fc.FeatureType == esriFeatureType.esriFTAnnotation)
                            {
                                IFeatureWorkspaceAnno pFWsAnno   = pFWs as IFeatureWorkspaceAnno;
                                IAnnoClass            pAnnoClass = fc.Extension as IAnnoClass;

                                IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass();
                                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;
                                try
                                {
                                    pTempFc = pFWsAnno.CreateAnnotationClass(strFCName,
                                                                             pFields, fc.CLSID, fc.EXTCLSID, fc.ShapeFieldName, "",
                                                                             pFeatureDatasetNew, null, pAnnoClass.AnnoProperties, pGLS,
                                                                             pAnnoClass.SymbolCollection, true);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                            else//若为地理要素
                            {
                                try
                                {
                                    pTempFc = pFeatureDatasetNew.CreateFeatureClass(strFCName, pFields, null, null, fc.FeatureType, fc.ShapeFieldName, null);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            if (fc.FeatureType == esriFeatureType.esriFTAnnotation)//若为注记
                            {
                                IFeatureWorkspaceAnno pFWsAnno   = pFWs as IFeatureWorkspaceAnno;
                                IAnnoClass            pAnnoClass = fc.Extension as IAnnoClass;

                                IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass();
                                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;
                                try
                                {
                                    pTempFc = pFWsAnno.CreateAnnotationClass(strFCName,
                                                                             pFields, fc.CLSID, fc.EXTCLSID, fc.ShapeFieldName, "",
                                                                             pFeatureDatasetNew, null, pAnnoClass.AnnoProperties, pGLS,
                                                                             pAnnoClass.SymbolCollection, true);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                            else
                            {
                                try
                                {
                                    pTempFc = pFeatureDatasetNew.CreateFeatureClass(strFCName, pFields, null, null, fc.FeatureType, fc.ShapeFieldName, null);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                        }
                        catch
                        {
                            WaitForm.Stop();
                        }
                    }
                }
                if (fc.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    IFeature       outFeature;
                    IFeature       pFeature;
                    IFeatureCursor pFeatureCursor = GetSelectedFeatures(GetLayerByNameFromMap(m_Map, strFCName));
                    if (pFeatureCursor == null)
                    {
                        return;
                    }
                    while ((pFeature = pFeatureCursor.NextFeature()) != null)
                    {
                        try
                        {
                            outFeature = pTempFc.CreateFeature();
                            CoordConvertAnnotationFeature(pFeature, ref outFeature);
                            outFeature.Store();
                        }
                        catch (System.Exception ex)
                        {
                            WaitForm.Stop();
                        }
                    }
                    outfc = pTempFc;
                }
                else//若为几何要素
                {
                    IFeature       outFeature;
                    IFeature       pFeature;
                    IFeatureCursor pFeatureCursor = GetSelectedFeatures(GetLayerByNameFromMap(m_Map, strFCName));
                    if (pFeatureCursor == null)
                    {
                        return;
                    }
                    while ((pFeature = pFeatureCursor.NextFeature()) != null)
                    {
                        try
                        {
                            outFeature = pTempFc.CreateFeature();
                            CoordConvertFeature(pFeature, ref outFeature);
                            outFeature.Store();
                        }
                        catch
                        {
                            WaitForm.Stop();
                        }
                    }
                    outfc = pTempFc;
                }
            }
            catch (System.Exception ex)
            {
                WaitForm.Stop();
            }
        }
Example #7
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);
            }
        }
Example #8
0
        private IFeatureClass CreateFeatureClass(IFeatureDataset featureDataset,TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode) 
        {
            try
            {
                if (featureDataset != null)
                {
                    IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                    IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
         
                    ///创建数据表字段
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IEnumFieldError enumFieldError = null;
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///字段信息验证
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = featureDataset.Workspace;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ////创建FeatureClass
                    IFeatureClass featureClass = null;
                    if (tableStructureNode.IsGeometryTable)
                    {
                        ////创建非注记FeatureClass
                        if (featureCodeNode.GeometryType != "")
                        {
                            featureClass = featureDataset.CreateFeatureClass(featureCodeNode.TableName,
                               fixFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID,
                               esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");
                        }
                        else
                        {
                            ///创建注记
                            IFormattedTextSymbol pTxtSymbo=new TextSymbolClass();

                            IFeatureWorkspaceAnno pFeatureWorkspaceAnno = this.m_pIDataset.Workspace as IFeatureWorkspaceAnno;

                            IGraphicsLayerScale pGraphSacle = new GraphicsLayerScaleClass();
                            pGraphSacle.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            //pGraphSacle.ReferenceScale=1000;


                            ISymbolCollection pSymbolCollection = new SymbolCollectionClass();

                            IAnnotateLayerProperties pAnnoLayerProp = new LabelEngineLayerPropertiesClass();
                            pAnnoLayerProp.FeatureLinked = true;
                            pAnnoLayerProp.CreateUnplacedElements = false;
                            pAnnoLayerProp.DisplayAnnotation = true;
                            pAnnoLayerProp.UseOutput = true;

                            IAnnotationExpressionEngine pAnnoExpressionEngine =new AnnotationVBScriptEngineClass();
                            ILabelEngineLayerProperties pLabelEngineLayerProperties = pAnnoLayerProp as ILabelEngineLayerProperties;
                            pLabelEngineLayerProperties.ExpressionParser = pAnnoExpressionEngine;
                            pLabelEngineLayerProperties.Expression = "[DESCRIPTION]";
                            pLabelEngineLayerProperties.IsExpressionSimple = true;
                            pLabelEngineLayerProperties.Offset = 0;
                            pLabelEngineLayerProperties.SymbolID = 0;
                            pLabelEngineLayerProperties.Symbol = pTxtSymbo;

                            IAnnotateLayerTransformationProperties pAnnoLayerTransProp = pAnnoLayerProp as IAnnotateLayerTransformationProperties;
                            pAnnoLayerTransProp.ReferenceScale=200;
                            pAnnoLayerTransProp.Units= ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            pAnnoLayerTransProp.ScaleRatio=1;

                            IAnnotateLayerPropertiesCollection pAnnoLayerProptyCollection =new AnnotateLayerPropertiesCollectionClass();
                           pAnnoLayerProptyCollection.Add(pAnnoLayerProp);

                           featureClass= pFeatureWorkspaceAnno.CreateAnnotationClass(featureCodeNode.TableName,fixFields,ocDesc.InstanceCLSID
                               ,ocDesc.ClassExtensionCLSID,fcDesc.ShapeFieldName,"",featureDataset,null,
                               pAnnoLayerProptyCollection, pGraphSacle, pSymbolCollection,true);
                        }
                    }
                    else
                    {
                        ///创建非空间数据
                    }
                    return featureClass;
                }
                return null;
            }
            catch(Exception ex)
            {
                Logger.WriteErrorLog(ex);
                return null;
            }
        }
Example #9
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);
        }
Example #10
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);
        }
Example #11
0
        /// <summary>
        /// 根据模板创建指定的要素类(从模板中复制要素类)

        /// </summary>
        /// <param name="FCName">要素类名称</param>
        /// <param name="IncludeFeature">是否导入源要素类中的要素</param>
        /// <returns>是否创建成功</returns>
        public bool CreateDefaultFeatureClass(string FCName, bool IncludeFeature)
        {
            IFeatureWorkspace pDesFeatureWorkspace = this._Workspace as IFeatureWorkspace;
            IFeatureClass     pDesFeatureClass     = null;

            if (pDesFeatureWorkspace == null)
            {
                return(false);
            }

            IFeatureWorkspace pSourFeatureWorkspace = this._TempleteWorkspace as IFeatureWorkspace;

            if (pSourFeatureWorkspace == null)
            {
                return(false);
            }

            #region 创建目标图层
            //获取源要素类
            IFeatureClass pSourFeatureClass = pSourFeatureWorkspace.OpenFeatureClass(FCName);
            if (pSourFeatureClass == null)
            {
                return(false);
            }

            //获取源要素类后判断要素类的类型

            if (pSourFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)   //如果是注记层
            {
                IFeatureWorkspaceAnno pFWSAnno   = pDesFeatureWorkspace as IFeatureWorkspaceAnno;
                IAnnoClass            pAnnoClass = pSourFeatureClass.Extension as IAnnoClass;
                IGraphicsLayerScale   pGLS       = new GraphicsLayerScaleClass();
                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;

                pDesFeatureClass = pFWSAnno.CreateAnnotationClass(pSourFeatureClass.AliasName, pSourFeatureClass.Fields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.ShapeFieldName, "", null, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
            }
            else    //如果是普通要素类
            {
                pDesFeatureClass = pDesFeatureWorkspace.CreateFeatureClass(FCName, pSourFeatureClass.Fields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.FeatureType, pSourFeatureClass.ShapeFieldName, "");
            }

            #endregion

            if (pDesFeatureClass == null)
            {
                return(false);
            }

            //导入要素
            if (IncludeFeature)  //如果需要复制要素
            {
                Exception eError = null;

                Dictionary <string, string> pDic = new Dictionary <string, string>();
                IFeatureCursor pFeatureCursor    = pSourFeatureClass.Search(null, false);

                IFields pFields = pSourFeatureClass.Fields;

                for (int i = 0; i < pFields.FieldCount; i++)
                {
                    IField pField = pFields.get_Field(i);
                    if (pField.Editable)
                    {
                        pDic.Add(pField.Name, pField.Name);
                    }
                }

                SysCommon.Gis.SysGisDataSet pSysGisDataSet = new SysCommon.Gis.SysGisDataSet();
                pSysGisDataSet.WorkSpace = this._Workspace;

                pSysGisDataSet.NewFeatures(FCName, pFeatureCursor, pDic, null, true, true, out eError);

                //释放cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
            }
            return(true);
        }
Example #12
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);
        }
Example #13
0
        private IFeatureClass CreateFeatureClass(IFeatureDataset featureDataset,TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode)
        {
            try
            {
                if (featureDataset != null)
                {
                    IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                    IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;

                    ///�������ݱ��ֶ�
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IEnumFieldError enumFieldError = null;
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///�ֶ���Ϣ��֤
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = featureDataset.Workspace;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ////����FeatureClass
                    IFeatureClass featureClass = null;
                    if (tableStructureNode.IsGeometryTable)
                    {
                        ////������ע��FeatureClass
                        if (featureCodeNode.GeometryType != "")
                        {
                            featureClass = featureDataset.CreateFeatureClass(featureCodeNode.TableName,
                               fixFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID,
                               esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");
                        }
                        else
                        {
                            ///����ע��
                            IFormattedTextSymbol pTxtSymbo=new TextSymbolClass();

                            IFeatureWorkspaceAnno pFeatureWorkspaceAnno = this.m_pIDataset.Workspace as IFeatureWorkspaceAnno;

                            IGraphicsLayerScale pGraphSacle = new GraphicsLayerScaleClass();
                            pGraphSacle.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            //pGraphSacle.ReferenceScale=1000;

                            ISymbolCollection pSymbolCollection = new SymbolCollectionClass();

                            IAnnotateLayerProperties pAnnoLayerProp = new LabelEngineLayerPropertiesClass();
                            pAnnoLayerProp.FeatureLinked = true;
                            pAnnoLayerProp.CreateUnplacedElements = false;
                            pAnnoLayerProp.DisplayAnnotation = true;
                            pAnnoLayerProp.UseOutput = true;

                            IAnnotationExpressionEngine pAnnoExpressionEngine =new AnnotationVBScriptEngineClass();
                            ILabelEngineLayerProperties pLabelEngineLayerProperties = pAnnoLayerProp as ILabelEngineLayerProperties;
                            pLabelEngineLayerProperties.ExpressionParser = pAnnoExpressionEngine;
                            pLabelEngineLayerProperties.Expression = "[DESCRIPTION]";
                            pLabelEngineLayerProperties.IsExpressionSimple = true;
                            pLabelEngineLayerProperties.Offset = 0;
                            pLabelEngineLayerProperties.SymbolID = 0;
                            pLabelEngineLayerProperties.Symbol = pTxtSymbo;

                            IAnnotateLayerTransformationProperties pAnnoLayerTransProp = pAnnoLayerProp as IAnnotateLayerTransformationProperties;
                            pAnnoLayerTransProp.ReferenceScale=200;
                            pAnnoLayerTransProp.Units= ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            pAnnoLayerTransProp.ScaleRatio=1;

                            IAnnotateLayerPropertiesCollection pAnnoLayerProptyCollection =new AnnotateLayerPropertiesCollectionClass();
                           pAnnoLayerProptyCollection.Add(pAnnoLayerProp);

                           featureClass= pFeatureWorkspaceAnno.CreateAnnotationClass(featureCodeNode.TableName,fixFields,ocDesc.InstanceCLSID
                               ,ocDesc.ClassExtensionCLSID,fcDesc.ShapeFieldName,"",featureDataset,null,
                               pAnnoLayerProptyCollection, pGraphSacle, pSymbolCollection,true);
                        }
                    }
                    else
                    {
                        ///�����ǿռ�����
                    }
                    return featureClass;
                }
                return null;
            }
            catch(Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
        }
Example #14
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);
        }
Example #15
0
        public bool CreateFeatureClassUnderDS(string FCName, string DSName, bool IncludeFeature, bool CreateDS, string TempDBID, bool AddFID)
        {
            IFeatureWorkspace pDesFeatureWorkspace = this._Workspace as IFeatureWorkspace;
            IFeatureClass     pDesFeatureClass     = null;

            if (pDesFeatureWorkspace == null)
            {
                return(false);
            }

            IFeatureWorkspace pSourFeatureWorkspace = this._TempleteWorkspace as IFeatureWorkspace;

            if (pSourFeatureWorkspace == null)
            {
                return(false);
            }

            IFeatureDataset pDesFeatureDataset = null;
            IFeatureDataset pSrcFeatureDataset = null;

            if (CreateDS)
            {
                //创建数据集

                pSrcFeatureDataset = pSourFeatureWorkspace.OpenFeatureDataset(DSName);
                IGeoDataset pGeoDataset = pSrcFeatureDataset as IGeoDataset;
                pDesFeatureDataset = pDesFeatureWorkspace.CreateFeatureDataset(DSName + TempDBID, pGeoDataset.SpatialReference);
            }
            else
            {
                pDesFeatureDataset = pDesFeatureWorkspace.OpenFeatureDataset(DSName + TempDBID);
            }

            #region 创建目标图层
            //获取源要素类
            IFeatureClass pSourFeatureClass = pSourFeatureWorkspace.OpenFeatureClass(FCName);
            if (pSourFeatureClass == null)
            {
                return(false);
            }

            //获取源要素类后判断要素类的类型

            if (pSourFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)   //如果是注记层
            {
                IFeatureWorkspaceAnno pFWSAnno   = pDesFeatureWorkspace as IFeatureWorkspaceAnno;
                IAnnoClass            pAnnoClass = pSourFeatureClass.Extension as IAnnoClass;
                IGraphicsLayerScale   pGLS       = new GraphicsLayerScaleClass();
                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;

                ///添加特殊字段
                ///
                IField     pField     = new FieldClass();
                IFieldEdit pFieldEdit = pField as IFieldEdit;

                pFieldEdit.Editable_2 = true;
                pFieldEdit.Name_2     = "GOFID";
                pFieldEdit.Type_2     = esriFieldType.esriFieldTypeInteger;



                IField     pField2     = new FieldClass();
                IFieldEdit pFieldEdit2 = pField2 as IFieldEdit;

                pFieldEdit2.Editable_2 = true;
                pFieldEdit2.Name_2     = "pro_id"; //项目ID
                pFieldEdit2.Type_2     = esriFieldType.esriFieldTypeInteger;

                IFields pFields = pSourFeatureClass.Fields;

                if (AddFID)
                {
                    IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                    pFieldsEdit.AddField(pField);
                    pFieldsEdit.AddField(pField2);
                    pDesFeatureClass = pFWSAnno.CreateAnnotationClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.ShapeFieldName, "", pDesFeatureDataset, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                    pFieldsEdit.DeleteField(pField);
                    pFieldsEdit.DeleteField(pField2);
                }
                else
                {
                    pDesFeatureClass = pFWSAnno.CreateAnnotationClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.ShapeFieldName, "", pDesFeatureDataset, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                }
            }
            else    //如果是普通要素类
            {
                ///添加特殊字段
                ///
                IField     pField     = new FieldClass();
                IFieldEdit pFieldEdit = pField as IFieldEdit;

                pFieldEdit.Editable_2 = true;
                pFieldEdit.Name_2     = "GOFID";
                pFieldEdit.Type_2     = esriFieldType.esriFieldTypeInteger;


                IField     pField2     = new FieldClass();
                IFieldEdit pFieldEdit2 = pField2 as IFieldEdit;

                pFieldEdit2.Editable_2 = true;
                pFieldEdit2.Name_2     = "pro_id"; //项目ID
                pFieldEdit2.Type_2     = esriFieldType.esriFieldTypeInteger;

                IFields pFields = pSourFeatureClass.Fields;

                if (AddFID)
                {
                    IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                    pFieldsEdit.AddField(pField);
                    pFieldsEdit.AddField(pField2);
                    pDesFeatureClass = pDesFeatureDataset.CreateFeatureClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.FeatureType, pSourFeatureClass.ShapeFieldName, "");
                    pFieldsEdit.DeleteField(pField);
                    pFieldsEdit.DeleteField(pField2);
                }
                else
                {
                    pDesFeatureClass = pDesFeatureDataset.CreateFeatureClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.FeatureType, pSourFeatureClass.ShapeFieldName, "");
                }
            }

            #endregion

            if (pDesFeatureClass == null)
            {
                return(false);
            }

            //导入要素
            if (IncludeFeature)  //如果需要复制要素
            {
                Exception eError = null;

                Dictionary <string, string> pDic = new Dictionary <string, string>();
                IFeatureCursor pFeatureCursor    = pSourFeatureClass.Search(null, false);

                IFields pFields = pSourFeatureClass.Fields;

                for (int i = 0; i < pFields.FieldCount; i++)
                {
                    IField pField = pFields.get_Field(i);
                    if (pField.Editable)
                    {
                        pDic.Add(pField.Name, pField.Name);
                    }
                }

                SysCommon.Gis.SysGisDataSet pSysGisDataSet = new SysCommon.Gis.SysGisDataSet();
                pSysGisDataSet.WorkSpace = this._Workspace;

                pSysGisDataSet.NewFeatures(FCName, pFeatureCursor, pDic, null, true, true, out eError);

                //释放cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
            }
            return(true);
        }
Example #16
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);
            }
        }
Example #17
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;
        }
Example #18
0
        /// <summary>
        /// 以原工作空间为模板创建新的工作空间
        /// </summary>
        private void CreatWorkspaceFromOrig()
        {
            WaitForm.SetCaption("正在创建新的工作空间...请稍后");
            IFeatureClassContainer pFcContainer = null;
            IFeatureClass          pFcTemp      = null;
            IFeatureClass          pNewFc       = null;
            ISpatialReference      pSr          = null;
            ISpatialReference      pSrTemp      = null;
            IFields pflds = null;
            double  dblXmin, dblXmax, dblYmin, dblYmax;
            double  dblZmin, dblZmax, dblMmin, dblMmax;

            CreateWorkspaceDomains(m_pOrigWorkspace, m_pDestWorkspace);
            IFeatureWorkspace pFeaWorkspace = m_pDestWorkspace as IFeatureWorkspace;
            IEnumDataset      enumDs        = m_pOrigWorkspace.get_Datasets(esriDatasetType.esriDTAny);
            IDataset          pDs           = enumDs.Next();

            while (pDs != null)
            {
                if (pDs.Type == esriDatasetType.esriDTFeatureDataset)
                {
                    pSr     = new UnknownCoordinateSystemClass();
                    pSrTemp = (pDs as IGeoDataset).SpatialReference;
                    if (pSrTemp.HasXYPrecision())
                    {
                        pSrTemp.GetDomain(out dblXmin, out dblXmax, out dblYmin, out dblYmax);
                        pSr.SetDomain(dblXmin, dblXmax, dblYmin, dblYmax);
                    }
                    if (pSrTemp.HasZPrecision())
                    {
                        pSrTemp.GetZDomain(out dblZmin, out dblZmax);
                        pSr.SetZDomain(dblZmin, dblZmax);
                    }
                    if (pSrTemp.HasMPrecision())
                    {
                        pSrTemp.GetMDomain(out dblMmin, out dblMmax);
                        pSr.SetMDomain(dblMmin, dblMmax);
                    }
                    IFeatureDataset pFeaDs = pFeaWorkspace.CreateFeatureDataset(pDs.Name, pSr);
                    pFcContainer = (IFeatureClassContainer)pDs;
                    if (pFcContainer.ClassCount > 0)
                    {
                        for (int i = 0; i < pFcContainer.ClassCount; i++)
                        {
                            try
                            {
                                pFcTemp = pFcContainer.get_Class(i);
                                pflds   = CommonFunction.GetFieldsFormFeatureClass(pFcTemp);

                                //若为注记
                                if (pFcTemp.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    IFeatureWorkspaceAnno pFWSAno    = pFeaWorkspace as IFeatureWorkspaceAnno;
                                    IAnnoClass            pAnnoClass = pFcTemp.Extension as IAnnoClass;
                                    IGraphicsLayerScale   pGLS       = new GraphicsLayerScaleClass();
                                    pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                    pGLS.Units          = pAnnoClass.ReferenceScaleUnits;


                                    pNewFc = pFWSAno.CreateAnnotationClass((pFcTemp as IDataset).Name,
                                                                           pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.ShapeFieldName,
                                                                           "", pFeaDs, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                                    (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName);
                                }
                                else//若为地理要素
                                {
                                    try
                                    {
                                        pNewFc = pFeaDs.CreateFeatureClass((pFcTemp as IDataset).Name,
                                                                           pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.FeatureType, pFcTemp.ShapeFieldName, null);
                                        if (pFcTemp.AliasName == "图廓线")
                                        {
                                            int n = 0;
                                        }
                                        (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName);
                                    }
                                    catch (System.Exception ex)
                                    {
                                        System.Console.WriteLine(ex.Message);
                                    }
                                }
                            }
                            catch (System.Exception ex)
                            {
                                System.Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
                else if (pDs.Type == esriDatasetType.esriDTFeatureClass)
                {
                    pFcTemp = (IFeatureClass)pDs;
                    pflds   = CommonFunction.GetFieldsFormFeatureClass(pFcTemp, pSr);
                    try
                    {
                        pNewFc = pFeaWorkspace.CreateFeatureClass(pDs.Name,
                                                                  pflds,
                                                                  pFcTemp.CLSID,
                                                                  pFcTemp.EXTCLSID,
                                                                  pFcTemp.FeatureType,
                                                                  pFcTemp.ShapeFieldName,
                                                                  null);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
                else if (pDs.Type == esriDatasetType.esriDTTable)
                {
                    ITable pTable = (ITable)pDs;
                    try
                    {
                        ITable pNewTable = pFeaWorkspace.CreateTable(pDs.Name,
                                                                     pTable.Fields,
                                                                     pTable.CLSID,
                                                                     pTable.EXTCLSID,
                                                                     null);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
                pDs = enumDs.Next();
            }
        }
Example #19
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();
     }
 }