From 68fce07607bff1d31e1849d8a1eb663b91df2979 Mon Sep 17 00:00:00 2001 From: Otmane Lahlou <otmane.lahlou@c-s.fr> Date: Mon, 27 Sep 2010 15:21:48 +0200 Subject: [PATCH] ADD: testing srid accessors --- Testing/Code/Projections/CMakeLists.txt | 24 +- .../otbGenericRSTransformWithSRID.cxx | 211 ++++++++++++++++++ .../Code/Projections/otbProjectionsTests3.cxx | 1 + 3 files changed, 226 insertions(+), 10 deletions(-) create mode 100644 Testing/Code/Projections/otbGenericRSTransformWithSRID.cxx diff --git a/Testing/Code/Projections/CMakeLists.txt b/Testing/Code/Projections/CMakeLists.txt index b1a074849c..d021eb7f1b 100644 --- a/Testing/Code/Projections/CMakeLists.txt +++ b/Testing/Code/Projections/CMakeLists.txt @@ -317,7 +317,6 @@ ADD_TEST(prTvOrthoRectificationCevennes ${PROJECTIONS_TESTS2} 4.881e+06 500 500 -# 220 0.5 -0.5 31 @@ -335,14 +334,12 @@ ADD_TEST(prTvOrthoRectificationToulouseWithDEM ${PROJECTIONS_TESTS2} 4829184.8 500 500 -# 220 0.5 -0.5 31 N ${INPUTDATA}/DEM/srtm_directory/ - 4 -# ${TEMP}/prTvOrthoRectificationToulouseWithDEM_UTM.tif + 0.5 ) ADD_TEST(prTvOrthoRectificationCevennesWithDEM ${PROJECTIONS_TESTS2} @@ -355,19 +352,14 @@ ADD_TEST(prTvOrthoRectificationCevennesWithDEM ${PROJECTIONS_TESTS2} 4.881e+06 500 500 -# 200 0.5 -0.5 31 N ${INPUTDATA}/DEM/srtm_directory/ - 4 -# ${TEMP}/prTvOrthoRectificationCevennesWithDEM_UTM.tif + 0.5 ) - - - #========================= Ortho rectif SPOT5 =============================== ADD_TEST(prTlOrthoRectificationSPOT5 ${PROJECTIONS_TESTS2} @@ -531,6 +523,17 @@ ADD_TEST(prTvGenericRSTransform ${PROJECTIONS_TESTS3} ${TEMP}/prTvGenericRSTransform.txt ) +ADD_TEST(prTvGenericRSTransformWithSRID ${PROJECTIONS_TESTS3} + --compare-ascii ${EPSILON_4} + ${BASELINE_FILES}/prTvGenericRSTransform.txt + ${TEMP}/prTvGenericRSTransform_WithSRID.txt + otbGenericRSTransformWithSRID + 1.35617289802566 + 43.4876035537 + ${TEMP}/prTvGenericRSTransform_WithSRID.txt +) + + ADD_TEST(prTuVectorDataProjectionFilterNew ${PROJECTIONS_TESTS3} otbVectorDataProjectionFilterNew ) #test points @@ -719,6 +722,7 @@ otbGenericMapProjectionNew.cxx otbGenericMapProjection.cxx otbGenericRSTransformNew.cxx otbGenericRSTransform.cxx +otbGenericRSTransformWithSRID.cxx otbVectorDataProjectionFilterNew.cxx otbVectorDataProjectionFilter.cxx otbVectorDataProjectionFilterFromMapToSensor.cxx diff --git a/Testing/Code/Projections/otbGenericRSTransformWithSRID.cxx b/Testing/Code/Projections/otbGenericRSTransformWithSRID.cxx new file mode 100644 index 0000000000..e4a1524559 --- /dev/null +++ b/Testing/Code/Projections/otbGenericRSTransformWithSRID.cxx @@ -0,0 +1,211 @@ +/*========================================================================= + + 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> + +/** + * This test is the same than the otbGenericRSTransform + * except using the SRID to build the wkt. + */ + +int otbGenericRSTransformWithSRID(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 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->SetInputSRID(4326); // WGS 84 + wgs2utm->SetOutputSRID(32631); // UTM 31 N + wgs2utm->InstanciateTransform(); + + TransformType::Pointer utm2wgs = TransformType::New(); + wgs2utm->GetInverse(utm2wgs); + + TransformType::Pointer wgs2lambert = TransformType::New(); + wgs2lambert->SetInputSRID(4326); // WGS 84 + wgs2lambert->SetOutputProjectionRef(lambertRef); + + wgs2lambert->InstanciateTransform(); + + TransformType::Pointer lambert2wgs = TransformType::New(); + wgs2lambert->GetInverse(lambert2wgs); + + TransformType::Pointer wgs2tmt = TransformType::New(); + wgs2tmt->SetInputSRID(4326); // WGS 84 + wgs2tmt->SetOutputProjectionRef(tmtRef); + + wgs2tmt->InstanciateTransform(); + + TransformType::Pointer tmt2wgs = TransformType::New(); + wgs2tmt->GetInverse(tmt2wgs); + + TransformType::Pointer wgs2wgs = TransformType::New(); + wgs2wgs->SetInputSRID(4326); // WGS 84 + wgs2wgs->SetOutputSRID(4326); // WGS 84 + wgs2wgs->InstanciateTransform(); + + TransformType::Pointer utm2utm = TransformType::New(); + utm2utm->SetInputSRID(32631); // UTM 31 N + utm2utm->SetOutputSRID(32631); // UTM 31 N + 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->SetInputSRID(32631); // UTM + utm2lambert->SetOutputProjectionRef(lambertRef); + + utm2lambert->InstanciateTransform(); + + TransformType::Pointer lambert2utm = TransformType::New(); + utm2lambert->GetInverse(lambert2utm); + + TransformType::Pointer utm2tmt = TransformType::New(); + utm2tmt->SetInputSRID(32631); + 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); + + // Set floatfield to format writing properly + ofs.setf(ios::fixed, ios::floatfield); + ofs.precision(10); + + 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.precision(3); + + 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.precision(10); + + ofs << "Testing wgs84 to utm 31 north: " << geoPoint; + ofs.precision(3); + ofs << " -> " << utmPoint << std::endl; + ofs << "Testing utm 31 north to wgs84: " << utmPoint; + ofs.precision(10); + ofs << " -> " << utm2wgs->TransformPoint(utmPoint) << std::endl; + + ofs << "Testing wgs84 to lambert 2: " << geoPoint; + ofs.precision(3); + ofs << " -> " << lambertPoint << std::endl; + ofs << "Testing lambert 2 to wgs84: " << lambertPoint; + ofs.precision(10); + ofs << " -> " << lambert2wgs->TransformPoint(lambertPoint) << std::endl; + + ofs << "Testing wgs84 to transmeractor: " << geoPoint; + ofs.precision(3); + ofs << " -> " << tmtPoint << std::endl; + ofs << "Testing transmercator to wgs84: " << tmtPoint; + ofs.precision(10); + ofs << " -> " << tmt2wgs->TransformPoint(tmtPoint) << std::endl; + + ofs << std::endl << "Testing cross geo ..." << std::endl << std::endl; + + ofs.precision(3); + + 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 397914966f..8a7823dc64 100644 --- a/Testing/Code/Projections/otbProjectionsTests3.cxx +++ b/Testing/Code/Projections/otbProjectionsTests3.cxx @@ -32,6 +32,7 @@ void RegisterTests() REGISTER_TEST(otbGenericMapProjection); REGISTER_TEST(otbGenericRSTransformNew); REGISTER_TEST(otbGenericRSTransform); + REGISTER_TEST(otbGenericRSTransformWithSRID); REGISTER_TEST(otbVectorDataProjectionFilterNew); REGISTER_TEST(otbVectorDataProjectionFilter); REGISTER_TEST(otbVectorDataProjectionFilterFromMapToSensor); -- GitLab