Closed gorloffslava closed 1 year ago
By reading the documentation of the CSV driver https://gdal.org/drivers/vector/csv.html, by default the .csvt file is not created. A special layer creation option is required.
CREATE_CSVT=[YES/NO]: Defaults to NO. Create the associated .csvt file (see above paragraph) to describe the type of each column of the layer and its optional width and precision.
By reading the documentation of the CSV driver https://gdal.org/drivers/vector/csv.html, by default the .csvt file is not created. A special layer creation option is required.
CREATE_CSVT=[YES/NO]: Defaults to NO. Create the associated .csvt file (see above paragraph) to describe the type of each column of the layer and its optional width and precision.
Thanks for your response! We use that when writing datasets, yes, and it works.
But in our issue above, we copy dataset, not create from scratch, so expect all sidecars to be copied automatically as it happens, for example, w/ GeoTIFF or ESRI Shapefile. +It doesn't seem to affect opening datasets which already have this sidecar.
I may be wrong, but doesn't driver.CreateCopy make a copy of the internal presentation of the data that GDAL has after opening the source dataset? So it does not copy files even if the source and target formats are the same, but the data gets rewritten. Have you tried to use the layer creation option as I suggested? Unfortunately I am not a programmer and I can't tell how to test that.
Maybe https://gdal.org/api/python/osgeo.ogr.html#osgeo.ogr.DataSource.CopyLayer does something similar:
Duplicate an existing layer. This function creates a new layer, duplicate the field definitions of the source layer and then duplicate each features of the source layer. The papszOptions argument can be used to control driver specific creation options. These options are normally documented in the format specific documentation. The source layer may come from another dataset.
I'm working on having GetFileList() report the .csvt file, but you indeed shouldn't expect CreateCopy() to create a .csvt file, even if the source dataset is a .csv file with a .csvt. Output driver of GDAL know nothing about input drivers, and everything goes through a pivot model that forget about the implementation details. You'd better use plain file copy if you want to do CSV -> CSV without any change. As there isn't a way of provider layer creation options in the GDALDataset::CopyLayer() call done by GDALDriver::DefaultCreateCopy(), you'd better use GDALVectorTranslate() instead
@rouault big thanks for fixing this! And for your explanation about CreateCopy() behavior.
@jratike80 big thanks for your assist as well!
Expected behavior and actual behavior.
Given:
.csv
index and.csvt
sidecar.testcsvt.csv
andtestcsvt.csvt
from GDAL autotest data: https://github.com/OSGeo/gdal/tree/master/autotest/ogr/data/csvSteps to reproduce the problem.
Reproduction case #1:
Expected output:
['testcsvt.csv', 'testcsvt.csvt']
Actual output:['testcsvt.csv']
Reproduction case #2:
Expected output:
['testcsvt.csv', 'testcsvt.csvt']
Actual output:['testcsvt.csv']
Reproduction case #3: How can we checked that CSVT is really loaded by GDAL?
Operating system
Reproducible w/ any of the following:
GDAL version and provenance
Reproducible w/ any of the following:
master
branch