Skip to content
Snippets Groups Projects
Commit d4a0e740 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: correct handling of parameters

parent b8db5b1a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment