Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Cabieces
otb
Commits
ab1c6867
Commit
ab1c6867
authored
13 years ago
by
Otmane Lahlou
Browse files
Options
Downloads
Patches
Plain Diff
ENH: port ConvertSensorToGeoPoint to new framework api
parent
c4940382
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Applications/Projections/otbConvertSensorToGeoPoint.cxx
+95
-132
95 additions, 132 deletions
Applications/Projections/otbConvertSensorToGeoPoint.cxx
with
95 additions
and
132 deletions
Applications/Projections/otbConvertSensorToGeoPoint.cxx
+
95
−
132
View file @
ab1c6867
...
@@ -15,158 +15,121 @@
...
@@ -15,158 +15,121 @@
PURPOSE. See the above copyright notices for more information.
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
=========================================================================*/
#include
"otbWrapperApplication.h"
#include
"otbWrapperApplicationFactory.h"
#include
<iostream>
#include
<iomanip>
#include
"otbCommandLineArgumentParser.h"
#include
"otbVectorImage.h"
#include
"otbImageFileReader.h"
#include
"otbForwardSensorModel.h"
#include
"otbForwardSensorModel.h"
#include
"otbCoordinateToName.h"
#include
"otbMacro.h"
#include
"otbMacro.h"
#include
"itkExceptionObject.h"
namespace
otb
{
namespace
Wrapper
{
int
main
(
int
argc
,
char
*
argv
[])
class
ConvertSensorToGeoPoint
:
public
Application
{
{
try
public:
{
/** Standard class typedefs. */
// Parse command line parameters
typedef
ConvertSensorToGeoPoint
Self
;
typedef
otb
::
CommandLineArgumentParser
ParserType
;
typedef
Application
Superclass
;
ParserType
::
Pointer
parser
=
ParserType
::
New
();
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
parser
->
SetProgramDescription
(
"Sensor to geographic coordinates conversion. "
"If x, y are not provided, convert the four corners"
);
parser
->
AddOption
(
"--data"
,
"sensor image"
,
"-in"
);
parser
->
AddOption
(
"--sample"
,
"X value of desired point"
,
"-x"
,
1
,
false
);
parser
->
AddOption
(
"--line"
,
"Y value of desired point"
,
"-y"
,
1
,
false
);
typedef
otb
::
CommandLineArgumentParseResult
ParserResultType
;
ParserResultType
::
Pointer
parseResult
=
ParserResultType
::
New
();
try
{
parser
->
ParseCommandLine
(
argc
,
argv
,
parseResult
);
}
catch
(
itk
::
ExceptionObject
&
err
)
{
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
;
}
// Code
/** Standard macro */
itkNewMacro
(
Self
);
std
::
string
filename
=
parseResult
->
GetParameterString
(
"--data"
);
itkTypeMacro
(
ConvertSensorToGeoPoint
,
otb
::
Application
);
typedef
otb
::
VectorImage
<
double
,
2
>
ImageType
;
/** Filters typedef */
typedef
otb
::
ImageFileReader
<
ImageType
>
ReaderType
;
typedef
otb
::
ForwardSensorModel
<
double
>
ModelType
;
ReaderType
::
Pointer
reader
=
ReaderType
::
New
();
typedef
itk
::
Point
<
double
,
2
>
PointType
;
reader
->
SetFileName
(
filename
);
reader
->
GenerateOutputInformation
();
typedef
otb
::
ForwardSensorModel
<
double
>
ModelType
;
private:
ModelType
::
Pointer
model
=
ModelType
::
New
();
ConvertSensorToGeoPoint
()
model
->
SetImageGeometry
(
reader
->
GetOutput
()
->
GetImageKeywordlist
());
{
if
(
model
->
IsValidSensorModel
()
==
false
)
SetName
(
"ConvertSensorToGeoPoint"
);
{
SetDescription
(
"Convert Sensor Point To Geographic Point using a Forward Sensor Model"
);
std
::
cerr
<<
"Unable to create a model"
<<
std
::
endl
;
return
1
;
// Documentation
}
SetDocName
(
"Convert Sensor Point To Geographic Point"
);
SetDocLongDescription
(
"Sensor to geographic coordinates conversion"
);
ImageType
::
Pointer
inputImage
=
reader
->
GetOutput
();
SetDocLimitations
(
"None"
);
SetDocAuthors
(
"OTB-Team"
);
typedef
itk
::
Point
<
double
,
2
>
PointType
;
SetDocSeeAlso
(
"ConvertCartoToGeoPoint application, otbObtainUTMZoneFromGeoPoint application"
);
std
::
vector
<
PointType
>
points
;
if
(
parseResult
->
IsOptionPresent
(
"--sample"
)
&&
parseResult
->
IsOptionPresent
(
"--line"
))
AddDocTag
(
"Projections"
);
{
}
PointType
point
;
point
[
0
]
=
parseResult
->
GetParameterInt
(
"--sample"
);
point
[
1
]
=
parseResult
->
GetParameterInt
(
"--line"
);
points
.
push_back
(
point
);
}
else
{
// find the four corners
PointType
point
;
point
[
0
]
=
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetIndex
()[
0
];
point
[
1
]
=
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetIndex
()[
1
];
points
.
push_back
(
point
);
point
[
0
]
=
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetIndex
()[
0
]
+
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetSize
()[
0
]
-
1
;
point
[
1
]
=
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetIndex
()[
1
];
points
.
push_back
(
point
);
point
[
0
]
=
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetIndex
()[
0
];
point
[
1
]
=
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetIndex
()[
1
]
+
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetSize
()[
1
]
-
1
;
points
.
push_back
(
point
);
point
[
0
]
=
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetIndex
()[
0
]
+
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetSize
()[
0
]
-
1
;
point
[
1
]
=
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetIndex
()[
1
]
+
reader
->
GetOutput
()
->
GetLargestPossibleRegion
().
GetSize
()[
1
]
-
1
;
points
.
push_back
(
point
);
}
virtual
~
ConvertSensorToGeoPoint
()
{
}
for
(
unsigned
int
i
=
0
;
i
<
points
.
size
();
++
i
)
void
DoCreateParameters
()
{
{
AddParameter
(
ParameterType_InputImage
,
"in"
,
"Sensor image"
);
AddParameter
(
ParameterType_Group
,
"input"
,
"Point Coordinates"
);
AddParameter
(
ParameterType_Float
,
"input.idx"
,
"X value of desired point"
);
AddParameter
(
ParameterType_Float
,
"input.idy"
,
"Y value of desired point"
);
// Output with Output Role
AddParameter
(
ParameterType_Group
,
"output"
,
"Geographic Coordinates"
);
AddParameter
(
ParameterType_Float
,
"output.idx"
,
"Output Point Longitude"
);
AddParameter
(
ParameterType_Float
,
"output.idy"
,
"Output Point Latitude"
);
AddParameter
(
ParameterType_String
,
"output.town"
,
"Main town near the coordinates computed"
);
AddParameter
(
ParameterType_String
,
"output.country"
,
"Country of the image"
);
// Set the parameter role for the output parameters
SetParameterRole
(
"output.idx"
,
Role_Output
);
SetParameterRole
(
"output.idy"
,
Role_Output
);
SetParameterRole
(
"output.town"
,
Role_Output
);
SetParameterRole
(
"output.country"
,
Role_Output
);
}
void
DoUpdateParameters
()
{
}
ModelType
::
OutputPointType
outputPoint
;
void
DoExecute
()
{
// Get input Image
FloatVectorImageType
::
Pointer
inImage
=
GetParameterImage
(
"in"
);
// Instanciate a ForwardSensor Model
ModelType
::
Pointer
model
=
ModelType
::
New
();
model
->
SetImageGeometry
(
inImage
->
GetImageKeywordlist
());
if
(
model
->
IsValidSensorModel
()
==
false
)
{
std
::
cerr
<<
"Unable to create a model"
<<
std
::
endl
;
}
outputPoint
=
model
->
TransformPoint
(
points
[
i
]);
// Convert the desired point
PointType
point
;
point
[
0
]
=
GetParameterFloat
(
"input.idx"
);
point
[
1
]
=
GetParameterFloat
(
"input.idy"
);
if
(
!
parseResult
->
IsOptionPresent
(
"--OTBTesting"
))
ModelType
::
OutputPointType
outputPoint
;
{
outputPoint
=
model
->
TransformPoint
(
point
);
std
::
cout
<<
std
::
setprecision
(
10
)
<<
"Sensor Point (x , y) : ("
<<
points
[
i
][
0
]
<<
", "
<<
points
[
i
][
1
]
<<
")
\n
"
;
std
::
cout
<<
std
::
setprecision
(
10
)
<<
"Geographic Point (Lat, Lon) : ("
<<
outputPoint
[
1
]
<<
", "
<<
outputPoint
[
0
]
<<
")
\n\n
"
;
}
else
{
std
::
string
outputTestFileName
=
parseResult
->
GetParameterString
(
"--OTBTesting"
,
0
);
std
::
ofstream
outputTestFile
;
// Set the value computed
outputTestFile
.
open
(
outputTestFileName
.
c_str
());
SetParameterFloat
(
"output.idx"
,
outputPoint
[
0
]);
SetParameterFloat
(
"output.idy"
,
outputPoint
[
1
]);
outputTestFile
<<
std
::
setprecision
(
10
)
<<
"Sensor Point (x , y) : ("
<<
points
[
i
][
0
]
<<
", "
// Set the town and the neaerest city
<<
points
[
i
][
1
]
<<
")
\n
"
;
CoordinateToName
::
Pointer
coord2name
=
CoordinateToName
::
New
();
outputTestFile
<<
std
::
setprecision
(
10
)
<<
"Geographic Point (Lat, Lon) : ("
<<
outputPoint
[
1
]
<<
", "
coord2name
->
SetLon
(
outputPoint
[
0
]);
<<
outputPoint
[
0
]
<<
")
\n\n
"
;
coord2name
->
SetLat
(
outputPoint
[
1
]);
outputTestFile
.
close
();
coord2name
->
Evaluate
();
}
}
SetParameterString
(
"output.town"
,
coord2name
->
GetPlaceName
());
SetParameterString
(
"output.country"
,
coord2name
->
GetCountryName
());
}
}
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
::
ConvertSensorToGeoPoint
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment