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
David Youssefi
otb
Commits
cb9ceff9
Commit
cb9ceff9
authored
13 years ago
by
Guillaume Pasero
Browse files
Options
Downloads
Patches
Plain Diff
ENH: updated VectorDataSetField to new framework
parent
6b4c00c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Applications/Util/CMakeLists.txt
+3
-0
3 additions, 0 deletions
Applications/Util/CMakeLists.txt
Applications/Util/otbVectorDataSetField.cxx
+79
-50
79 additions, 50 deletions
Applications/Util/otbVectorDataSetField.cxx
with
82 additions
and
50 deletions
Applications/Util/CMakeLists.txt
+
3
−
0
View file @
cb9ceff9
...
...
@@ -51,3 +51,6 @@ OTB_CREATE_APPLICATION(NAME CompareImages
SOURCES otbCompareImages.cxx
LINK_LIBRARIES OTBIO
)
OTB_CREATE_APPLICATION
(
NAME VectorDataSetField
SOURCES otbVectorDataSetField.cxx
LINK_LIBRARIES OTBBasicFilters
)
This diff is collapsed.
Click to expand it.
Applications/Util/otbVectorDataSetField.cxx
+
79
−
50
View file @
cb9ceff9
...
...
@@ -16,71 +16,100 @@
=========================================================================*/
#include
"otbVectorDataSetField.h"
#include
"otbWrapperApplication.h"
#include
"otbWrapperApplicationFactory.h"
#include
<iostream>
//
#include <iostream>
#include
"otbVectorData.h"
#include
"otbVectorDataFileWriter.h"
#include
"otbVectorDataFileReader.h"
//
#include "otbVectorDataFileWriter.h"
//
#include "otbVectorDataFileReader.h"
namespace
otb
{
int
VectorDataSetField
::
Describe
(
ApplicationDescriptor
*
descriptor
)
namespace
Wrapper
{
descriptor
->
SetName
(
"VectorDataSetField"
);
descriptor
->
SetDescription
(
"Set a specified field to a specified value on all features of a vector data"
);
descriptor
->
AddOption
(
"Input"
,
"Input vector data"
,
"in"
,
1
,
true
,
ApplicationDescriptor
::
FileName
);
descriptor
->
AddOption
(
"Output"
,
"Output vector data"
,
"out"
,
1
,
true
,
ApplicationDescriptor
::
FileName
);
descriptor
->
AddOption
(
"Field"
,
"Field name"
,
"fn"
,
1
,
true
,
ApplicationDescriptor
::
String
);
descriptor
->
AddOption
(
"Value"
,
"Field value"
,
"fv"
,
1
,
true
,
ApplicationDescriptor
::
String
);
return
EXIT_SUCCESS
;
}
int
VectorDataSetField
::
Execute
(
otb
::
ApplicationOptionsResult
*
parseResult
)
class
VectorDataSetField
:
public
Application
{
try
{
typedef
otb
::
VectorData
<>
VectorDataType
;
typedef
otb
::
VectorDataFileReader
<
VectorDataType
>
ReaderVectorType
;
ReaderVectorType
::
Pointer
reader
=
ReaderVectorType
::
New
();
reader
->
SetFileName
(
parseResult
->
GetParameterString
(
"Input"
));
reader
->
Update
();
public:
/** Standard class typedefs. */
typedef
VectorDataSetField
Self
;
typedef
Application
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
/** Standard macro */
itkNewMacro
(
Self
);
itkTypeMacro
(
VectorDataSetField
,
otb
::
Application
);
/** Filters typedef */
//typedef otb::MultiChannelExtractROI<FloatVectorImageType::InternalPixelType,
// FloatVectorImageType::InternalPixelType> ExtractROIFilterType;
private:
VectorDataSetField
()
{
SetName
(
"VectorDataSetField"
);
SetDescription
(
"Set a field in vector data."
);
// Documentation
SetDocName
(
"Vector data set field Application"
);
SetDocLongDescription
(
"Set a specified field to a specified value on all features of a vector data (Note: doesn't work with KML files yet)"
);
SetDocLimitations
(
"None"
);
SetDocAuthors
(
"OTB-Team"
);
SetDocSeeAlso
(
" "
);
SetDocCLExample
(
"otbApplicationLauncherCommandLine VectorDataSetField ${OTB-BIN}/bin "
"--in ${OTB-DATA}/Input/ToulousePoints-examples.shp --out dataOut.shp --fn MyField --fv MyValue"
);
AddDocTag
(
"VectorData Manipulation"
);
}
virtual
~
VectorDataSetField
()
{
}
void
DoCreateParameters
()
{
AddParameter
(
ParameterType_InputVectorData
,
"in"
,
"Input"
);
SetParameterDescription
(
"in"
,
"Input Vector Data"
);
AddParameter
(
ParameterType_OutputVectorData
,
"out"
,
"Output"
);
SetParameterDescription
(
"out"
,
"Output Vector Data"
);
AddParameter
(
ParameterType_String
,
"fn"
,
"Field"
);
SetParameterDescription
(
"fn"
,
"Field name"
);
AddParameter
(
ParameterType_String
,
"fv"
,
"Value"
);
SetParameterDescription
(
"fv"
,
"Field value"
);
}
void
DoUpdateParameters
()
{
// Nothing to do (for now)
}
void
DoExecute
()
{
m_InputData
=
GetParameterVectorData
(
"in"
);
typedef
VectorDataType
::
DataTreeType
DataTreeType
;
typedef
itk
::
PreOrderTreeIterator
<
DataTreeType
>
TreeIteratorType
;
TreeIteratorType
it
(
reader
->
GetOutput
()
->
GetDataTree
());
TreeIteratorType
it
(
m_InputData
->
GetDataTree
());
for
(
it
.
GoToBegin
();
!
it
.
IsAtEnd
();
++
it
)
{
it
.
Get
()
->
SetFieldAsString
(
parseResult
->
GetParameterString
(
"Field"
),
parseResult
->
GetParameterString
(
"Value"
));
}
typedef
otb
::
VectorDataFileWriter
<
VectorDataType
>
WriterVectorType
;
WriterVectorType
::
Pointer
writerVector
=
WriterVectorType
::
New
();
writerVector
->
SetFileName
(
parseResult
->
GetParameterString
(
"Output"
));
writerVector
->
SetInput
(
reader
->
GetOutput
());
writerVector
->
Update
();
}
catch
(
itk
::
ExceptionObject
&
err
)
{
std
::
cout
<<
"Following otbException caught :"
<<
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 found !"
<<
std
::
endl
;
return
EXIT_FAILURE
;
it
.
Get
()
->
SetFieldAsString
(
GetParameterAsString
(
"fn"
),
GetParameterAsString
(
"fv"
));
}
return
EXIT_SUCCESS
;
SetParameterOutputVectorData
(
"out"
,
m_InputData
);
}
VectorDataType
::
Pointer
m_InputData
;
};
}
}
OTB_APPLICATION_EXPORT
(
otb
::
Wrapper
::
VectorDataSetField
)
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