Commit 47507622 authored by Julien Osman's avatar Julien Osman

ENH: Add possibility to define the output projection with EPSG code in otbGDALImageIO

parent c035b340
......@@ -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;
......
......@@ -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()->SetSpatialRef(spatialReference.getOGRSpatialReference());
}
// 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
......
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