Commit f18b7e44 authored by Julien Osman's avatar Julien Osman

Merge branch 'fix_1889' into 'develop'

Add "epsg" filename extension

Closes #1889

See merge request !709
parents 4a35915e 56f33fa2
Pipeline #4263 passed with stages
in 107 minutes and 43 seconds
......@@ -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>
......
......@@ -6,3 +6,7 @@
BLOCKYSIZE=1024
QUALITY=75
TILED=YES
1
1 ; -99999
1
4326
......@@ -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>
......
/*
* 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;
......
/*
* 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
#
# 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
)
......
/*
* 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;
}
/*
* 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;
......
/*
* 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
......
/*
* 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
*/
......
/*
* 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());
}
......
#
# 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
......
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