2017-08-02 424 views
0

我正在開發GDAL庫版本爲1.11.4的CAD程序。使用GDAL將DXF塊從一個文件導入另一個文件

我有兩個DXF文件:a.dxfb.dxfa.dxf是一個模板文件。該文件有一個塊層。它包含一些功能(符號信息)。 b.dxf包含一些點座標。我應該使用符號(a.dxf)顯示點(b.dxf)。

我的想法:從a.dxf導出塊並將它們導入到b.dxf

但是b.dxf無法在CAD上打開。她是我的代碼:

enter code here 
#include "stdafx.h" 
#include "gdal_priv.h" 
#include "ogrsf_frmts.h" 
#include "gdal.h" 
#include "stdio.h" 

int main() 
{ 
    const char *pszDriverName = "DXF"; 
    OGRSFDriver *poDriver = nullptr; 

    RegisterOGRDXF(); 

    CPLSetConfigOption("GDAL_DATA", "./debug/data"); 
    CPLSetConfigOption("DXF_INLINE_BLOCKS", "false"); 


    poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("DXF"); 
    if (poDriver == NULL) 
    { 
     printf("%s driver not available.\n", pszDriverName); 
     exit(1); 
    } 

    OGRDataSource* poDS = OGRSFDriverRegistrar::Open("a.dxf", true, &poDriver); 
    //the block layer 
    OGRLayer* blockLayer = poDS->GetLayer(0); 
    OGRFeature* copy = blockLayer->GetFeature(0); 

    OGRDataSource* poDS1 = poDriver->CreateDataSource("b.dxf"); 
    OGRLayer* blockLayer1 = poDS1->CreateLayer("blocks"); 
    OGRLayer* entityLayer1 = poDS1->CreateLayer("entites"); 
    auto err1 = blockLayer1->CreateFeature(copy); 

    OGRFeature::DestroyFeature(copy); 

    OGRDataSource::DestroyDataSource(poDS); 
    OGRDataSource::DestroyDataSource(poDS1); 
} 

有誰知道問題是什麼?

回答

0

我解決了這個問題。加{copy-> SetFID(1)},fid等於零默認值。我不知道爲什麼。

相關問題