diff --git a/.mailmap b/.mailmap index 4f5b29673164f0f4717494cec297a17c037b4d73..40ef95e52d046d8d1917e474e2da727203f8fa46 100644 --- a/.mailmap +++ b/.mailmap @@ -54,6 +54,7 @@ Julien Malik <julien.malik@c-s.fr> Julien Malik <julien.m Julien Michel <julien.michel@cnes.fr> Julien Michel <julien.michel@cnes.fr> Julien Michel <julien.michel@c-s.fr> Julien Michel <julien.michel@cnes.fr> Julien Michel <julien.michel@orfeo-toolbox.org> +Julien Osman <julien.osman@c-s.fr> Laurențiu Nicola <lnicola@dend.ro> Laurentiu Nicola <lnicola@dend.ro> Laurențiu Nicola <lnicola@dend.ro> Laurențiu Nicola <grayshade@gmail.com> Luc Hermitte <luc.hermitte@c-s.fr> Luc Hermitte <luc.hermitte@cnes.fr> diff --git a/Data/Baseline/OTB/Images/ioTvExtendedFilenameToWriterOptions_FullOptions.txt b/Data/Baseline/OTB/Images/ioTvExtendedFilenameToWriterOptions_FullOptions.txt index 24aa9176adc183618a4eab0eff7bba66564b3169..cb15e8af02c9a9104b2c65de8163701c8602d4bf 100644 --- a/Data/Baseline/OTB/Images/ioTvExtendedFilenameToWriterOptions_FullOptions.txt +++ b/Data/Baseline/OTB/Images/ioTvExtendedFilenameToWriterOptions_FullOptions.txt @@ -6,3 +6,7 @@ BLOCKYSIZE=1024 QUALITY=75 TILED=YES +1 +1 ; -99999 +1 +4326 diff --git a/Data/Baseline/OTB/Images/ioTvExtendedFilenameToWriterOptions_NoOptions.txt b/Data/Baseline/OTB/Images/ioTvExtendedFilenameToWriterOptions_NoOptions.txt index bc148dae46a6fe0d8cf4d957fc56837d85e0d582..36b5af85f7e31afe993a955b944b12208266c2d9 100644 --- a/Data/Baseline/OTB/Images/ioTvExtendedFilenameToWriterOptions_NoOptions.txt +++ b/Data/Baseline/OTB/Images/ioTvExtendedFilenameToWriterOptions_NoOptions.txt @@ -3,3 +3,5 @@ 0 1 0 +0 +0 diff --git a/Data/Baseline/OTB/Images/ioTvImageFileWriterTIF2TIFOutput.tif b/Data/Baseline/OTB/Images/ioTvImageFileWriterTIF2TIFOutput.tif new file mode 100644 index 0000000000000000000000000000000000000000..cc6fa20f33988e4c299d3f72ab3942029811d194 --- /dev/null +++ b/Data/Baseline/OTB/Images/ioTvImageFileWriterTIF2TIFOutput.tif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:066954e96682c1d8f0641c8501ab29f6d82d0dce44bb170ec9f9166552cd7982 +size 250778 diff --git a/Documentation/Cookbook/rst/ExtendedFilenames.rst b/Documentation/Cookbook/rst/ExtendedFilenames.rst index e1319dfe624e1e7edb85b94303ed2a0bedf90876..cb2d22b5dca4f6a31bdaffecc8831ca3c6225aec 100644 --- a/Documentation/Cookbook/rst/ExtendedFilenames.rst +++ b/Documentation/Cookbook/rst/ExtendedFilenames.rst @@ -323,6 +323,18 @@ The available syntax for boolean options are: ----------------------------------------------- +:: + + &epsg=<(int)value> + +- To set the projection system of the output image. + +- Provide the `EPSG code`_ of the desired projection. + +.. _EPSG code : https://en.wikipedia.org/wiki/EPSG_Geodetic_Parameter_Dataset + +----------------------------------------------- + :: &multiwrite==<(bool)false> diff --git a/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToWriterOptions.h b/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToWriterOptions.h index 582e6136acbfbd9f367a658ddd2720811e3a8797..e9f03a8684f26b4af1c76989ecd51b31ed81e02b 100644 --- a/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToWriterOptions.h +++ b/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToWriterOptions.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * Copyright (C) 2018 CS Systemes d'Information (CS SI) + * Copyright (C) 2018-2020 CS Systemes d'Information (CS SI) * * This file is part of Orfeo Toolbox * @@ -37,7 +37,13 @@ namespace otb * - &gdal:co:<KEY>=<VALUE> : the gdal creation option <KEY> * - streaming modes * - box - * See http://wiki.orfeo-toolbox.org/index.php/ExtendedFileName + * - &bands=<BANDS_LIST> : to select a subset of bands from the output image + * - &nodata=<VALUE>/<VALUE:VALUE...> : to set specific nodata values + * - &multiwrite=<(bool)false> : to desactivate multi-writing + * - &epsg=<VALUE> : to set the spatial reference system + * + * See http://wiki.orfeo-toolbox.org/index.php/ExtendedFileName for + * more information * * \sa ImageFileWriter * @@ -76,6 +82,7 @@ public: std::pair<bool, double> streamingSizeValue; std::pair<bool, std::string> box; std::pair<bool, std::string> bandRange; + std::pair<bool, unsigned int> srsValue; std::vector<std::string> optionList; }; @@ -111,6 +118,8 @@ public: bool StreamingSizeValueIsSet() const; double GetStreamingSizeValue() const; std::string GetBandRange() const; + bool SrsValueIsSet() const; + unsigned int GetSrsValue() const; bool BoxIsSet() const; std::string GetBox() const; diff --git a/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToWriterOptions.cxx b/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToWriterOptions.cxx index 068063e4111cdccba88b8003f301774021de92e4..055923bb52024339931f2dd61168d63edf1edbfa 100644 --- a/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToWriterOptions.cxx +++ b/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToWriterOptions.cxx @@ -1,6 +1,6 @@ /* * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * Copyright (C) 2018 CS Systemes d'Information (CS SI) + * Copyright (C) 2018-2020 CS Systemes d'Information (CS SI) * * This file is part of Orfeo Toolbox * @@ -52,8 +52,10 @@ ExtendedFilenameToWriterOptions::ExtendedFilenameToWriterOptions() : ExtendedFil m_Options.bandRange.first = false; m_Options.bandRange.second = ""; + m_Options.srsValue.first = false; + m_Options.optionList = {"writegeom", "writerpctags", "multiwrite", "streaming:type", - "streaming:sizemode", "streaming:sizevalue", "nodata", "box", "bands"}; + "streaming:sizemode", "streaming:sizevalue", "nodata", "box", "bands", "epsg"}; } void ExtendedFilenameToWriterOptions::SetExtendedFileName(const char* extFname) @@ -216,6 +218,34 @@ void ExtendedFilenameToWriterOptions::SetExtendedFileName(const std::string& ext } } + if (!map["epsg"].empty()) + { + int code; + try + { + code = std::stoi(map["epsg"]); + } + catch(const std::invalid_argument& e) + { + itkWarningMacro("Invalid value (" + << map["epsg"] + << ") for Geographic coordinate reference system. Must be integer."); + code = 0; + } + if (code < 0) + { + itkWarningMacro("Invalid value (" + << map["epsg"] + << ") for Geographic coordinate reference system. Must be positive."); + code = 0; + } + if (code > 0) + { + m_Options.srsValue.first = true; + m_Options.srsValue.second = (unsigned int) code; + } + } + // Option Checking for (it = map.begin(); it != map.end(); it++) { @@ -336,4 +366,14 @@ std::string ExtendedFilenameToWriterOptions::GetBandRange() const return m_Options.bandRange.second; } +bool ExtendedFilenameToWriterOptions::SrsValueIsSet() const +{ + return m_Options.srsValue.first; +} + +unsigned int ExtendedFilenameToWriterOptions::GetSrsValue() const +{ + return m_Options.srsValue.second; +} + } // end namespace otb diff --git a/Modules/IO/ExtendedFilename/test/CMakeLists.txt b/Modules/IO/ExtendedFilename/test/CMakeLists.txt index e6b14d78eb5d54c42b80961647d549478f50f510..6be14b984b2d5c2c49e7542758d41bac5efca4c1 100644 --- a/Modules/IO/ExtendedFilename/test/CMakeLists.txt +++ b/Modules/IO/ExtendedFilename/test/CMakeLists.txt @@ -1,5 +1,6 @@ # # Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) +# Copyright (C) 2020 CS Systemes d'Information (CS SI) # # This file is part of Orfeo Toolbox # @@ -58,7 +59,7 @@ otb_add_test(NAME ioTvExtendedFilenameToReaderOptions_FullOptions COMMAND otbExt ${BASELINE}/ioTvExtendedFilenameToReaderOptions_FullOptions.txt ${TEMP}/ioTvExtendedFilenameToReaderOptions_FullOptions.txt otbExtendedFilenameToReaderOptions - /home/data/filename.tif?&geom=/home/dev/custom.geom&sdataidx=2&resol=4&skipcarto=On&bands=-23,:3,45:,-6:-6,234:-5&nodata=-99999 + /home/data/filename.tif?&geom=/home/dev/custom.geom&sdataidx=2&resol=4&skipcarto=On&bands=-23,:3,45:,-6:-6,234:-5 ${TEMP}/ioTvExtendedFilenameToReaderOptions_FullOptions.txt ) @@ -86,7 +87,7 @@ otb_add_test(NAME ioTvExtendedFilenameToWriterOptions_FullOptions COMMAND otbExt ${BASELINE}/ioTvExtendedFilenameToWriterOptions_FullOptions.txt ${TEMP}/ioTvExtendedFilenameToWriterOptions_FullOptions.txt otbExtendedFilenameToWriterOptions - /home/data/filename.tif?&writegeom=ON&gdal:co:QUALITY=75&gdal:co:TILED=YES&gdal:co:BLOCKYSIZE=1024 + /home/data/filename.tif?&writegeom=ON&gdal:co:QUALITY=75&gdal:co:TILED=YES&gdal:co:BLOCKYSIZE=1024&nodata=-99999&epsg=4326 ${TEMP}/ioTvExtendedFilenameToWriterOptions_FullOptions.txt ) diff --git a/Modules/IO/ExtendedFilename/test/otbExtendedFilenameToWriterOptionsTest.cxx b/Modules/IO/ExtendedFilename/test/otbExtendedFilenameToWriterOptionsTest.cxx index fd4b64437e622e101cd80f58a438a4cbca6d802e..6ad79a8f8966be3b0e35dbb40af70b62f4576bcc 100644 --- a/Modules/IO/ExtendedFilename/test/otbExtendedFilenameToWriterOptionsTest.cxx +++ b/Modules/IO/ExtendedFilename/test/otbExtendedFilenameToWriterOptionsTest.cxx @@ -1,5 +1,6 @@ /* * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * Copyright (C) 2020 CS Systemes d'Information (CS SI) * * This file is part of Orfeo Toolbox * @@ -45,10 +46,25 @@ int otbExtendedFilenameToWriterOptions(int itkNotUsed(argc), char* argv[]) file << helper->gdalCreationOptionsIsSet() << std::endl; if (helper->gdalCreationOptionsIsSet()) + { for (unsigned int i = 0; i < helper->GetgdalCreationOptions().size(); i++) { file << helper->GetgdalCreationOptions()[i] << std::endl; } + } + + file << helper->NoDataValueIsSet() << std::endl; + if (helper->NoDataValueIsSet()) + { + for (auto const& nodata_kv : helper->GetNoDataList()) + { + file << nodata_kv.first << " ; " << nodata_kv.second << "\n"; + } + } + + file << helper->SrsValueIsSet() << std::endl; + if (helper->SrsValueIsSet()) + file << helper->GetSrsValue() << std::endl; return EXIT_SUCCESS; } diff --git a/Modules/IO/IOGDAL/include/otbGDALImageIO.h b/Modules/IO/IOGDAL/include/otbGDALImageIO.h index aeb1870facc07e170aa31d6985ea3b498969f5fe..7de21d9db923ce7b81e18412a20679b6a79476ad 100644 --- a/Modules/IO/IOGDAL/include/otbGDALImageIO.h +++ b/Modules/IO/IOGDAL/include/otbGDALImageIO.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * Copyright (C) 2018 CS Systemes d'Information (CS SI) + * Copyright (C) 2018-2020 CS Systemes d'Information (CS SI) * * This file is part of Orfeo Toolbox * @@ -30,6 +30,7 @@ #include "otbImageIOBase.h" #include "OTBIOGDALExport.h" +#include "otbSpatialReference.h" namespace otb { @@ -197,6 +198,9 @@ public: itkGetMacro(NbBands, int); + /** Set the projection system from EPSG code */ + void SetEpsgCode(const unsigned int wellKnownCRS); + protected: /** * Constructor. @@ -246,9 +250,10 @@ private: /** GDAL parameters. */ typedef itk::SmartPointer<GDALDatasetWrapper> GDALDatasetWrapperPointer; GDALDatasetWrapperPointer m_Dataset; + unsigned int m_epsgCode; GDALDataTypeWrapper* m_PxType; - /** Nombre d'octets par pixel */ + /** Number of bytes per pixel */ int m_BytePerPixel; bool GDALInfoReportCorner(const char* corner_name, double x, double y, double& dfGeoX, double& dfGeoY) const; diff --git a/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx b/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx index 165b4549ecf9aabd60e1e7484d7a43414123a6f8..81e4492bad076ed8cc71e044a19c2805f6513111 100644 --- a/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx +++ b/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx @@ -1,6 +1,6 @@ /* * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * Copyright (C) 2018 CS Systemes d'Information (CS SI) + * Copyright (C) 2018-2020 CS Systemes d'Information (CS SI) * * This file is part of Orfeo Toolbox * @@ -116,6 +116,8 @@ GDALImageIO::GDALImageIO() m_ResolutionFactor = 0; m_BytePerPixel = 0; m_WriteRPCTags = false; + + m_epsgCode = 0; } GDALImageIO::~GDALImageIO() @@ -405,6 +407,11 @@ std::vector<std::string> GDALImageIO::GetOverviewsInfo() return desc; } +void GDALImageIO::SetEpsgCode(const unsigned int epsgCode) +{ + m_epsgCode = epsgCode; +} + void GDALImageIO::InternalReadImageInformation() { itk::ExposeMetaData<unsigned int>(this->GetMetaDataDictionary(), MetaDataKey::ResolutionFactor, m_ResolutionFactor); @@ -1165,6 +1172,13 @@ void GDALImageIO::Write(const void* buffer) lFirstColumn = 0; } + // If needed, set the coordinate reference + if (m_epsgCode != 0) + { + auto spatialReference = SpatialReference::FromEPSG(m_epsgCode); + m_Dataset->GetDataSet()->SetProjection(spatialReference.ToWkt().c_str()); + } + // Convert buffer from void * to unsigned char * // unsigned char *p = static_cast<unsigned char*>( const_cast<void *>(buffer)); // printDataBuffer(p, m_PxType->pixType, m_NbBands, 10*2); // Buffer incorrect diff --git a/Modules/IO/ImageIO/include/otbImageFileWriter.h b/Modules/IO/ImageIO/include/otbImageFileWriter.h index 41abb75f0f2eef68447b2a84d12785e3686d5a41..ef987d753eb5ea087f3ae5cf89a811ad82ebecf6 100644 --- a/Modules/IO/ImageIO/include/otbImageFileWriter.h +++ b/Modules/IO/ImageIO/include/otbImageFileWriter.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * Copyright (C) 2020 CS Systemes d'Information (CS SI) * * This file is part of Orfeo Toolbox * @@ -57,7 +58,7 @@ namespace otb * \sa ImageFileReader * \sa ImageSeriesReader * \sa ImageIOBase - * \sa ExtendedFilenameToReaderOptions + * \sa ExtendedFilenameToWriterOptions * * \ingroup OTBImageIO */ diff --git a/Modules/IO/ImageIO/include/otbImageFileWriter.hxx b/Modules/IO/ImageIO/include/otbImageFileWriter.hxx index fd3a8ae57fda623ed8ad08fa08dea84caf8f0c9e..543639ccdb5073e06f4c2f1d65689563b905eaa5 100644 --- a/Modules/IO/ImageIO/include/otbImageFileWriter.hxx +++ b/Modules/IO/ImageIO/include/otbImageFileWriter.hxx @@ -1,6 +1,6 @@ /* * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * Copyright (C) 2018 CS Systemes d'Information (CS SI) + * Copyright (C) 2018-2020 CS Systemes d'Information (CS SI) * * This file is part of Orfeo Toolbox * @@ -421,7 +421,7 @@ void ImageFileWriter<TInputImage>::GenerateOutputInformation(void) // Manage extended filename if ((strcmp(m_ImageIO->GetNameOfClass(), "GDALImageIO") == 0) && - (m_FilenameHelper->gdalCreationOptionsIsSet() || m_FilenameHelper->WriteRPCTagsIsSet() || m_FilenameHelper->NoDataValueIsSet())) + (m_FilenameHelper->gdalCreationOptionsIsSet() || m_FilenameHelper->WriteRPCTagsIsSet() || m_FilenameHelper->NoDataValueIsSet() || m_FilenameHelper->SrsValueIsSet())) { typename GDALImageIO::Pointer imageIO = dynamic_cast<GDALImageIO*>(m_ImageIO.GetPointer()); @@ -438,6 +438,8 @@ void ImageFileWriter<TInputImage>::GenerateOutputInformation(void) imageIO->SetWriteRPCTags(m_FilenameHelper->GetWriteRPCTags()); if (m_FilenameHelper->NoDataValueIsSet()) imageIO->SetNoDataList(m_FilenameHelper->GetNoDataList()); + if (m_FilenameHelper->SrsValueIsSet()) + imageIO->SetEpsgCode(m_FilenameHelper->GetSrsValue()); } diff --git a/Modules/IO/ImageIO/test/CMakeLists.txt b/Modules/IO/ImageIO/test/CMakeLists.txt index 0c93a78ab691d2dc6b7a239945f83b205353760e..203716f813b0e98776cf35782313bae9092f00eb 100644 --- a/Modules/IO/ImageIO/test/CMakeLists.txt +++ b/Modules/IO/ImageIO/test/CMakeLists.txt @@ -1,5 +1,6 @@ # # Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) +# Copyright (C) 2020 CS Systemes d'Information (CS SI) # # This file is part of Orfeo Toolbox # @@ -910,6 +911,13 @@ otb_add_test(NAME ioTvImageFileWriterPNG2BSQ COMMAND otbImageIOTestDriver otbImageFileWriterTest ${INPUTDATA}/cthead1.png ${TEMP}/ioImageFileWriterPNG2BSQ_cthead1.hdr ) + +otb_add_test(NAME ioTvImageFileWriterTIF2TIF COMMAND otbImageIOTestDriver + --compare-image ${EPSILON_9} ${BASELINE}/ioTvImageFileWriterTIF2TIFOutput.tif + ${TEMP}/ioImageFileWriterTIF2TIF_QB_Toulouse_Ortho_PAN.tif + otbImageFileWriterTest + ${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif + ${TEMP}/ioImageFileWriterTIF2TIF_QB_Toulouse_Ortho_PAN.tif?epsg=4326 ) otb_add_test(NAME ioTvCompareWritingComplexImage_TIF COMMAND otbImageIOTestDriver otbCompareWritingComplexImageTest