Skip to content

Commit

Permalink
Merge pull request #9668 from rouault/fix_9666
Browse files Browse the repository at this point in the history
AAIGRID: fix reading file whose first value is nan (fixes #9666)
  • Loading branch information
rouault authored Apr 17, 2024
2 parents 9724995 + 307c249 commit 324d6b0
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 100 deletions.
47 changes: 0 additions & 47 deletions autotest/gcore/aaigrid_read.py

This file was deleted.

52 changes: 0 additions & 52 deletions autotest/gcore/aaigrid_write.py

This file was deleted.

45 changes: 45 additions & 0 deletions autotest/gdrivers/aaigrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@

pytestmark = pytest.mark.require_driver("AAIGRID")


###############################################################################


def test_aaigrid_read_byte_tif_grd():

ds = gdal.Open("data/aaigrid/byte.tif.grd")
assert ds.GetRasterBand(1).Checksum() == 4672


###############################################################################
# Perform simple read test.

Expand All @@ -51,6 +61,30 @@ def test_aaigrid_1():
tst.testOpen()


###############################################################################
# CreateCopy tests

init_list = [
("byte.tif", 4672),
("int16.tif", 4672),
("uint16.tif", 4672),
("float32.tif", 4672),
("utmsmall.tif", 50054),
]


@pytest.mark.parametrize(
"filename,checksum",
init_list,
ids=[tup[0].split(".")[0] for tup in init_list],
)
def test_aaigrid_createcopy(filename, checksum):
ut = gdaltest.GDALTest(
"AAIGrid", "../gcore/data/" + filename, 1, checksum, filename_absolute=True
)
ut.testCreateCopy()


###############################################################################
# Verify some auxiliary data.

Expand Down Expand Up @@ -478,3 +512,14 @@ def test_aaigrid_write_south_up_raster():
gdal.GetDriverByName("AAIGRID").Delete(
"/vsimem/test_aaigrid_write_south_up_raster.asc"
)


###############################################################################
# Test reading a file starting with nan (https://github.com/OSGeo/gdal/issues/9666)


def test_aaigrid_starting_with_nan():

ds = gdal.Open("data/aaigrid/starting_with_nan.asc")
assert ds.GetRasterBand(1).DataType == gdal.GDT_Float32
assert ds.GetRasterBand(1).Checksum() == 65300
File renamed without changes.
10 changes: 10 additions & 0 deletions autotest/gdrivers/data/aaigrid/starting_with_nan.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ncols 5
nrows 5
xllcorner 0
yllcorner 0
cellsize 1
nan nan nan nan nan
nan nan nan nan nan
nan nan 1.0 nan nan
nan nan nan nan nan
nan nan nan nan nan
6 changes: 5 additions & 1 deletion frmts/aaigrid/aaigriddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,11 @@ GDALDataset *AAIGDataset::CommonOpen(GDALOpenInfo *poOpenInfo,
// null seems to be specific of D12 software
// See https://github.com/OSGeo/gdal/issues/5095
(i + 5 < poOpenInfo->nHeaderBytes &&
memcmp(poOpenInfo->pabyHeader + i, "null ", 5) == 0)) &&
memcmp(poOpenInfo->pabyHeader + i, "null ", 5) == 0) ||
(i + 4 < poOpenInfo->nHeaderBytes &&
EQUALN(reinterpret_cast<const char *>(
poOpenInfo->pabyHeader + i),
"nan ", 4))) &&
poOpenInfo->pabyHeader[i] != '\n' &&
poOpenInfo->pabyHeader[i] != '\r')
{
Expand Down

0 comments on commit 324d6b0

Please sign in to comment.