用AO实现ACAD到Geodatabase的转换

Private Sub Command1_Click()
    Dim pWorkspaceFact      As IWorkspaceFactory
    Dim pWorkspace          As IWorkspace
    Dim myFWS               As IFeatureWorkspace
    Dim myFDS               As IFeatureDataset
    Dim myFCContainer       As IFeatureClassContainer
    Dim inDataName          As IDatasetName
    Dim inFDataName         As IFeatureDatasetName
    Dim inEnumDS_FC         As IEnumDatasetName
   
    Dim pOutAcFact          As IWorkspaceFactory
    Dim pOutAcWorkspaceName As IWorkspaceName
    Dim pOutAcFeatDSName    As IFeatureDatasetName
    Dim pOutAcDSName        As IDatasetName
    Dim outFDS              As IFeatureDataset
    Dim pPropset            As IPropertySet
    Dim pName               As IName
   
    Dim theLayer            As IFeatureLayer
    Dim myFDC               As IFeatureDataConverter

    Set pPropset = New PropertySet
    pPropset.SetProperty "Database", "F:/szhh/canada"
    Set pOutAcFact = New AccessWorkspaceFactory
    Set pOutAcWorkspaceName = pOutAcFact.Create("F:/szhh/canada", "canada", pPropset, Form1.hWnd)
    Set pOutAcFeatDSName = New FeatureDatasetName
    Set pOutAcDSName = pOutAcFeatDSName
    Set pOutAcDSName.WorkspaceName = pOutAcWorkspaceName
    pOutAcDSName.Name = "Country"
    Set pName = pOutAcFeatDSName
    'Set outFDS = pName.Open
   
    Set myFDC = New FeatureDataConverter
   
    Set pWorkspaceFact = New CadWorkspaceFactory
    Set pWorkspace = pWorkspaceFact.OpenFromFile("F:/szhh", Form1.hWnd)
    Set myFWS = pWorkspace
    Set myFDS = myFWS.OpenFeatureDataset("aaa.dwg")
    Set myFCContainer = myFDS
    Set inDataName = myFDS.FullName
    Set inFDataName = inDataName
    Set inEnumDS_FC = inFDataName.FeatureClassNames
    inEnumDS_FC.Reset
   
    Dim inDSname As IDatasetName
    Dim myFCname As IFeatureClassName
    Set inDSname = inEnumDS_FC.Next
    Set theLayer = Nothing
    While Not inDSname Is Nothing
        Set myFCname = inDSname
        If inDSname.Name = "Annotation" Then
            Set theLayer = New CadAnnotationLayer
        Else
            Set theLayer = New CadFeatureLayer
        End If
       
        Dim myFCL As IFeatureClass
        Dim ShapeField As IField
        Dim myGeom As IGeometryDef
        theLayer.Name = inDSname.Name
        Set myFCL = myFCContainer.ClassByName(inDSname.Name)
        Set ShapeField = myFCL.Fields.Field(myFCL.FindField(myFCL.ShapeFieldName))
        Set myGeom = ShapeField.GeometryDef
       
        Dim myFilter As IQueryFilter
        Set myFilter = New QueryFilter
        myFilter.SubFields = "*"
       
'        Dim myInGeo As IGeoDataset
'        Set myInGeo = myFDS
'        Dim myInRef As ISpatialReference
'        Set myInRef = myInGeo.SpatialReference
'        Dim inXMin As Double
'        Dim inXMax As Double
'        Dim inYMin As Double
'        Dim inYMax As Double
'        inXMin = 0
'        inXMax = 0
'        inYMin = 0
'        inYMax = 0
'        myInRef.GetDomain inXMin, inXMax, inYMin, inYMax
'
'        Dim myOutGeo As IGeoDataset
'        Set myOutGeo = outFDS
'        Dim myOutRef As ISpatialReference
'        Set myOutRef = myOutGeo.SpatialReference
'        Dim outXMin As Double
'        Dim outXMax As Double
'        Dim outYMin As Double
'        Dim outYMax As Double
'        outXMin = 0
'        outXMax = 0
'        outYMin = 0
'        outYMax = 0
'        myOutRef.GetDomain outXMin, outXMax, outYMin, outYMax
'
'        Dim newXMin As Double, newXMax As Double, newYMin As Double, newYMax As Double
'        If inXMin < outXMin Then newXMin = inXMin Else newXMin = outXMin
'        If inXMax > outXMax Then newXMax = inXMax Else newXMax = outXMax
'        If inYMin < outYMin Then newYMin = inYMin Else newYMin = outYMin
'        If inYMax > outYMax Then newYMax = inYMax Else newYMax = outYMax
'        myOutRef.SetDomain newXMin, newXMax, newYMin, newYMax
       
        Dim myEnumInv As IEnumInvalidObject
        Set myEnumInv = myFDC.ConvertFeatureClass(myFCname, myFilter, pOutAcFeatDSName, myFCname, myGeom, myFCL.Fields, "", 1000, Form1.hWnd)
        myEnumInv.Reset
        Dim myInv As IInvalidObjectInfo
        While Not myInv Is Nothing
            MsgBox "Invalid Object #" & myInv.InvalidObjectID & myInv.ErrorDescription
            Set myInv = myEnumInv.Next
        Wend
        Set inDSname = inEnumDS_FC.Next
    Wend
End Sub

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值