首页 > 代码库 > 要素类的复制方法

要素类的复制方法

转自原文 要素类的复制方法

 

如何根据一个要素类(源要素类)在另一个工作空间中产生一个同字段,但空间范围可能不一致的要素类(目标要素类)?本文提供了完备的方法。

 

 public ESRI.ArcGIS.Geodatabase.IFeatureClass CloneFeatureClass(ESRI.ArcGIS.Geodatabase.IFeatureClass srcFeatureClass, ESRI.ArcGIS.Geodatabase.IFeatureWorkspace SaveFeatWorkspace, string Name, ESRI.ArcGIS.Geometry.IEnvelope newEnvelope)
{
    if (Name == ""||Name ==null)
    {
        Name = srcFeatureClass.AliasName;
    }
    Name = this.getRightDatasetName(Name, ".");

    IFields pFields = this.CloneFeatureClassFields(srcFeatureClass, newEnvelope);
    //Anno要素类
    if (srcFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
    {
        //Anno Workspace
        IFeatureWorkspaceAnno pFWSAnno =SaveFeatWorkspace as IFeatureWorkspaceAnno;
        //获得AnnoFeatureClass的显示参数units和referencescale
        IAnnoClass pAnnoClass = srcFeatureClass.Extension as IAnnoClass;

        IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass();
        pGLS.Units = pAnnoClass.ReferenceScaleUnits;
        pGLS.ReferenceScale = pAnnoClass.ReferenceScale;

        ISymbol pSymbol = (ISymbol)MakeTextSymbol();
        //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();

        return pFWSAnno.CreateAnnotationClass(Name, pFields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, srcFeatureClass.ShapeFieldName, "", null, null, pAnnoPropsColl, pGLS, pSymbolColl, true);
    }
    else
    {
        return SaveFeatWorkspace.CreateFeatureClass(Name, pFields, null, null, esriFeatureType.esriFTSimple, srcFeatureClass.ShapeFieldName, "");
    }
}

 

方法中的两个函数,一个getRightDatasetName是解析要素类名称,即能够将诸如SDE.FC转换为FC。另一个方法CloneFeatureClassFields则是将一个要素类的Fields提取出来。

 

要素类的复制方法