Skip to content
Snippets Groups Projects
Commit f583c992 authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

ENH: adapt application ObtainUTMZoneFromGeoPoint to new framework

parent abfac2e9
No related branches found
No related tags found
No related merge requests found
......@@ -15,95 +15,84 @@
PURPOSE, See the above copyright notices for more information.
=========================================================================*/
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include <iostream>
#include <fstream>
#include "otbCommandLineArgumentParser.h"
#include "otbMapProjections.h"
#include "otbImage.h"
#include "itkExceptionObject.h"
#include "itkMacro.h"
#include "otbUtils.h"
int main(int argc, char* argv[])
namespace otb
{
namespace Wrapper
{
try
class ObtainUTMZoneFromGeoPoint : public Application
{
public:
/** Standard class typedefs. */
typedef ObtainUTMZoneFromGeoPoint Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(ObtainUTMZoneFromGeoPoint, otb::Application);
private:
ObtainUTMZoneFromGeoPoint()
{
// Parse command line parameters
typedef otb::CommandLineArgumentParser ParserType;
ParserType::Pointer parser = ParserType::New();
SetName("ObtainUTMZoneFromGeoPoint");
SetDescription("UTM zone determination from a geographic point.");
// Documentation
SetDocName("Obtain UTM Zone From Geo Point Application");
SetDocLongDescription("UTM zone determination from a geographic point.");
SetDocLimitations("None");
SetDocAuthors("OTB-Team");
SetDocSeeAlso(" ");
parser->SetProgramDescription("UTM zone determination from a geographic point");
parser->AddOption("--Latitude","Latitude value of desired point","-lat");
parser->AddOption("--Longitude","Longitude value of desired point","-lon");
AddDocTag(Tags::Coordinates);
}
typedef otb::CommandLineArgumentParseResult ParserResultType;
ParserResultType::Pointer parseResult = ParserResultType::New();
virtual ~ObtainUTMZoneFromGeoPoint()
{
}
try
void DoCreateParameters()
{
parser->ParseCommandLine(argc, argv, parseResult);
AddParameter(ParameterType_Float, "lat", "Latitude");
SetParameterDescription("lat", "Latitude value of desired point.");
AddParameter(ParameterType_Float, "lon", "Longitude");
SetParameterDescription("lon", "Longitude value of desired point.");
AddParameter(ParameterType_Int,"utm","UTMZone");
SetParameterDescription("utm","UTM Zone");
MandatoryOff("utm");
SetParameterRole("utm", Role_Output);
SetExampleComment("Obtain a UTM Zone", 0);
SetDocExampleParameterValue("lat","10.0");
SetDocExampleParameterValue("lon","124.0");
}
catch ( itk::ExceptionObject & err )
void DoUpdateParameters()
{
std::string descriptionException = err.GetDescription();
if (descriptionException.find("ParseCommandLine(): Help Parser") != std::string::npos)
{
std::cout << "WARNING : output file pixels are converted in 'unsigned char'" << std::endl;
return EXIT_SUCCESS;
}
if (descriptionException.find("ParseCommandLine(): Version Parser") != std::string::npos)
{
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
// Nothing to do
}
// Code
double lon = parseResult->GetParameterDouble("--Longitude");
double lat =parseResult->GetParameterDouble("--Latitude");
int utmZone = otb::Utils::GetZoneFromGeoPoint(lon, lat);
if (!parseResult->IsOptionPresent("--OTBTesting"))
void DoExecute()
{
std::cout << "Geographic Point (Lat, Lon) : (" << lat << "," << lon << ")" << std::endl;
std::cout << "UTM Corresponding Zone : ==> " << utmZone << " <==" << std::endl;
int utmZone = otb::Utils::GetZoneFromGeoPoint(GetParameterFloat("lon"),
GetParameterFloat("lat"));
SetParameterInt("utm",utmZone);
}
else
{
std::string outputTestFileName = parseResult->GetParameterString("--OTBTesting", 0);
};
std::ofstream outputTestFile;
outputTestFile.open(outputTestFileName.c_str());
outputTestFile << "Geographic Point (Lat, Lon) : (" << lat << "," << lon << ")" << std::endl;
outputTestFile << "UTM Corresponding Zone : ==> " << utmZone << " <==" << std::endl;
outputTestFile.close();
}
}
catch ( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject raised !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch ( std::bad_alloc & err )
{
std::cout << "Exception bad_alloc : "<<(char*)err.what()<< std::endl;
return EXIT_FAILURE;
}
catch ( ... )
{
std::cout << "Unknown exception raised !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::ObtainUTMZoneFromGeoPoint)
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