Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdaltindex: add -lco (fixes #3623) #9257

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/gdaltindex_bin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void Usage(bool bIsError, const char *pszErrorMsg)
" [-skip_different_projection] [-t_srs <target_srs>]\n"
" [-src_srs_name field_name] [-src_srs_format "
"{AUTO|WKT|EPSG|PROJ}]\n"
" [-lyr_name <name>]\n"
" [-lyr_name <name>] [-lco <KEY>=<VALUE>]...\n"
" [-gti_filename <name>]\n"
" [-tr <xres> <yres>] [-te <xmin> <ymin> <xmax> "
"<ymax>]\n"
Expand Down
12 changes: 9 additions & 3 deletions apps/gdaltindex_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct GDALTileIndexOptions
std::string osFormat{};
std::string osIndexLayerName{};
std::string osLocationField = "location";
CPLStringList aosLCO{};
std::string osTargetSRS{};
bool bWriteAbsolutePath = false;
bool bSkipDifferentProjection = false;
Expand Down Expand Up @@ -504,9 +505,9 @@ GDALDatasetH GDALTileIndex(const char *pszDest, int nSrcCount,
oSRS = *poSrcSRS;
}

poLayer = poTileIndexDS->CreateLayer(osLayerName.c_str(),
oSRS.IsEmpty() ? nullptr : &oSRS,
wkbPolygon, nullptr);
poLayer = poTileIndexDS->CreateLayer(
osLayerName.c_str(), oSRS.IsEmpty() ? nullptr : &oSRS, wkbPolygon,
psOptions->aosLCO.List());
if (!poLayer)
return nullptr;

Expand Down Expand Up @@ -1193,6 +1194,11 @@ GDALTileIndexOptionsNew(char **papszArgv,
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
psOptions->osLocationField = papszArgv[++iArg];
}
else if (strcmp(papszArgv[iArg], "-lco") == 0)
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
psOptions->aosLCO.AddString(papszArgv[++iArg]);
}
else if (strcmp(papszArgv[iArg], "-t_srs") == 0)
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
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 @@ -286,10 +286,12 @@ def test_gdaltindex_lib_gti_non_xml(tmp_path, four_tiles):
colorInterpretation="gray",
mask=True,
metadataOptions={"foo": "bar"},
layerCreationOptions=["FID=my_fid"],
)

ds = ogr.Open(index_filename)
lyr = ds.GetLayer(0)
assert lyr.GetFIDColumn() == "my_fid"
assert lyr.GetMetadataItem("RESX") == "60"
assert lyr.GetMetadataItem("RESY") == "60"
assert lyr.GetMetadataItem("MINX") == "0"
Expand Down
8 changes: 7 additions & 1 deletion doc/source/programs/gdaltindex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Synopsis
[-f <format>] [-tileindex <field_name>] [-write_absolute_path]
[-skip_different_projection] [-t_srs <target_srs>]
[-src_srs_name <field_name>] [-src_srs_format {AUTO|WKT|EPSG|PROJ}]
[-lyr_name <name>]
[-lyr_name <name>] [-lco <NAME>=<VALUE>]...
[-gti_filename <name>]
[-tr <xres> <yres>] [-te <xmin> <ymin> <xmax> <ymax>]
[-ot <datatype>] [-bandcount <val>] [-nodata <val>[,<val>...]]
Expand Down Expand Up @@ -130,6 +130,12 @@ tileindex, or as input for the :ref:`GTI <raster.gti>` driver.

Layer name to create/append to in the output tile index file.

.. option:: -lco <NAME>=<VALUE>

.. versionadded:: 3.9

Layer creation option (format specific)

.. option:: <index_file>

The name of the output file to create/append to. The default dataset will
Expand Down
12 changes: 12 additions & 0 deletions swig/include/python/gdal_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -4202,6 +4202,7 @@ def TileIndexOptions(options=None,
maxPixelSize=None,
format=None,
layerName=None,
layerCreationOptions=None,
locationFieldName="location",
outputSRS=None,
writeAbsolutePath=None,
Expand Down Expand Up @@ -4236,6 +4237,8 @@ def TileIndexOptions(options=None,
output format ("ESRI Shapefile", "GPKG", etc...)
layerName:
output layer name
layerCreationOptions:
list or dict of layer creation options
locationFieldName:
Specifies the name of the field in the resulting vector dataset where the path of the input dataset will be stored. The default field name is "location". Can be set to None to disable creation of such field.
outputSRS:
Expand Down Expand Up @@ -4297,6 +4300,15 @@ def TileIndexOptions(options=None,
new_options += ['-f', format]
if layerName is not None:
new_options += ['-lyr_name', layerName]

if layerCreationOptions is not None:
if isinstance(layerCreationOptions, dict):
for k, v in layerCreationOptions.items():
new_options += ['-lco', f'{k}={v}']
else:
for opt in layerCreationOptions:
new_options += ['-lco', opt]

if locationFieldName is not None:
new_options += ['-tileindex', locationFieldName]
if outputSRS is not None:
Expand Down
Loading