Skip to content
Snippets Groups Projects
Commit c526551c authored by Julien Malik's avatar Julien Malik
Browse files

ENH: add test for instanciation of GenericRSTransform from image projref and kwl

parent 2176f919
No related branches found
No related tags found
No related merge requests found
...@@ -208,18 +208,33 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions> ...@@ -208,18 +208,33 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
{ {
typedef otb::InverseSensorModel<double, InputSpaceDimension, OutputSpaceDimension> InverseSensorModelType; typedef otb::InverseSensorModel<double, InputSpaceDimension, OutputSpaceDimension> InverseSensorModelType;
typename InverseSensorModelType::Pointer sensorModel = InverseSensorModelType::New(); typename InverseSensorModelType::Pointer sensorModel = InverseSensorModelType::New();
sensorModel->SetImageGeometry(m_OutputKeywordList);
if (!m_DEMDirectory.empty()) bool imageGeometrySet = false;
try
{
sensorModel->SetImageGeometry(m_OutputKeywordList);
imageGeometrySet = true;
}
catch( itk::ExceptionObject& e)
{ {
sensorModel->SetDEMDirectory(m_DEMDirectory); otbMsgDevMacro(<< "Unable to instanciate a sensor model with the provided output keyword list. Exception caught : " << e)
} }
else if (m_AverageElevation != -32768.0)
if (imageGeometrySet)
{ {
sensorModel->SetAverageElevation(m_AverageElevation); if (!m_DEMDirectory.empty())
{
sensorModel->SetDEMDirectory(m_DEMDirectory);
}
else if (m_AverageElevation != -32768.0)
{
sensorModel->SetAverageElevation(m_AverageElevation);
}
m_OutputTransform = sensorModel.GetPointer();
outputTransformIsSensor = true;
otbMsgDevMacro(<< "Output projection set to sensor model");
} }
m_OutputTransform = sensorModel.GetPointer();
outputTransformIsSensor = true;
otbMsgDevMacro(<< "Output projection set to sensor model");
} }
......
...@@ -819,6 +819,10 @@ ADD_TEST(prTvGenericRSTransformWithSRID ${PROJECTIONS_TESTS3} ...@@ -819,6 +819,10 @@ ADD_TEST(prTvGenericRSTransformWithSRID ${PROJECTIONS_TESTS3}
) )
ADD_TEST(prTvGenericRSTransformFromImage ${PROJECTIONS_TESTS3}
otbGenericRSTransformFromImage
${INPUTDATA}/WithoutProjRefWithKeywordlist.tif)
ADD_TEST(prTuVectorDataProjectionFilterNew ${PROJECTIONS_TESTS3} otbVectorDataProjectionFilterNew ) ADD_TEST(prTuVectorDataProjectionFilterNew ${PROJECTIONS_TESTS3} otbVectorDataProjectionFilterNew )
#test points #test points
...@@ -1062,6 +1066,7 @@ otbGenericMapProjection.cxx ...@@ -1062,6 +1066,7 @@ otbGenericMapProjection.cxx
otbGenericRSTransformNew.cxx otbGenericRSTransformNew.cxx
otbGenericRSTransform.cxx otbGenericRSTransform.cxx
otbGenericRSTransformWithSRID.cxx otbGenericRSTransformWithSRID.cxx
otbGenericRSTransformFromImage.cxx
otbVectorDataProjectionFilterNew.cxx otbVectorDataProjectionFilterNew.cxx
otbVectorDataProjectionFilter.cxx otbVectorDataProjectionFilter.cxx
otbVectorDataProjectionFilterFromMapToSensor.cxx otbVectorDataProjectionFilterFromMapToSensor.cxx
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbGenericRSTransform.h"
#include <ogr_spatialref.h>
#include <fstream>
typedef otb::VectorImage<double, 2> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::GenericRSTransform<> TransformType;
typedef TransformType::InputPointType PointType;
int otbGenericRSTransformFromImage(int argc, char* argv[])
{
/*
* This test checks if we can instanciate a GenericRSTransform from the image information
* without throwing an exception
*/
// Reader
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->UpdateOutputInformation();
// Build wgs ref
OGRSpatialReference oSRS;
oSRS.SetWellKnownGeogCS("WGS84");
char * wgsRef = NULL;
oSRS.exportToWkt(&wgsRef);
// Instanciate WGS->Image transform
TransformType::Pointer wgs2img = TransformType::New();
wgs2img->SetInputProjectionRef(wgsRef);
wgs2img->SetOutputProjectionRef(reader->GetOutput()->GetProjectionRef());
wgs2img->SetOutputKeywordList(reader->GetOutput()->GetImageKeywordlist());
wgs2img->InstanciateTransform();
// Instanciate Image->WGS transform
TransformType::Pointer img2wgs = TransformType::New();
img2wgs->SetInputProjectionRef(reader->GetOutput()->GetProjectionRef());
img2wgs->SetInputKeywordList(reader->GetOutput()->GetImageKeywordlist());
img2wgs->SetOutputProjectionRef(wgsRef);
img2wgs->InstanciateTransform();
return EXIT_SUCCESS;
}
...@@ -59,13 +59,13 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[]) ...@@ -59,13 +59,13 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[])
spacing[0] = 0.000006; spacing[0] = 0.000006;
spacing[1] = -0.000006; spacing[1] = -0.000006;
// Filter : Taget SRS : WGS84 // Filter : Target SRS : WGS84
FilterType::Pointer filter = FilterType::New(); FilterType::Pointer filter = FilterType::New();
filter->SetInput(reader->GetOutput()); filter->SetInput(reader->GetOutput());
filter->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(4326)); //WGS84 filter->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(4326)); //WGS84
filter->Compute(); filter->Compute();
// Otuput file // Output file
std::ofstream outfile(outfname); std::ofstream outfile(outfname);
outfile<<"Output Parameters for SRID : 4326 (WGS84)"<<std::endl; outfile<<"Output Parameters for SRID : 4326 (WGS84)"<<std::endl;
...@@ -74,7 +74,7 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[]) ...@@ -74,7 +74,7 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[])
outfile<<"Output Size : "<<filter->GetOutputSize()<<std::endl; outfile<<"Output Size : "<<filter->GetOutputSize()<<std::endl;
outfile<< std::endl; outfile<< std::endl;
// target SRS : 32631 UTM 31 N // Target SRS : 32631 UTM 31 N
filter->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(32631)); //WGS84 filter->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(32631)); //WGS84
filter->Compute(); filter->Compute();
...@@ -84,7 +84,7 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[]) ...@@ -84,7 +84,7 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[])
outfile<<"Output Size : "<<filter->GetOutputSize()<<std::endl; outfile<<"Output Size : "<<filter->GetOutputSize()<<std::endl;
outfile<< std::endl; outfile<< std::endl;
// target SRS : lambertII // Target SRS : lambertII
typedef otb::Lambert2EtenduForwardProjection Lambert2Type; typedef otb::Lambert2EtenduForwardProjection Lambert2Type;
Lambert2Type::Pointer lambert2Projection = Lambert2Type::New(); Lambert2Type::Pointer lambert2Projection = Lambert2Type::New();
std::string lambertRef = lambert2Projection->GetWkt(); std::string lambertRef = lambert2Projection->GetWkt();
......
...@@ -33,6 +33,7 @@ void RegisterTests() ...@@ -33,6 +33,7 @@ void RegisterTests()
REGISTER_TEST(otbGenericRSTransformNew); REGISTER_TEST(otbGenericRSTransformNew);
REGISTER_TEST(otbGenericRSTransform); REGISTER_TEST(otbGenericRSTransform);
REGISTER_TEST(otbGenericRSTransformWithSRID); REGISTER_TEST(otbGenericRSTransformWithSRID);
REGISTER_TEST(otbGenericRSTransformFromImage);
REGISTER_TEST(otbVectorDataProjectionFilterNew); REGISTER_TEST(otbVectorDataProjectionFilterNew);
REGISTER_TEST(otbVectorDataProjectionFilter); REGISTER_TEST(otbVectorDataProjectionFilter);
REGISTER_TEST(otbVectorDataProjectionFilterFromMapToSensor); REGISTER_TEST(otbVectorDataProjectionFilterFromMapToSensor);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment