diff --git a/autotest/ogr/data/dxf/insert_only_col_count_zero.dxf b/autotest/ogr/data/dxf/insert_only_col_count_zero.dxf new file mode 100644 index 000000000000..04b8de6fda85 --- /dev/null +++ b/autotest/ogr/data/dxf/insert_only_col_count_zero.dxf @@ -0,0 +1,200 @@ + 0 +SECTION + 2 +TABLES + 0 +ENDSEC + 0 +SECTION + 2 +BLOCKS + 0 +BLOCK + 5 +44 +100 +AcDbEntity + 8 +0 +100 +AcDbBlockBegin + 2 +STAR + 70 +0 + 10 +0.0 + 20 +0.0 + 30 +0.0 + 3 +STAR + 1 + + 0 +LINE + 5 +45 +100 +AcDbEntity + 8 +0 + 62 +256 +100 +AcDbLine + 10 +-0.0281474976710656 + 20 +1.0414574138294284 + 30 +0.0 + 11 +0.6192449487634439 + 21 +-1.0696049115004942 + 31 +0.0 + 0 +LINE + 5 +46 +100 +AcDbEntity + 8 +0 + 62 +256 +100 +AcDbLine + 10 +0.6192449487634439 + 20 +-1.0696049115004942 + 30 +0.0 + 11 +-0.9570149208162315 + 21 +0.4785074604081158 + 31 +0.0 + 0 +LINE + 5 +47 +100 +AcDbEntity + 8 +0 + 62 +256 +100 +AcDbLine + 10 +-0.9570149208162315 + 20 +0.4785074604081158 + 30 +0.0 + 11 +1.0414574138294284 + 21 +0.3659174697238533 + 31 +0.0 + 0 +LINE + 5 +48 +100 +AcDbEntity + 8 +0 + 62 +256 +100 +AcDbLine + 10 +1.0414574138294284 + 20 +0.3659174697238533 + 30 +0.0 + 11 +-0.4785074604081158 + 21 +-1.0414574138294284 + 31 +0.0 + 0 +LINE + 5 +49 +100 +AcDbEntity + 8 +0 + 62 +256 +100 +AcDbLine + 10 +-0.4785074604081158 + 20 +-1.0414574138294284 + 30 +0.0 + 11 +-0.0562949953421313 + 21 +1.0133099161583627 + 31 +0.0 + 0 +ENDBLK + 5 +4A +100 +AcDbEntity + 8 +0 +100 +AcDbBlockEnd + 0 +ENDSEC + 0 +SECTION + 2 +ENTITIES + 0 +INSERT + 5 +55 +100 +AcDbEntity + 8 +0 + 62 +256 +100 +AcDbBlockReference + 2 +STAR + 10 +79.0976537766561876 + 20 +119.9621950624433424 + 30 +0.0 + 44 +1.0 + 45 +1.0 + 70 +0 + 0 +ENDSEC + 0 +EOF diff --git a/autotest/ogr/ogr_dxf.py b/autotest/ogr/ogr_dxf.py index 16cd74c362f8..9932e5288454 100644 --- a/autotest/ogr/ogr_dxf.py +++ b/autotest/ogr/ogr_dxf.py @@ -4124,3 +4124,24 @@ def test_ogr_dxf_write_MEASUREMENT(tmp_vsimem): pass with ogr.Open(filename) as ds: assert ds.GetMetadataItem("$MEASUREMENT", "DXF_HEADER_VARIABLES") == " 0" + + +############################################################################### +# Use case of https://github.com/OSGeo/gdal/issues/11591 +# Test reading a INSERT block whose column count is zero. +# Not totally sure about the exact behavior we should do. Currently +# the zero count is strictly honored and no geometry from the block will be +# inserted into the regular geometries. LibreCAD 2.1.3 does the same thing + + +@gdaltest.enable_exceptions() +def test_ogr_dxf_insert_col_count_zero(): + + with ogr.Open("data/dxf/insert_only_col_count_zero.dxf") as ds: + lyr = ds.GetLayer(0) + assert lyr.GetFeatureCount() == 0 + + with gdal.config_option("DXF_INLINE_BLOCKS", "NO"): + with ogr.Open("data/dxf/insert_only_col_count_zero.dxf") as ds: + lyr = ds.GetLayerByName("blocks") + assert lyr.GetFeatureCount() == 1 diff --git a/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp b/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp index 5c3d26b5e0df..cbdb9dd6173d 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp @@ -88,6 +88,8 @@ int OGRDXFDataSource::Open(const char *pszFilename, bool bHeaderOnly, CSLConstList papszOptionsIn) { + SetDescription(pszFilename); + osEncoding = CPL_ENC_ISO8859_1; bInlineBlocks = CPLTestBool( diff --git a/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp b/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp index 719d3bb85324..64aa386f81bc 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp @@ -3167,7 +3167,7 @@ bool OGRDXFLayer::TranslateINSERT() case 70: m_oInsertState.m_nColumnCount = atoi(szLineBuf); - if (m_oInsertState.m_nColumnCount <= 0) + if (m_oInsertState.m_nColumnCount < 0) { DXF_LAYER_READER_ERROR(); m_oInsertState.m_nRowCount = 0; @@ -3178,7 +3178,7 @@ bool OGRDXFLayer::TranslateINSERT() case 71: m_oInsertState.m_nRowCount = atoi(szLineBuf); - if (m_oInsertState.m_nRowCount <= 0) + if (m_oInsertState.m_nRowCount < 0) { DXF_LAYER_READER_ERROR(); m_oInsertState.m_nRowCount = 0; @@ -3205,6 +3205,12 @@ bool OGRDXFLayer::TranslateINSERT() return false; } + if (m_oInsertState.m_nRowCount == 0 || m_oInsertState.m_nColumnCount == 0) + { + m_oInsertState.m_nRowCount = 0; + m_oInsertState.m_nColumnCount = 0; + } + /* -------------------------------------------------------------------- */ /* Process any attribute entities. */ /* -------------------------------------------------------------------- */