【问题标题】:Import DXF blocks from one file to another using GDAL使用 GDAL 将 DXF 块从一个文件导入到另一个文件
【发布时间】:2018-01-09 02:23:25
【问题描述】:

我正在使用 GDAL 库版本 1.11.4 开发 CAD 程序。

我有两个 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);
}

有人知道问题出在哪里吗?

【问题讨论】:

    标签: c++ gdal dxf


    【解决方案1】:

    我解决了这个问题。添加 {copy->SetFID(1)},fid 默认为零。我不知道为什么。

    【讨论】:

      猜你喜欢
      • 2018-08-09
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      相关资源
      最近更新 更多