From d4a0e740b3a196133920abef320239aa17b7d9f4 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Sat, 26 Mar 2011 12:32:44 -0700 Subject: [PATCH] ENH: correct handling of parameters --- Code/IO/otbMapProjectionWrapper.cxx | 49 ++++++++++++++++++- Code/IO/otbMapProjectionWrapper.h | 12 +++++ .../Code/IO/otbMapProjectionWrapperTest.cxx | 2 + 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Code/IO/otbMapProjectionWrapper.cxx b/Code/IO/otbMapProjectionWrapper.cxx index d2675c1605..29e9a63fc3 100644 --- a/Code/IO/otbMapProjectionWrapper.cxx +++ b/Code/IO/otbMapProjectionWrapper.cxx @@ -17,10 +17,12 @@ =========================================================================*/ #include "otbMapProjectionWrapper.h" + +#include <cassert> + #include "otbMacro.h" #include "projection/ossimMapProjection.h" - #include "projection/ossimMapProjectionFactory.h" #include "projection/ossimMapProjection.h" #include "base/ossimGpt.h" @@ -31,6 +33,8 @@ #include "base/ossimString.h" #include "gdal/ossimOgcWktTranslator.h" +#include "projection/ossimUtmProjection.h" + namespace otb { @@ -89,7 +93,14 @@ void MapProjectionWrapper::SetWkt(std::string projectionRefWkt) { this->m_ProjectionRefWkt = projectionRefWkt; reinstanciateProjection = true; - this->InstanciateProjection(); +// this->InstanciateProjection(); Should not be needed... + this->Modified(); +} + +void MapProjectionWrapper::SetParameter(std::string key, std::string value) +{ + m_ParameterStore[key] = value; + reinstanciateProjection = true; this->Modified(); } @@ -143,6 +154,7 @@ bool MapProjectionWrapper::InstanciateProjection() } this->reinstanciateProjection = false; + this->ApplyParametersToProjection(); return true; } return false; @@ -195,8 +207,41 @@ void MapProjectionWrapper::ForwardTransform(double lon, double lat, double h, z = h; } +void MapProjectionWrapper::ApplyParametersToProjection() +{ + // Start by identifying the projection, that will be necessary for + // the casting. + std::string projectionName = this->GetMapProjection()->getClassName(); + + StoreType::const_iterator it; + + // Apply parameters to Utm + if (projectionName.compare("ossimUtmProjection") == 0) + { + ossimUtmProjection* projection = dynamic_cast<ossimUtmProjection*>(this->GetMapProjection()); + it = m_ParameterStore.find("Zone"); + if (it != m_ParameterStore.end()) + { + int zone = atoi((*it).second.c_str()); + projection->setZone(zone); + } + it = m_ParameterStore.find("Hemisphere"); + if (it != m_ParameterStore.end()) + { + projection->setHemisphere((*it).second[0]); + } + } +} + void MapProjectionWrapper::PrintMap() const { std::cout << m_MapProjection->print(std::cout); + std::cout << "Parameter store:\n"; + for (StoreType::const_iterator it = m_ParameterStore.begin(); + it != m_ParameterStore.end(); + ++it) + { + std::cout << " " << (*it).first << ": " << (*it).second << "\n"; + } } } // namespace otb diff --git a/Code/IO/otbMapProjectionWrapper.h b/Code/IO/otbMapProjectionWrapper.h index c8afab5a83..a373de286f 100644 --- a/Code/IO/otbMapProjectionWrapper.h +++ b/Code/IO/otbMapProjectionWrapper.h @@ -18,6 +18,9 @@ #ifndef __otbMapProjectionWrapper_h #define __otbMapProjectionWrapper_h +#include <string> +#include <map> + #include "itkObject.h" #include "itkObjectFactory.h" @@ -61,6 +64,8 @@ public: std::string GetWkt(); void SetWkt(std::string projectionRefWkt); + void SetParameter(std::string key, std::string value); + bool InstanciateProjection(); void InverseTransform(double x, double y, double z, @@ -69,18 +74,25 @@ public: double& x, double& y, double& z); void PrintMap() const; + protected: MapProjectionWrapper(); virtual ~MapProjectionWrapper(); + private: MapProjectionWrapper(const Self &); //purposely not implemented void operator =(const Self&); //purposely not implemented + void ApplyParametersToProjection(); + InternalMapProjectionPointer m_MapProjection; std::string m_ProjectionRefWkt; + typedef std::map<std::string, std::string> StoreType; + StoreType m_ParameterStore; + bool reinstanciateProjection; }; } // namespace otb diff --git a/Testing/Code/IO/otbMapProjectionWrapperTest.cxx b/Testing/Code/IO/otbMapProjectionWrapperTest.cxx index a548b97348..7b0f7e5f52 100644 --- a/Testing/Code/IO/otbMapProjectionWrapperTest.cxx +++ b/Testing/Code/IO/otbMapProjectionWrapperTest.cxx @@ -177,6 +177,8 @@ int otbMapProjectionWrapperTest(int argc, char* argv[]) otb::MapProjectionWrapper::Pointer genericMapProjection = otb::MapProjectionWrapper::New(); genericMapProjection->SetWkt(projectionRefWkt); + genericMapProjection->SetParameter("Zone", "46"); + genericMapProjection->SetParameter("Hemisphere", "S"); file << "Instanciating from : " << projectionRefWkt << std::endl; file << genericMapProjection->GetWkt() << std::endl << std::endl; -- GitLab