将DWG文件导入MDB

Posted by 蒋波涛 6 October,2006 Views (18)Comment

将dwg文件作为要素数据集导入Map对象后,需要将这个dataset中的要素类转换到一个personal geodatabase中,自己写的一个要素类之间复制的代码一直出现莫名其妙的问题。今天的ESRI论坛上,看到一个比较好的方法,它直接使用了ESRI提供的一个数据装载函数:

Private Sub ConvertCad(byval pOutWorkspace As IWorkspace)

'Get the Workspace Name
Dim pWorkspaceName As IWorkspaceName
Dim pDataset As IDataset
Set pDataset = pOutWorkspace ' Workspaces implement IDataset
Set pWorkspaceName = pDataset.FullName


'Open the Cad Workspace
Dim pCADWF As IWorkspaceFactory
Set pCADWF = New CadWorkspaceFactory
Dim pInWs As IFeatureWorkspace
Set pInWs = pCADWF.OpenFromFile("M:\ArcGis\TestRoutine", 0)
'Open the feature dataset
Dim pDs As IFeatureDataset
Set pDs = pInWs.OpenFeatureDataset("N103A.dwg")
'loop through the cad feature classes and convert
Dim pFCC As IFeatureClassContainer
Set pFCC = pDs
Dim pFC As IFeatureClass
Dim pEnumFc As IEnumFeatureClass
Set pEnumFc = pFCC.Classes
Set pFC = pEnumFc.Next
Do Until pFC Is Nothing
    'Get the Input featureclassname
    Dim pInFcName As IFeatureClassName
    Dim pInDs As IDataset
    Set pInDs = pFC
    Set pInFcName = pInDs.FullName
    'Create new output featureclassname
    'give output featureclass same name as
    'input cad drawing
    Dim pOutFcName As IFeatureClassName
    Set pOutFcName = New FeatureClassName
    Dim pDatasetName As IDatasetName
    Set pDatasetName = pOutFcName
    pDatasetName.Name = (Replace((pFC.FeatureDataset.Name), ".dwg", "_"))
& pFC.AliasName
    Set pDatasetName.WorkspaceName = pWorkspaceName
    'Get fields for input featureclass and run them
    'through the field checker
    Dim pFieldChecker As IFieldChecker
    Dim pFields As IFields
    Set pFields = pFC.Fields
    Dim pOutFields As IFields
    Set pFieldChecker = New FieldChecker
    pFieldChecker.InputWorkspace = pInWs
    Set pFieldChecker.ValidateWorkspace = pOutWorkspace
    pFieldChecker.Validate pFields, Nothing, pOutFields
    'Convert the data
    Dim pFDC As IFeatureDataConverter
    Set pFDC = New FeatureDataConverter
    pFDC.ConvertFeatureClass pInFcName, Nothing, Nothing, pOutFcName,
Nothing, pOutFields, "", 100, 0
  Set pFDC = Nothing
'Get the next feature class to convert
Set pFC = pEnumFc.Next
Loop
End Sub

Related Items

Categories : ArcObjects Tags : ArcObjects  
Comments
2007-1-25 12:32:06

我想实现类似的功能,即将矢量数据导入SDE数据库中,但是最后执行ConvertFeatureClass 时,总是提示“The application has not licensed to create or modify this type of data”,不知博主是否知晓是何原因,会不会是D版问题?

Posted by enable Gravatar Icon

2007-1-25 13:50:16

你的D版是ArcView级别的,无法对SDE进行写操作。

Posted by 蒋波涛 Gravatar Icon

2007-1-26 9:49:17

那要如何升级成ArcInfo呢

Posted by enable Gravatar Icon

2007-1-26 10:32:22

需要你找到ArcInfo的License或加密狗咯

Posted by 蒋波涛 Gravatar Icon

2007-1-26 11:29:02

可是我装的时候是选择的Arc/Info啊。对了,正版该怎么装,我有狗和License文件

Posted by enable Gravatar Icon

2007-1-30 14:03:02

似乎不是这个问题,现在出现的提示是“Must be the owner to do this operation”,这里的Owner不是所云

Posted by enable Gravatar Icon

2007-1-31 9:20:29

问题已基本解决,多谢回复

Posted by enable Gravatar Icon

2007-9-3 16:30:54

ConvertFeatureClass 这个函数不能转cad里面的注记层,想请问蒋老师该怎么转呢?

Posted by DxHappy Gravatar Icon

2007-9-3 22:07:38

自己编写,无非是遍历每个字段,将源记录的每个值都写道目标记录上保存即可,唯一需要注意的是Annotation字段需要使用IAnnotationFeature的Annotation属性。

Posted by 蒋波涛 Gravatar Icon

2008-6-25 21:12:23

蒋老师,如何用IFeatureDataConverter 实现Geodatabase转出为CAD格式呢,恳求指点。

Posted by xuxingliang Gravatar Icon

2008-6-28 23:39:01

格式问题必须由IWorkspaceFactory决定。

Posted by 蒋波涛 Gravatar Icon

2008-7-2 18:15:27

请问如何将CAD中的Annotation层导入至geodatabase中已存在的annotation 要素类中

Posted by chedengke Gravatar Icon

2008-7-2 18:18:21

不明白如何正确使用iannotationfeature的annotation属性,麻烦给出例子,先谢了

Posted by chedengke Gravatar Icon

2008-7-2 20:37:36

请看BLOG的第一篇

Posted by 蒋波涛 Gravatar Icon

2008-7-3 11:18:39

麻烦您说的清楚一点 那一篇叫什么名字.在这我先把我要实现的东东再说一下:我想把一个CAD的annotation层数据导入到一个已存在的geodatabase中的一个已建好的annotation feature class中。您上面提到遍历每个字段,Annotation字段需要使用IAnnotationFeature的Annotation属性。希望您能告诉我具体的实现代码。谢谢

Posted by chedengke Gravatar Icon

2008-7-3 11:34:17

这是我的代码 您帮忙给看看
Dim pinFeatureCursor As IFeatureCursor
Set pinFeatureCursor = pinfeatclass.Search(Nothing, False)
Dim pinfeature As IFeature
Set pinfeature = pinFeatureCursor.NextFeature
Dim poutfeature As IFeature
Dim poutannofeature As IAnnotationFeature
Dim pinannofeature As IAnnotationFeature
Do While Not pinfeature Is Nothing
Set pinannofeature = pinfeature
Set poutfeature = poutfeatclass.CreateFeature
Set poutannofeature = poutfeature
poutannofeature.Annotation = pinannofeature.Annotation
'上面一行提示错误automatation error
Set poutfeature = poutannofeature
Set poutfeature.Shape = pinfeature.Shape
poutfeature.Store
Set pinfeature = pinFeatureCursor.NextFeature
Loop
MsgBox "Convert operation complete!", vbInformation

Posted by chedengke Gravatar Icon

2008-7-3 15:06:21

poutannofeature.Annotation = pinannofeature.Annotation
不要这些写,Annotation是一个IElement对象,即ITextElement对象,你最好根据CAD数据标注携带的信息,自己产生TextElement后赋值给它。

Posted by 蒋波涛 Gravatar Icon

2008-7-3 15:18:24

您能给我写出来吗?或在我上面代码的基础上改一下.我刚刚接触AO,听您的解释云里雾里的,麻烦了.我QQ:57843573.希望能加您好友,有什么问题及时向你请教^_^!

Posted by chedengke Gravatar Icon

Leave a comment

Or, take a look at Archives and Categories

目录

存档