diff --git a/Testing/Code/Projections/CMakeLists.txt b/Testing/Code/Projections/CMakeLists.txt index f1297f73ec1ca508669cc3ba1460901612aa95fb..88834f8c5cefa66affb5b747c7adadd4ff54233b 100644 --- a/Testing/Code/Projections/CMakeLists.txt +++ b/Testing/Code/Projections/CMakeLists.txt @@ -378,6 +378,15 @@ ADD_TEST(prTvGenericMapProjection ${PROJECTIONS_TESTS3} ADD_TEST(prTuGenericRSTransformNew ${PROJECTIONS_TESTS3} otbGenericRSTransformNew ) +ADD_TEST(prTuGenericRSTransform ${PROJECTIONS_TESTS3} otbGenericRSTransform + --compare-ascii ${EPSILON_4} ${BASELINE_FILES}/prTvGenericMapProjection.txt + ${BASELINE_FILES}/prTvGenericRSTransform.txt + ${TEMP}/prTvGenericRSTransform.txt + 1.35617289802566 + 43.4876035537 + ${TEMP}/prTvGenericRSTransform.txt +) + ADD_TEST(prTuVectorDataProjectionFilterNew ${PROJECTIONS_TESTS3} otbVectorDataProjectionFilterNew ) #test points @@ -478,6 +487,7 @@ otbCompositeTransform.cxx otbGenericMapProjectionNew.cxx otbGenericMapProjection.cxx otbGenericRSTransformNew.cxx +otbGenericRSTransform.cxx otbVectorDataProjectionFilterNew.cxx otbVectorDataProjectionFilter.cxx otbVectorDataProjectionFilterFromMapToSensor.cxx diff --git a/Testing/Code/Projections/otbGenericRSTransform.cxx b/Testing/Code/Projections/otbGenericRSTransform.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e95d6bc9803b7141c229fbdfd40b735b9f50134c --- /dev/null +++ b/Testing/Code/Projections/otbGenericRSTransform.cxx @@ -0,0 +1,194 @@ +/*========================================================================= + + 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 "otbGenericRSTransform.h" +#include <ogr_spatialref.h> +#include <fstream> + +int otbGenericRSTransform( int argc, char* argv[] ) +{ + OGRSpatialReference oSRS; + + typedef otb::GenericRSTransform<> TransformType; + typedef TransformType::InputPointType PointType; + + PointType geoPoint; + + geoPoint[0] = atof(argv[1]); + geoPoint[1] = atof(argv[2]); + const char * outfname = argv[3]; + + + // Build wgs ref + oSRS.SetWellKnownGeogCS("WGS84"); + char * wgsRef = NULL; + oSRS.exportToWkt(&wgsRef); + + // Build UTM ref + oSRS.SetProjCS("UTM"); + oSRS.SetUTM(31,true); + char * utmRef = NULL; + oSRS.exportToWkt(&utmRef); + + + // Build Lambert II ref + double stdParallel1 = 45.89891944; + double stdParallel2 = 47.69601389; + double originLatL2 = 46.8; + double originLongL2 = 2.33722778; + double falseEastingL2 = 600000; + double falseNorthingL2 = 2200000; + oSRS.SetProjCS("Lambert II "); + oSRS.SetLCC(stdParallel1,stdParallel2,originLatL2,originLongL2,falseEastingL2,falseNorthingL2); + char * lambertRef = NULL; + oSRS.exportToWkt(&lambertRef); + + // Build the Transmercator ref + double originLatTmt = 49.83; + double originLongTmt = 6.16; + + + oSRS.SetProjCS("Transmercator "); + oSRS.SetWellKnownGeogCS("WGS84"); + oSRS.SetTM(originLatTmt,originLongTmt,1,0,0); + char * tmtRef = NULL; + oSRS.exportToWkt(&tmtRef); + + TransformType::Pointer wgs2utm = TransformType::New(); + wgs2utm->SetInputProjectionRef(wgsRef); + wgs2utm->SetOutputProjectionRef(utmRef); + wgs2utm->InstanciateTransform(); + + TransformType::Pointer utm2wgs = TransformType::New(); + wgs2utm->GetInverse(utm2wgs); + + TransformType::Pointer wgs2lambert = TransformType::New(); + wgs2lambert->SetInputProjectionRef(wgsRef); + wgs2lambert->SetOutputProjectionRef(lambertRef); + wgs2lambert->InstanciateTransform(); + + TransformType::Pointer lambert2wgs = TransformType::New(); + wgs2lambert->GetInverse(lambert2wgs); + + TransformType::Pointer wgs2tmt = TransformType::New(); + wgs2tmt->SetInputProjectionRef(wgsRef); + wgs2tmt->SetOutputProjectionRef(tmtRef); + wgs2tmt->InstanciateTransform(); + + TransformType::Pointer tmt2wgs = TransformType::New(); + wgs2tmt->GetInverse(tmt2wgs); + + TransformType::Pointer wgs2wgs = TransformType::New(); + wgs2wgs->SetInputProjectionRef(wgsRef); + wgs2wgs->SetOutputProjectionRef(wgsRef); + wgs2wgs->InstanciateTransform(); + + TransformType::Pointer utm2utm = TransformType::New(); + utm2utm->SetInputProjectionRef(utmRef); + utm2utm->SetOutputProjectionRef(utmRef); + utm2utm->InstanciateTransform(); + + TransformType::Pointer lambert2lambert = TransformType::New(); + lambert2lambert->SetInputProjectionRef(lambertRef); + lambert2lambert->SetOutputProjectionRef(lambertRef); + lambert2lambert->InstanciateTransform(); + + TransformType::Pointer tmt2tmt = TransformType::New(); + tmt2tmt->SetInputProjectionRef(tmtRef); + tmt2tmt->SetOutputProjectionRef(tmtRef); + tmt2tmt->InstanciateTransform(); + + TransformType::Pointer utm2lambert = TransformType::New(); + utm2lambert->SetInputProjectionRef(utmRef); + utm2lambert->SetOutputProjectionRef(lambertRef); + utm2lambert->InstanciateTransform(); + + TransformType::Pointer lambert2utm = TransformType::New(); + utm2lambert->GetInverse(lambert2utm); + + TransformType::Pointer utm2tmt = TransformType::New(); + utm2tmt->SetInputProjectionRef(utmRef); + utm2tmt->SetOutputProjectionRef(tmtRef); + utm2tmt->InstanciateTransform(); + + TransformType::Pointer tmt2utm = TransformType::New(); + utm2tmt->GetInverse(tmt2utm); + + TransformType::Pointer lambert2tmt = TransformType::New(); + lambert2tmt->SetInputProjectionRef(lambertRef); + lambert2tmt->SetOutputProjectionRef(tmtRef); + lambert2tmt->InstanciateTransform(); + + TransformType::Pointer tmt2lambert = TransformType::New(); + lambert2tmt->GetInverse(tmt2lambert); + + + ofstream ofs; + ofs.open(outfname); + + ofs<<"Testing geopoint: "<<geoPoint<<std::endl<<std::endl; + + + ofs<<"Testing wgs84 to wgs84: "<<geoPoint<<" -> "<<wgs2wgs->TransformPoint(geoPoint)<<std::endl; + + PointType utmPoint, lambertPoint, tmtPoint; + + utmPoint = wgs2utm->TransformPoint(geoPoint); + lambertPoint = wgs2lambert->TransformPoint(geoPoint); + tmtPoint = wgs2tmt->TransformPoint(geoPoint); + + ofs<<"Testing utm 31 north to utm 31 north: "<<utmPoint<<" -> "<<utm2utm->TransformPoint(utmPoint)<<std::endl; + ofs<<"Testing lambert 2 to lambert 2: "<<lambertPoint<<" -> "<<lambert2lambert->TransformPoint(lambertPoint)<<std::endl; + ofs<<"Testing transmercator 31 north to transmercator: "<<tmtPoint<<" -> "<<tmt2tmt->TransformPoint(tmtPoint)<<std::endl; + + + ofs<<std::endl<<"Testing geo 2 carto ..."<<std::endl<<std::endl; + + + ofs<<"Testing wgs84 to utm 31 north: "<<geoPoint<<" -> "<<utmPoint<<std::endl; + ofs<<"Testing utm 31 north to wgs84: "<<utmPoint<<" -> "<<utm2wgs->TransformPoint(utmPoint)<<std::endl; + + ofs<<"Testing wgs84 to lambert 2: "<<geoPoint<<" -> "<<lambertPoint<<std::endl; + ofs<<"Testing lambert 2 to wgs84: "<<lambertPoint<<" -> "<<lambert2wgs->TransformPoint(lambertPoint)<<std::endl; + + ofs<<"Testing wgs84 to transmeractor: "<<geoPoint<<" -> "<<tmtPoint<<std::endl; + ofs<<"Testing transmercator to wgs84: "<<tmtPoint<<" -> "<<tmt2wgs->TransformPoint(tmtPoint)<<std::endl; + + + ofs<<std::endl<<"Testing cross geo ..."<<std::endl<<std::endl; + + + ofs<<"Testing lambert 2 to utm 31 north: "<<lambertPoint<<" -> "<<lambert2utm->TransformPoint(lambertPoint)<<std::endl; + ofs<<"Testing utm 31 north to lambert 2: "<<utmPoint<<" -> "<<utm2lambert->TransformPoint(utmPoint)<<std::endl; + + ofs<<"Testing lambert 2 to transmercator: "<<lambertPoint<<" -> "<<lambert2tmt->TransformPoint(lambertPoint)<<std::endl; + ofs<<"Testing transmercator to lambert 2: "<<tmtPoint<<" -> "<<tmt2lambert->TransformPoint(tmtPoint)<<std::endl; + + + ofs<<"Testing transmercator to utm 31 north: "<<tmtPoint<<" -> "<<tmt2utm->TransformPoint(tmtPoint)<<std::endl; + ofs<<"Testing utm 31 north to transmercator: "<<utmPoint<<" -> "<<utm2tmt->TransformPoint(utmPoint)<<std::endl; + + ofs.close(); + + return EXIT_SUCCESS; +} + + diff --git a/Testing/Code/Projections/otbProjectionsTests3.cxx b/Testing/Code/Projections/otbProjectionsTests3.cxx index 6aa8ab16803c478d2c56aee4ea198dcf3c0a3187..712ecb957e3f7d744fecb3a7eaf677de44ecf0ee 100644 --- a/Testing/Code/Projections/otbProjectionsTests3.cxx +++ b/Testing/Code/Projections/otbProjectionsTests3.cxx @@ -32,6 +32,7 @@ void RegisterTests() REGISTER_TEST(otbGenericMapProjectionNew); REGISTER_TEST(otbGenericMapProjection); REGISTER_TEST(otbGenericRSTransformNew); + REGISTER_TEST(otbGenericRSTransform); REGISTER_TEST(otbVectorDataProjectionFilterNew); REGISTER_TEST(otbVectorDataProjectionFilter); REGISTER_TEST(otbVectorDataProjectionFilterFromMapToSensor);