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
Container Registry
Model registry
Operate
Environments
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
Antoine Belvire
otb
Commits
4ed16a66
Commit
4ed16a66
authored
18 years ago
by
Jordi Inglada
Browse files
Options
Downloads
Patches
Plain Diff
Exemple Metadata
parent
5564df8f
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
Examples/IO/CMakeLists.txt
+4
-0
4 additions, 0 deletions
Examples/IO/CMakeLists.txt
Examples/IO/MetadataExample.cxx
+213
-0
213 additions, 0 deletions
Examples/IO/MetadataExample.cxx
with
217 additions
and
0 deletions
Examples/IO/CMakeLists.txt
+
4
−
0
View file @
4ed16a66
...
...
@@ -40,6 +40,10 @@ TARGET_LINK_LIBRARIES(MultibandImageReadWrite OTBCommon OTBIO ITKCommon ITKIO)
ADD_EXECUTABLE
(
ExtractROI ExtractROI.cxx
)
TARGET_LINK_LIBRARIES
(
ExtractROI OTBCommon OTBIO ITKCommon ITKIO
)
ADD_EXECUTABLE
(
MetadataExample MetadataExample.cxx
)
TARGET_LINK_LIBRARIES
(
MetadataExample OTBCommon OTBIO ITKCommon ITKIO
)
#ADD_EXECUTABLE(ImageReadExportVTK ImageReadExportVTK.cxx )
#TARGET_LINK_LIBRARIES(ImageReadExportVTK ITKCommon ITKIO)
...
...
This diff is collapsed.
Click to expand it.
Examples/IO/MetadataExample.cxx
0 → 100755
+
213
−
0
View file @
4ed16a66
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// SoftwareGuide: BeginLatex
//
// This example illustrates the access to metadata image information
// with OTB. By metadata, we mean data which is typically stored with
// remote sensing images, like geographical coordinates of pixels,
// pixel spacing or resolution, etc. Of course, the availability of
// these data depends on the image format used and on the fact that
// the image producer must fill the available metadata fields. The
// image formats which typically support metadata are for example
// CEOS and GeoTiff.
//
// The metadata support is embedded in OTB's IO functionnalities and
// is accessible through the \doxygen{otb::Image} and
// \doxygen{otb::VectorImage} classes. You should avoid using the
// \doxygen{itk::Image} class if you want to have metadata support.
//
// SoftwareGuide: EndLatex
#include
"itkExceptionObject.h"
#include
<iostream>
#include
<fstream>
#include
<string>
#include
"otbImage.h"
#include
"otbImageFileReader.h"
int
main
(
int
argc
,
char
*
argv
[])
{
// Verify the number of parameters in the command line
const
char
*
inputFilename
=
argv
[
1
];
const
char
*
outputAsciiFilename
=
argv
[
2
];
// SoftwareGuide: BeginLatex
//
// This simple example will consist on reading an image from a file
// and writing the metadata to an output ASCII file. As usual we
// start by defining the types needed for the image to be read.
//
// SoftwareGuide: EndLatex
// SoftwareGuide: BeginCodeSnippet
typedef
unsigned
char
InputPixelType
;
const
unsigned
int
Dimension
=
2
;
typedef
otb
::
Image
<
InputPixelType
,
Dimension
>
InputImageType
;
typedef
otb
::
ImageFileReader
<
InputImageType
>
ReaderType
;
// SoftwareGuide: EndCodeSnippet
// SoftwareGuide: BeginLatex
//
// We can now instantiate the reader and get a pointer to the input image.
//
// SoftwareGuide: EndLatex
// SoftwareGuide: BeginCodeSnippet
ReaderType
::
Pointer
reader
=
ReaderType
::
New
();
InputImageType
::
Pointer
image
=
InputImageType
::
New
();
reader
->
SetFileName
(
inputFilename
);
reader
->
Update
();
image
=
reader
->
GetOutput
();
// SoftwareGuide: EndCodeSnippet
// SoftwareGuide: BeginLatex
//
// Once the image has been read, we can access the metadata
// information. We will copy this information to an ASCII file, so we
// create an output file stream for this purpose.
//
// SoftwareGuide: EndLatex
// SoftwareGuide: BeginCodeSnippet
std
::
ofstream
file
;
file
.
open
(
outputAsciiFilename
);
// SoftwareGuide: EndCodeSnippet
// SoftwareGuide: BeginLatex
//
// We can now call the different available methods for accessing the
// metadata. Useful methods are :
// \begin{itemize}
// \item \code{GetSpacing}: the sampling step;
// \item \code{GetOrigin}: the coordinates of the origin of the image;
// \item \code{GetProjectionRef}: the image projection reference;
// \item \code{GetGCPProjection}: the projection for the eventual
// ground control points;
// \item \code{GetGCPCount}: the number of GCPs available;
// \end{itemize}
//
// SoftwareGuide: EndLatex
// SoftwareGuide: BeginCodeSnippet
file
<<
"Spacing "
<<
image
->
GetSpacing
()
<<
std
::
endl
;
file
<<
"Origin "
<<
image
->
GetOrigin
()
<<
std
::
endl
;
file
<<
"Projection REF "
<<
image
->
GetProjectionRef
()
<<
std
::
endl
;
file
<<
"GCP Projection "
<<
image
->
GetGCPProjection
()
<<
std
::
endl
;
unsigned
int
GCPCount
=
image
->
GetGCPCount
();
file
<<
"GCP Count "
<<
image
->
GetGCPCount
()
<<
std
::
endl
;
// SoftwareGuide: EndCodeSnippet
// SoftwareGuide: BeginLatex
//
// One can also get the GCPs by number, as well as their coordinates
// in image and geographical space.
//
// SoftwareGuide: EndLatex
// SoftwareGuide: BeginCodeSnippet
for
(
unsigned
int
GCPnum
=
0
;
GCPnum
<
GCPCount
;
GCPnum
++
)
{
file
<<
"GCP["
<<
GCPnum
<<
"] Id "
<<
image
->
GetGCPId
(
GCPnum
)
<<
std
::
endl
;
file
<<
"GCP["
<<
GCPnum
<<
"] Info "
<<
image
->
GetGCPInfo
(
GCPnum
)
<<
std
::
endl
;
file
<<
"GCP["
<<
GCPnum
<<
"] Row "
<<
image
->
GetGCPRow
(
GCPnum
)
<<
std
::
endl
;
file
<<
"GCP["
<<
GCPnum
<<
"] Col "
<<
image
->
GetGCPCol
(
GCPnum
)
<<
std
::
endl
;
file
<<
"GCP["
<<
GCPnum
<<
"] X "
<<
image
->
GetGCPX
(
GCPnum
)
<<
std
::
endl
;
file
<<
"GCP["
<<
GCPnum
<<
"] Y "
<<
image
->
GetGCPY
(
GCPnum
)
<<
std
::
endl
;
file
<<
"GCP["
<<
GCPnum
<<
"] Z "
<<
image
->
GetGCPZ
(
GCPnum
)
<<
std
::
endl
;
file
<<
"----------------"
<<
std
::
endl
;
}
// SoftwareGuide: EndCodeSnippet
// SoftwareGuide: BeginLatex
//
// If a geographical transformation is available, it can be recovered
// as follows.
//
// SoftwareGuide: EndLatex
// SoftwareGuide: BeginCodeSnippet
InputImageType
::
VectorType
tab
=
image
->
GetGeoTransform
();
file
<<
"Geo Transform "
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tab
.
size
()
;
i
++
)
{
file
<<
" "
<<
i
<<
" -> "
<<
tab
[
i
]
<<
std
::
endl
;
}
tab
.
clear
();
tab
=
image
->
GetUpperLeftCorner
();
file
<<
"Corners "
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
tab
.
size
()
;
i
++
)
{
file
<<
" UL["
<<
i
<<
"] -> "
<<
tab
[
i
]
<<
std
::
endl
;
}
tab
.
clear
();
tab
=
image
->
GetUpperRightCorner
();
for
(
int
i
=
0
;
i
<
tab
.
size
()
;
i
++
)
{
file
<<
" UR["
<<
i
<<
"] -> "
<<
tab
[
i
]
<<
std
::
endl
;
}
tab
.
clear
();
tab
=
image
->
GetLowerLeftCorner
();
for
(
int
i
=
0
;
i
<
tab
.
size
()
;
i
++
)
{
file
<<
" LL["
<<
i
<<
"] -> "
<<
tab
[
i
]
<<
std
::
endl
;
}
tab
.
clear
();
tab
=
image
->
GetLowerRightCorner
();
for
(
int
i
=
0
;
i
<
tab
.
size
()
;
i
++
)
{
file
<<
" LR["
<<
i
<<
"] -> "
<<
tab
[
i
]
<<
std
::
endl
;
}
tab
.
clear
();
file
.
close
();
// SoftwareGuide: EndCodeSnippet
return
EXIT_SUCCESS
;
}
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