要素类的复制方法
如何根据一个要素类(源要素类)在另一个工作空间中产生一个同字段,但空间范围可能不一致的要素类(目标要素类)?本文提供了完备的方法。
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提取出来。
Related Items
Comments
1.是在SDE上做吗?license是否有足够权限?
2.给出具体异常信息
谢谢您的回答!不是在sde上做,是personal geodatabase上,错误提示是:这个集合中找不到此项目!
我现在是学生,用的是破解版的。
如果是license的问题,您能给我发一份到邮箱吗?
你最好给出编译器中异常的error id,才能给你判断
我的程序是这样的:主界面上有个按钮,点击按钮会在personal geodatabase中生成一个注记类,现在程序能运行,点击按钮后会在那句代码停下了,提示错误就是:这个集合中找不到此项目!
error id我不知道从哪里看到啊,还麻烦您多指教!谢谢!
在VS中启动程序,出错处不断查看抛出的异常信息,寻找到错误号。
谢谢您!问题解决了,就是您说的license问题!
Leave a comment
Or, take a look at Archives and Categories
你好!我也在做标注,但是我的代码在运行到pFWSAnno.CreateAnnotationClass(Name, pFields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, srcFeatureClass.ShapeFieldName, "", null, null, pAnnoPropsColl, pGLS, pSymbolColl, true);这句时就会报错,说:在这个集合项目中找不到该项。大概就是这个意思了,请问这是什么原因阿?
谢谢赐教!