Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Lozac'h Loic
AgriSoilMoisture
Commits
54016089
Commit
54016089
authored
Jan 24, 2020
by
Lozac'h Loic
Browse files
ApplyCsvLabelsFile
parent
b1da2f9d
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/CMakeLists.txt
View file @
54016089
...
...
@@ -3,7 +3,10 @@ OTB_CREATE_APPLICATION(NAME InvertSARModel
LINK_LIBRARIES
${${
otb-module
}
_LIBRARIES
}
)
OTB_CREATE_APPLICATION
(
NAME ApplyCsvLabelsFile
SOURCES otbApplyCsvLabelsFile.cxx
LINK_LIBRARIES
${${
otb-module
}
_LIBRARIES
}
)
OTB_CREATE_APPLICATION
(
NAME SoilMoistureLULCMask
SOURCES otbSoilMoistureLULCMask.cxx
LINK_LIBRARIES
${${
otb-module
}
_LIBRARIES
}
...
...
app/otbApplyCsvLabelsFile.cxx
0 → 100644
View file @
54016089
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "itkFixedArray.h"
#include "itkObjectFactory.h"
// Mapper
#include "otbHumidityFunctors.h"
#include "itkUnaryFunctorImageFilter.h"
// Export csv
#include <boost/algorithm/string.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <iterator>
#include <string>
#include <algorithm>
#include <math.h>
namespace
otb
{
namespace
Wrapper
{
class
ApplyCsvLabelsFile
:
public
Application
{
public:
typedef
ApplyCsvLabelsFile
Self
;
typedef
Application
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
itkNewMacro
(
Self
);
itkTypeMacro
(
ApplyCsvLabelsFile
,
Application
);
typedef
std
::
map
<
UInt32ImageType
::
PixelType
,
FloatImageType
::
PixelType
>
OutputMapType
;
/** Soil moisture mapping */
typedef
otb
::
Functor
::
MapperFunctor
<
UInt32ImageType
::
PixelType
,
FloatImageType
::
PixelType
,
OutputMapType
>
MapperFunctorType
;
typedef
itk
::
UnaryFunctorImageFilter
<
UInt32ImageType
,
FloatImageType
,
MapperFunctorType
>
MoistMapFilterType
;
private:
void
DoInit
()
{
SetName
(
"ApplyCsvLabelsFile"
);
SetDescription
(
"Apply csv results from otbInvertSARModel on Labels image"
);
// Documentation
SetDocLimitations
(
"None"
);
SetDocAuthors
(
"Loic Lozach"
);
SetDocSeeAlso
(
" "
);
// Input images
AddParameter
(
ParameterType_InputFilename
,
"incsv"
,
"Input CSV File"
);
AddParameter
(
ParameterType_InputImage
,
"inlabels"
,
"Input labels image"
);
// Output image
AddParameter
(
ParameterType_OutputImage
,
"out"
,
"Output image"
);
SetParameterDescription
(
"out"
,
"The output image is the estimated soil moisture"
);
}
void
DoUpdateParameters
()
{
}
/*
* Do the work
*/
void
DoExecute
()
{
std
::
ifstream
file
(
this
->
GetParameterString
(
"incsv"
));
OutputMapType
dataList
;
UInt32ImageType
::
PixelType
label
;
FloatImageType
::
PixelType
moist
;
std
::
string
line
=
""
;
// Iterate through each line and split the content using delimeter, pass header
int
i
=
0
;
while
(
getline
(
file
,
line
))
{
i
+=
1
;
if
(
i
==
1
)
continue
;
std
::
vector
<
std
::
string
>
vec
;
boost
::
algorithm
::
split
(
vec
,
line
,
boost
::
is_any_of
(
";"
));
label
=
(
uint32
)
vec
[
0
];
moist
=
(
float
)
vec
[
5
];
dataList
.
insert
({
label
,
moist
});
}
// Close the File
file
.
close
();
otbAppLogINFO
(
"Exporting to raster file"
);
// Produce the map
//moistMap[0] = 0 ;
m_MapFilter
=
MoistMapFilterType
::
New
();
m_MapFilter
->
SetInput
(
GetParameterUInt32Image
(
"inlabels"
));
m_MapFilter
->
GetFunctor
().
SetMap
(
dataList
);
SetParameterOutputImage
(
"out"
,
m_MapFilter
->
GetOutput
());
}
// Create a nice map
MoistMapFilterType
::
Pointer
m_MapFilter
;
};
}
}
OTB_APPLICATION_EXPORT
(
otb
::
Wrapper
::
ApplyCsvLabelsFile
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment