Skip to content

Commit

Permalink
GTI: take into account comments of code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 17, 2024
1 parent ec76e6a commit 24c5ca3
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 194 deletions.
2 changes: 1 addition & 1 deletion apps/gdaltindex_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ GDALTileIndexOptionsNew(char **papszArgv,
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(2);
psOptions->xres = CPLAtofM(papszArgv[++iArg]);
psOptions->yres = CPLAtofM(papszArgv[++iArg]);
psOptions->yres = std::fabs(CPLAtofM(papszArgv[++iArg]));
}
else if (EQUAL(papszArgv[iArg], "-te"))
{
Expand Down
27 changes: 14 additions & 13 deletions autotest/gdrivers/gti.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def test_gti_wrong_prototype_tile(tmp_vsimem):
lyr.CreateFeature(f)
del index_ds

# no match, because error message is operating system dependent
with pytest.raises(Exception):
gdal.Open(index_filename)

Expand Down Expand Up @@ -520,7 +521,7 @@ def test_gti_wrong_width(tmp_vsimem):
lyr.SetMetadataItem("GEOTRANSFORM", ",".join([str(x) for x in gt]))
del index_ds

with pytest.raises(Exception, match="XSIZE metadata item should be > 0"):
with pytest.raises(Exception, match="XSIZE metadata item must be > 0"):
gdal.Open(index_filename)


Expand All @@ -536,7 +537,7 @@ def test_gti_wrong_height(tmp_vsimem):
lyr.SetMetadataItem("GEOTRANSFORM", ",".join([str(x) for x in gt]))
del index_ds

with pytest.raises(Exception, match="YSIZE metadata item should be > 0"):
with pytest.raises(Exception, match="YSIZE metadata item must be > 0"):
gdal.Open(index_filename)


Expand Down Expand Up @@ -593,7 +594,7 @@ def test_gti_wrong_gt(tmp_vsimem):

with pytest.raises(
Exception,
match="GEOTRANSFORM metadata item should be 6 numeric values separated with comma",
match="GEOTRANSFORM metadata item must be 6 numeric values separated with comma",
):
gdal.Open(index_filename)

Expand All @@ -609,7 +610,7 @@ def test_gti_wrong_gt_3rd_term(tmp_vsimem):
lyr.SetMetadataItem("GEOTRANSFORM", "0,1,123,0,0,-1")
del index_ds

with pytest.raises(Exception, match="3rd value of GEOTRANSFORM should be 0"):
with pytest.raises(Exception, match="3rd value of GEOTRANSFORM must be 0"):
gdal.Open(index_filename)


Expand All @@ -624,7 +625,7 @@ def test_gti_wrong_gt_5th_term(tmp_vsimem):
lyr.SetMetadataItem("GEOTRANSFORM", "0,1,0,0,1234,-1")
del index_ds

with pytest.raises(Exception, match="5th value of GEOTRANSFORM should be 0"):
with pytest.raises(Exception, match="5th value of GEOTRANSFORM must be 0"):
gdal.Open(index_filename)


Expand All @@ -639,7 +640,7 @@ def test_gti_wrong_gt_6th_term(tmp_vsimem):
lyr.SetMetadataItem("GEOTRANSFORM", "0,1,0,0,0,1")
del index_ds

with pytest.raises(Exception, match="6th value of GEOTRANSFORM should be < 0"):
with pytest.raises(Exception, match="6th value of GEOTRANSFORM must be < 0"):
gdal.Open(index_filename)


Expand Down Expand Up @@ -698,7 +699,7 @@ def test_gti_wrong_resx(tmp_vsimem):
lyr.SetMetadataItem("RESY", "1")
del index_ds

with pytest.raises(Exception, match="RESX metadata item should be > 0"):
with pytest.raises(Exception, match="RESX metadata item must be > 0"):
gdal.Open(index_filename)


Expand All @@ -712,7 +713,7 @@ def test_gti_wrong_resy(tmp_vsimem):
lyr.SetMetadataItem("RESY", "0")
del index_ds

with pytest.raises(Exception, match="RESY metadata item should be > 0"):
with pytest.raises(Exception, match="RESY metadata item must be > 0"):
gdal.Open(index_filename)


Expand All @@ -732,7 +733,7 @@ def test_gti_wrong_minx(tmp_vsimem):
lyr.SetMetadataItem("MAXY", str(gt[3]))
del index_ds

with pytest.raises(Exception, match="MAXX metadata item should be > MINX"):
with pytest.raises(Exception, match="MAXX metadata item must be > MINX"):
gdal.Open(index_filename)


Expand All @@ -752,7 +753,7 @@ def test_gti_wrong_miny(tmp_vsimem):
lyr.SetMetadataItem("MAXY", str(gt[3]))
del index_ds

with pytest.raises(Exception, match="MAXY metadata item should be > MINY"):
with pytest.raises(Exception, match="MAXY metadata item must be > MINY"):
gdal.Open(index_filename)


Expand Down Expand Up @@ -917,7 +918,7 @@ def test_gti_valid_nodata(tmp_vsimem, md, expected_nodata):
({"BAND_COUNT": "2", "NODATA": "0,invalid"}, "Invalid value for NODATA"),
(
{"BAND_COUNT": "2", "NODATA": "0,0,0"},
"Number of values in NODATA should be 1 or BAND_COUNT",
"Number of values in NODATA must be 1 or BAND_COUNT",
),
],
)
Expand Down Expand Up @@ -945,7 +946,7 @@ def test_gti_invalid_nodata(tmp_vsimem, md, error_msg):
),
(
{"BAND_COUNT": "2", "DATA_TYPE": "byte,byte,byte"},
"Number of values in DATA_TYPE should be 1 or BAND_COUNT",
"Number of values in DATA_TYPE must be 1 or BAND_COUNT",
),
],
)
Expand Down Expand Up @@ -976,7 +977,7 @@ def test_gti_invalid_data_type(tmp_vsimem, md, error_msg):
"BAND_COUNT": "2",
"COLOR_INTERPRETATION": "undefined,undefined,undefined",
},
"Number of values in COLOR_INTERPRETATION should be 1 or BAND_COUNT",
"Number of values in COLOR_INTERPRETATION must be 1 or BAND_COUNT",
),
],
)
Expand Down
2 changes: 2 additions & 0 deletions autotest/utilities/test_gdaltindex_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def test_gdaltindex_lib_outputSRS_writeAbsoluePath(tmp_path, four_tile_index):
"got %d features, expecting 5" % ds.GetLayer(0).GetFeatureCount()
)
filename = lyr.GetFeature(4).GetField("location")
# Check that path is absolute
assert filename.endswith("gdaltindex5.tif")
assert filename != "gdaltindex5.tif"

Expand Down Expand Up @@ -382,6 +383,7 @@ def test_gdaltindex_lib_directory(tmp_path, four_tiles):
del ds

with gdal.quiet_errors():
# triggers warnings: "file XXXX has 0.010000 as pixel size (< 10.000000). Skipping"
gdal.TileIndex(
index_filename,
[os.path.dirname(four_tiles[0])],
Expand Down
6 changes: 3 additions & 3 deletions doc/source/programs/gdalbuildvrt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ entries in the tile index will be added to the VRT.

.. note::

Starting with GDAL 3.9, for virtual mosaic with a very large number of tiles
(typically hundreds of thousands of tiles, or more), it is advised to use the
Starting with GDAL 3.9, for virtual mosaic with a very large number of source rasters
(typically hundreds of thousands of source rasters, or more), it is advised to use the
:ref:`gdaltindex` utility to generate a tile index compatible of the
:ref:`GTI <raster.gti>` driver.

With -separate, each files goes into a separate band in the VRT dataset. Otherwise,
the files are considered as tiles of a larger mosaic and the VRT file has as many bands as one
the files are considered as source rasters of a larger mosaic and the VRT file has as many bands as one
of the input files.

If one GDAL dataset is made of several subdatasets and has 0 raster bands,
Expand Down
27 changes: 16 additions & 11 deletions doc/source/programs/gdaltindex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,25 @@ tileindex, or as input for the :ref:`GTI <raster.gti>` driver.
'*' is a wildcard character that matches any number of any characters
including none. '?' is a wildcard character that matches a single character.
Comparisons are done in a case insensitive way.
Several filters may be specified
Several filters may be specified.

For example :``-filename_filter "*.tif" -filename_filter "*.tiff"``

.. option:: -min_pixel_size <val>

.. versionadded:: 3.9

Minimum pixel size that a raster should have to be selected. The pixel size
Minimum pixel size in term of geospatial extent per pixel (resolution) that
a raster should have to be selected. The pixel size
is evaluated after reprojection of its extent to the target SRS defined
by :option:`-t_srs`.

.. option:: -max_pixel_size <val>

.. versionadded:: 3.9

Maximum pixel size that a raster should have to be selected. The pixel size
Maximum pixel size in term of geospatial extent per pixel (resolution) that
a raster should have to be selected. The pixel size
is evaluated after reprojection of its extent to the target SRS defined
by :option:`-t_srs`.

Expand Down Expand Up @@ -141,7 +143,10 @@ tileindex, or as input for the :ref:`GTI <raster.gti>` driver.
specified here, unless :option:`-write_absolute_path` option is also used.

Starting with GDAL 3.9, this can also be a directory name. :option:`-recursive`
might also be used to recursve down to sub-directories.
can also be used to recurse down to sub-directories.

It is also possible to use the generic option ``--optfile filelist.txt``
to specify a list of source files.


Options specific to use by the GDAL GTI driver
Expand Down Expand Up @@ -186,7 +191,7 @@ specified.

Target resolution in SRS unit per pixel.

Written in the XML Virtutual Tile Index if :option:`-gti_filename`
Written in the XML Virtual Tile Index if :option:`-gti_filename`
is specified, or as ``RESX`` and ``RESY`` layer metadata items for formats that
support layer metadata.

Expand All @@ -196,7 +201,7 @@ specified.

Target extent in SRS unit.

Written in the XML Virtutual Tile Index if :option:`-gti_filename`
Written in the XML Virtual Tile Index if :option:`-gti_filename`
is specified, or as ``MINX``, ``MINY``, ``MAXX`` and ``MAXY`` layer metadata
items for formats that support layer metadata.

Expand All @@ -208,7 +213,7 @@ specified.
``Int16``, ``UInt32``, ``Int32``, ``UInt64``, ``Int64``, ``Float32``, ``Float64``, ``CInt16``,
``CInt32``, ``CFloat32`` or ``CFloat64``

Written in the XML Virtutual Tile Index if :option:`-gti_filename`
Written in the XML Virtual Tile Index if :option:`-gti_filename`
is specified, or as ``DATA_TYPE`` layer metadata item for formats that
support layer metadata.

Expand All @@ -218,7 +223,7 @@ specified.

Number of bands of the tiles of the tile index.

Written in the XML Virtutual Tile Index if :option:`-gti_filename`
Written in the XML Virtual Tile Index if :option:`-gti_filename`
is specified, or as ``BAND_COUNT`` layer metadata item for formats that
support layer metadata.

Expand All @@ -235,7 +240,7 @@ specified.

Nodata value of the tiles of the tile index.

Written in the XML Virtutual Tile Index if :option:`-gti_filename`
Written in the XML Virtual Tile Index if :option:`-gti_filename`
is specified, or as ``NODATA`` layer metadata item for formats that
support layer metadata.

Expand All @@ -246,7 +251,7 @@ specified.
Color interpretation of of the tiles of the tile index:
``red``, ``green``, ``blue``, ``alpha``, ``gray``, ``undefined``.

Written in the XML Virtutual Tile Index if :option:`-gti_filename`
Written in the XML Virtual Tile Index if :option:`-gti_filename`
is specified, or as ``COLOR_INTERPRETATION`` layer metadata item for formats that
support layer metadata.

Expand All @@ -256,7 +261,7 @@ specified.

Whether tiles in the tile index have a mask band.

Written in the XML Virtutual Tile Index if :option:`-gti_filename`
Written in the XML Virtual Tile Index if :option:`-gti_filename`
is specified, or as ``MASK_BAND`` layer metadata item for formats that
support layer metadata.

Expand Down
Loading

0 comments on commit 24c5ca3

Please sign in to comment.