Commit d3501c26 authored by Julien Osman's avatar Julien Osman

ENH: Add new Extendded Filename 'epsg' to set the projection of the output...

ENH: Add new Extendded Filename 'epsg' to set the projection of the output image with an EPSG code + tests + doc
parent 47507622
Pipeline #4138 failed with stages
in 5 minutes and 21 seconds
......@@ -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>
......
......@@ -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;
......
......@@ -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
......@@ -86,7 +86,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&nodata=-99999
/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
)
......
......@@ -57,5 +57,9 @@ int otbExtendedFilenameToWriterOptions(int itkNotUsed(argc), char* argv[])
file << helper->GetNoDataList()[i].first << " ; " << helper->GetNoDataList()[i].second << std::endl;
}
file << helper->SrsValueIsSet() << std::endl;
if (helper->SrsValueIsSet())
file << helper->GetSrsValue() << std::endl;
return EXIT_SUCCESS;
}
......@@ -57,7 +57,7 @@ namespace otb
* \sa ImageFileReader
* \sa ImageSeriesReader
* \sa ImageIOBase
* \sa ExtendedFilenameToReaderOptions
* \sa ExtendedFilenameToWriterOptions
*
* \ingroup OTBImageIO
*/
......
......@@ -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());
}
......
......@@ -910,6 +910,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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment