Commit 3d693036 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: easier use of EPSG code in GenericRSTransform

parent b89f4ee3
......@@ -19,6 +19,7 @@
#include "ogr_spatialref.h"
#include "cpl_conv.h"
#include "boost/lexical_cast.hpp"
namespace otb
{
......@@ -45,4 +46,18 @@ std::string GeoInformationConversion::ToWKT(int srid)
return ret;
}
std::string GeoInformationConversion::ToWKT(const std::string& candidateSrid)
{
std::string wkt(candidateSrid);
try
{
int srid = boost::lexical_cast<int>(candidateSrid);
return GeoInformationConversion::ToWKT(srid);
}
catch(boost::bad_lexical_cast &)
{
return wkt;
}
}
} // End namespace otb
......@@ -38,6 +38,7 @@ class GeoInformationConversion
public:
/** method used to create a wkt from an epsg number */
static std::string ToWKT(int srid);
static std::string ToWKT(const std::string& candidateSrid);
protected:
GeoInformationConversion(); // not implemented
......
......@@ -23,11 +23,10 @@
#include "otbMetaDataKey.h"
#include "itkMetaDataObject.h"
#include "itkExceptionObject.h"
#include "otbGeoInformationConversion.h"
#include "ogr_spatialref.h"
//TODO OTB wrapper around the WKT/ossimProjection/isGeographic, etc.
namespace otb
{
......@@ -107,6 +106,18 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
bool outputTransformIsSensor = false;
bool outputTransformIsMap = false;
// Prepare the projection ref (eventually convert the EPSG code into full WKT)
//
// Note that we do that at the GenericRSTransform level and not in the member
// class for several reasons:
// - at the GenericMapProjection and MapProjectionAdapter the method are
// called SetWkt and thus should not take a SRID.
// - we do not want to mix the GeoInformationConversion (which uses gdal) in
// the MapProjectionAdapter to keep ossim and gdal dependencies as separated
// as possible.
m_InputProjectionRef = GeoInformationConversion::ToWKT(m_InputProjectionRef);
m_OutputProjectionRef = GeoInformationConversion::ToWKT(m_OutputProjectionRef);
//*****************************
//Set the input transformation
//*****************************
......
......@@ -21,7 +21,6 @@
#include "otbImageFileReader.h"
#include "otbGCPsToRPCSensorModelImageFilter.h"
#include "otbGenericRSTransform.h"
#include "otbGeoInformationConversion.h"
#include "otbGeographicalDistance.h"
int otbGCPsToRPCSensorModelImageFilterCheckRpcModel(int argc, char* argv[])
......@@ -113,7 +112,7 @@ int otbGCPsToRPCSensorModelImageFilterCheckRpcModel(int argc, char* argv[])
GenericRSTransformType::Pointer grsTrasnform = GenericRSTransformType::New();
grsTrasnform->SetInputKeywordList(rpcEstimator->GetKeywordlist());
grsTrasnform->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(4326));
grsTrasnform->SetOutputProjectionRef("4326");
// Set the DEM Directory if any
if(parseResult->IsOptionPresent("--DEMDirectory"))
......
......@@ -21,7 +21,6 @@
#include <iostream>
#include "otbGenericRSTransform.h"
#include "otbGeoInformationConversion.h"
#include <ogr_spatialref.h>
/**
......@@ -65,15 +64,15 @@ int otbGenericRSTransformWithSRID(int argc, char* argv[])
oSRS.exportToWkt(&tmtRef);
TransformType::Pointer wgs2utm = TransformType::New();
wgs2utm->SetInputProjectionRef(otb::GeoInformationConversion::ToWKT(4326)); // WGS 84
wgs2utm->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(32631)); // UTM 31 N
wgs2utm->SetInputProjectionRef("4326"); // WGS 84
wgs2utm->SetOutputProjectionRef("32631"); // UTM 31 N
wgs2utm->InstanciateTransform();
TransformType::Pointer utm2wgs = TransformType::New();
wgs2utm->GetInverse(utm2wgs);
TransformType::Pointer wgs2lambert = TransformType::New();
wgs2lambert->SetInputProjectionRef(otb::GeoInformationConversion::ToWKT(4326)); // WGS 84
wgs2lambert->SetInputProjectionRef("4326"); // WGS 84
wgs2lambert->SetOutputProjectionRef(lambertRef);
wgs2lambert->InstanciateTransform();
......@@ -82,7 +81,7 @@ int otbGenericRSTransformWithSRID(int argc, char* argv[])
wgs2lambert->GetInverse(lambert2wgs);
TransformType::Pointer wgs2tmt = TransformType::New();
wgs2tmt->SetInputProjectionRef(otb::GeoInformationConversion::ToWKT(4326)); // WGS 84
wgs2tmt->SetInputProjectionRef("4326"); // WGS 84
wgs2tmt->SetOutputProjectionRef(tmtRef);
wgs2tmt->InstanciateTransform();
......@@ -91,13 +90,13 @@ int otbGenericRSTransformWithSRID(int argc, char* argv[])
wgs2tmt->GetInverse(tmt2wgs);
TransformType::Pointer wgs2wgs = TransformType::New();
wgs2wgs->SetInputProjectionRef(otb::GeoInformationConversion::ToWKT(4326)); // WGS 84
wgs2wgs->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(4326)); // WGS 84
wgs2wgs->SetInputProjectionRef("4326"); // WGS 84
wgs2wgs->SetOutputProjectionRef("4326"); // WGS 84
wgs2wgs->InstanciateTransform();
TransformType::Pointer utm2utm = TransformType::New();
utm2utm->SetInputProjectionRef(otb::GeoInformationConversion::ToWKT(32631)); // UTM 31 N
utm2utm->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(32631)); // UTM 31 N
utm2utm->SetInputProjectionRef("32631"); // UTM 31 N
utm2utm->SetOutputProjectionRef("32631"); // UTM 31 N
utm2utm->InstanciateTransform();
TransformType::Pointer lambert2lambert = TransformType::New();
......@@ -112,7 +111,7 @@ int otbGenericRSTransformWithSRID(int argc, char* argv[])
tmt2tmt->InstanciateTransform();
TransformType::Pointer utm2lambert = TransformType::New();
utm2lambert->SetInputProjectionRef(otb::GeoInformationConversion::ToWKT(32631)); // UTM
utm2lambert->SetInputProjectionRef("32631"); // UTM
utm2lambert->SetOutputProjectionRef(lambertRef);
utm2lambert->InstanciateTransform();
......@@ -121,7 +120,7 @@ int otbGenericRSTransformWithSRID(int argc, char* argv[])
utm2lambert->GetInverse(lambert2utm);
TransformType::Pointer utm2tmt = TransformType::New();
utm2tmt->SetInputProjectionRef(otb::GeoInformationConversion::ToWKT(32631));
utm2tmt->SetInputProjectionRef("32631");
utm2tmt->SetOutputProjectionRef(tmtRef);
utm2tmt->InstanciateTransform();
......
......@@ -20,7 +20,6 @@
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbGeoInformationConversion.h"
#include "otbMapProjections.h"
#include <iostream>
......@@ -62,7 +61,7 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[])
// Filter : Target SRS : WGS84
FilterType::Pointer filter = FilterType::New();
filter->SetInput(reader->GetOutput());
filter->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(4326)); //WGS84
filter->SetOutputProjectionRef("4326"); //WGS84
filter->Compute();
// Output file
......@@ -75,7 +74,7 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[])
outfile<< std::endl;
// Target SRS : 32631 UTM 31 N
filter->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(32631)); //WGS84
filter->SetOutputProjectionRef("32631"); // UTM 31 N
filter->Compute();
outfile<<"Output Parameters for SRID : 32631 (UTM 31 N)"<<std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment