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
fa215b38
Commit
fa215b38
authored
13 years ago
by
Guillaume Pasero
Browse files
Options
Downloads
Patches
Plain Diff
ENH: adapt Rasterization application to new framework
parent
38668122
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Applications/Rasterization/otbRasterization.cxx
+204
-201
204 additions, 201 deletions
Applications/Rasterization/otbRasterization.cxx
with
204 additions
and
201 deletions
Applications/Rasterization/otbRasterization.cxx
+
204
−
201
View file @
fa215b38
...
...
@@ -15,197 +15,208 @@
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include
"otbRasterization.h"
#include
"otbWrapperApplication.h"
#include
"otbWrapperApplicationFactory.h"
#include
<iostream>
#include
"otbCommandLineArgumentParser.h"
//Image
#include
"otbImage.h"
#include
"otbImageFileReader.h"
#include
"otbStreamingImageFileWriter.h"
#include
"itkRGBAPixel.h"
//VectorData
#include
"otbVectorData.h"
#include
"otbVectorDataExtractROI.h"
#include
"otbVectorDataProjectionFilter.h"
#include
"otbVectorDataFileReader.h"
#include
"otbVectorDataFileWriter.h"
#include
"otbVectorDataProperties.h"
//Rasterization
#include
"otbVectorDataToImageFilter.h"
#include
"otbGeoInformationConversion.h"
//Misc
#include
"otbRemoteSensingRegion.h"
#include
"otbStandardWriterWatcher.h"
#include
"otbPipelineMemoryPrintCalculator.h"
namespace
otb
{
int
Rasterization
::
Describe
(
ApplicationDescriptor
*
descriptor
)
namespace
Wrapper
{
descriptor
->
SetName
(
"Rasterization"
);
descriptor
->
SetDescription
(
"Reproject and Rasterize a Vector Data."
);
descriptor
->
AddOption
(
"InputVData"
,
"The input vector data to be rasterized"
,
"in"
,
1
,
true
,
ApplicationDescriptor
::
FileName
);
descriptor
->
AddOption
(
"OutputImage"
,
"An output image containing the rasterized vector data"
,
"out"
,
1
,
true
,
ApplicationDescriptor
::
OutputImage
);
descriptor
->
AddOption
(
"InputImage"
,
"A reference image for extraction region and projection information (optional)"
,
"im"
,
1
,
false
,
ApplicationDescriptor
::
InputImage
);
descriptor
->
AddOption
(
"SizeX"
,
"OutputSize[0] (useless if support image is given)"
,
"szx"
,
1
,
false
,
ApplicationDescriptor
::
Real
);
descriptor
->
AddOption
(
"SizeY"
,
"OutputSize[1] (useless if support image is given)"
,
"szy"
,
1
,
false
,
ApplicationDescriptor
::
Real
);
descriptor
->
AddOption
(
"RSID"
,
"Projection System RSID number (RSID 4326 for WGS84 32631 for UTM31N) (useless if support image is given)"
,
"epsg"
,
1
,
false
,
ApplicationDescriptor
::
Integer
);
descriptor
->
AddOption
(
"OriginX"
,
"OutputOrigin[0] (optional if support image is given )"
,
"orx"
,
1
,
false
,
ApplicationDescriptor
::
Real
);
descriptor
->
AddOption
(
"OriginY"
,
"OutputOrigin[1] (optional, useless if support image is given)"
,
"ory"
,
1
,
false
,
ApplicationDescriptor
::
Real
);
descriptor
->
AddOption
(
"SpacingX"
,
"OutputSpacing[0] (optional, useless if support image is given )"
,
"spx"
,
1
,
false
,
ApplicationDescriptor
::
Real
);
descriptor
->
AddOption
(
"SpacingY"
,
"OutputSpacing[1] (optional, useless if support image is given)"
,
"spy"
,
1
,
false
,
ApplicationDescriptor
::
Real
);
descriptor
->
AddOption
(
"AvailableMemory"
,
"Set the maximum of available memory for the pipeline execution in mega bytes (optional, 256 by default)"
,
"ram"
,
1
,
false
,
otb
::
ApplicationDescriptor
::
Integer
);
return
EXIT_SUCCESS
;
}
int
Rasterization
::
Execute
(
otb
::
ApplicationOptionsResult
*
parseResult
)
class
Rasterization
:
public
Application
{
// Images
//typedef itk::RGBAPixel<unsigned char> PixelType;
typedef
unsigned
char
PixelType
;
typedef
otb
::
Image
<
PixelType
,
2
>
ImageType
;
typedef
ImageType
::
PointType
PointType
;
typedef
ImageType
::
SizeType
SizeType
;
typedef
ImageType
::
SpacingType
SpacingType
;
typedef
ImageType
::
IndexType
IndexType
;
typedef
otb
::
StreamingImageFileWriter
<
ImageType
>
WriterType
;
// VectorData
typedef
otb
::
VectorData
<>
VectorDataType
;
typedef
VectorDataType
::
DataNodeType
DataNodeType
;
typedef
VectorDataType
::
DataTreeType
DataTreeType
;
typedef
DataNodeType
::
PointType
PointType
;
typedef
otb
::
VectorDataFileReader
<
VectorDataType
>
VectorDataReaderType
;
typedef
otb
::
VectorDataFileWriter
<
VectorDataType
>
VectorDataWriterType
;
public:
/** Standard class typedefs. */
typedef
Rasterization
Self
;
typedef
Application
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
/** Standard macro */
itkNewMacro
(
Self
);
itkTypeMacro
(
Rasterization
,
otb
::
Application
);
/** Filters typedef */
// the application produces a binary mask : no need to use a FloatVectorImageType
typedef
UInt8ImageType
::
PointType
PointType
;
typedef
UInt8ImageType
::
SizeType
SizeType
;
typedef
UInt8ImageType
::
SpacingType
SpacingType
;
typedef
UInt8ImageType
::
IndexType
IndexType
;
typedef
VectorDataProjectionFilter
<
VectorDataType
,
VectorDataType
>
VectorDataProjectionFilterType
;
typedef
VectorDataExtractROI
<
VectorDataType
>
VectorDataExtractROIType
;
typedef
VectorDataProperties
<
VectorDataType
>
VectorDataPropertiesType
;
// Image
typedef
otb
::
ImageFileReader
<
ImageType
>
ImageReaderType
;
// Rasterization
typedef
otb
::
VectorDataToImageFilter
<
VectorDataType
,
ImageType
>
VectorDataToImageFilterType
;
typedef
otb
::
VectorDataToImageFilter
<
VectorDataType
,
UInt8
ImageType
>
VectorDataToImageFilterType
;
// Misc
typedef
otb
::
RemoteSensingRegion
<
double
>
RemoteSensingRegionType
;
typedef
RemoteSensingRegionType
::
SizeType
SizePhyType
;
typedef
otb
::
PipelineMemoryPrintCalculator
MemoryCalculatorType
;
ImageReaderType
::
Pointer
imReader
;
ImageType
::
Pointer
referenceImage
;
// Reading the VectorData
std
::
string
vdFilename
=
parseResult
->
GetParameterString
(
"InputVData"
);
std
::
cout
<<
"Processing vector data : "
<<
vdFilename
<<
std
::
endl
;
VectorDataReaderType
::
Pointer
vdReader
=
VectorDataReaderType
::
New
();
vdReader
->
SetFileName
(
vdFilename
);
vdReader
->
Update
();
private:
Rasterization
()
{
SetName
(
"Rasterization"
);
SetDescription
(
"Reproject and Rasterize a Vector Data."
);
SetDocName
(
"Rasterization Application"
);
SetDocLongDescription
(
"Reproject and Rasterize a Vector Data."
);
SetDocLimitations
(
"None"
);
SetDocAuthors
(
"OTB-Team"
);
SetDocSeeAlso
(
" "
);
AddDocTag
(
Tags
::
Vector
);
}
// region information
SizeType
size
;
PointType
origin
;
SpacingType
spacing
;
SizePhyType
sizePhy
;
virtual
~
Rasterization
()
{
}
// reading projection information
// two choice :
std
::
string
outputProjectionRef
;
// a reference image is given as input
if
(
parseResult
->
IsOptionPresent
(
"InputImage"
))
void
DoCreateParameters
()
{
AddParameter
(
ParameterType_InputVectorData
,
"in"
,
"InputVectorData"
);
SetParameterDescription
(
"in"
,
"The input vector data to be rasterized"
);
AddParameter
(
ParameterType_OutputImage
,
"out"
,
"OutputImage"
);
SetParameterDescription
(
"out"
,
"An output image containing the rasterized vector data"
);
AddParameter
(
ParameterType_InputImage
,
"im"
,
"InputImage"
);
SetParameterDescription
(
"im"
,
"A reference image for extraction region and projection information (optional)"
);
MandatoryOff
(
"im"
);
AddParameter
(
ParameterType_Float
,
"szx"
,
"SizeX"
);
SetParameterDescription
(
"szx"
,
"OutputSize[0] (useless if support image is given)"
);
MandatoryOff
(
"szx"
);
AddParameter
(
ParameterType_Float
,
"szy"
,
"SizeY"
);
SetParameterDescription
(
"szy"
,
"OutputSize[1] (useless if support image is given)"
);
MandatoryOff
(
"szy"
);
AddParameter
(
ParameterType_Int
,
"epsg"
,
"RSID"
);
SetParameterDescription
(
"epsg"
,
"Projection System RSID number (RSID 4326 for WGS84 32631 for UTM31N) (useless if support image is given)"
);
MandatoryOff
(
"epsg"
);
AddParameter
(
ParameterType_Float
,
"orx"
,
"OriginX"
);
SetParameterDescription
(
"orx"
,
"OutputOrigin[0] (useless if support image is given)"
);
MandatoryOff
(
"orx"
);
AddParameter
(
ParameterType_Float
,
"ory"
,
"OriginY"
);
SetParameterDescription
(
"ory"
,
"OutputOrigin[1] (useless if support image is given)"
);
MandatoryOff
(
"ory"
);
AddParameter
(
ParameterType_Float
,
"spx"
,
"SpacingX"
);
SetParameterDescription
(
"spx"
,
"OutputSpacing[0] (useless if support image is given)"
);
MandatoryOff
(
"spx"
);
AddParameter
(
ParameterType_Float
,
"spy"
,
"SpacingY"
);
SetParameterDescription
(
"spy"
,
"OutputSpacing[1] (useless if support image is given)"
);
MandatoryOff
(
"spy"
);
AddParameter
(
ParameterType_RAM
,
"ram"
,
"Available RAM"
);
SetDefaultParameterInt
(
"ram"
,
256
);
MandatoryOff
(
"ram"
);
SetDocExampleParameterValue
(
"in"
,
"Rasterization/polgons.shp"
);
SetDocExampleParameterValue
(
"out"
,
"rasterImage.tif"
);
SetDocExampleParameterValue
(
"szx"
,
"1100"
);
SetDocExampleParameterValue
(
"szy"
,
"1100"
);
}
void
DoUpdateParameters
()
{
if
(
parseResult
->
IsOptionPresent
(
"SizeX"
)
||
parseResult
->
IsOptionPresent
(
"SizeY"
)
||
parseResult
->
IsOptionPresent
(
"OriginX"
)
||
parseResult
->
IsOptionPresent
(
"OriginY"
)
||
parseResult
->
IsOptionPresent
(
"SpacingX"
)
||
parseResult
->
IsOptionPresent
(
"SpacingY"
)
||
parseResult
->
IsOptionPresent
(
"RSID"
))
// Nothing to do
}
void
DoExecute
()
{
VectorDataType
::
Pointer
inputVData
=
GetParameterVectorData
(
"in"
);
inputVData
->
Update
();
UInt8ImageType
::
Pointer
referenceImage
;
// region information
SizeType
size
;
PointType
origin
;
SpacingType
spacing
;
SizePhyType
sizePhy
;
// reading projection information
// two choice :
std
::
string
outputProjectionRef
;
// a reference image is given as input
if
(
HasValue
(
"im"
))
{
std
::
cerr
<<
"Input entry problem "
<<
std
::
endl
<<
" reference image can't be used with other projection parameters. "
<<
std
::
endl
;
return
EXIT_FAILURE
;
if
(
HasValue
(
"szx"
)
||
HasValue
(
"szy"
)
||
HasValue
(
"orx"
)
||
HasValue
(
"ory"
)
||
HasValue
(
"spx"
)
||
HasValue
(
"spy"
)
||
HasValue
(
"epsg"
))
{
otbAppLogWARNING
(
"A reference image has been given, other parameters "
"regarding the output image will be ignored"
);
}
referenceImage
=
GetParameterUInt8Image
(
"im"
);
outputProjectionRef
=
referenceImage
->
GetProjectionRef
();
size
[
0
]
=
referenceImage
->
GetLargestPossibleRegion
().
GetSize
(
0
);
size
[
1
]
=
referenceImage
->
GetLargestPossibleRegion
().
GetSize
(
1
);
origin
=
referenceImage
->
GetOrigin
();
spacing
=
referenceImage
->
GetSpacing
();
sizePhy
[
0
]
=
size
[
0
]
*
spacing
[
0
];
sizePhy
[
1
]
=
size
[
1
]
*
spacing
[
1
];
}
std
::
string
imFilename
=
parseResult
->
GetParameterString
(
"InputImage"
);
imReader
=
ImageReaderType
::
New
();
imReader
->
SetFileName
(
imFilename
);
imReader
->
Update
();
referenceImage
=
imReader
->
GetOutput
();
outputProjectionRef
=
referenceImage
->
GetProjectionRef
();
size
[
0
]
=
referenceImage
->
GetLargestPossibleRegion
().
GetSize
(
0
);
size
[
1
]
=
referenceImage
->
GetLargestPossibleRegion
().
GetSize
(
1
);
origin
=
referenceImage
->
GetOrigin
();
spacing
=
referenceImage
->
GetSpacing
();
sizePhy
[
0
]
=
size
[
0
]
*
spacing
[
0
];
sizePhy
[
1
]
=
size
[
1
]
*
spacing
[
1
];
}
else
if
(
parseResult
->
IsOptionPresent
(
"SizeX"
)
&&
parseResult
->
IsOptionPresent
(
"SizeY"
))
else
if
(
HasValue
(
"szx"
)
&&
HasValue
(
"szy"
))
{
if
(
parseResult
->
IsOptionPresent
(
"RSID"
))
if
(
HasValue
(
"epsg"
))
{
unsigned
int
RSID
=
parseResult
->
GetParameterInt
(
"
RSID
"
);
unsigned
int
RSID
=
GetParameterInt
(
"
epsg
"
);
outputProjectionRef
=
otb
::
GeoInformationConversion
::
ToWKT
(
RSID
);
}
else
{
outputProjectionRef
=
vdReader
->
GetOutput
()
->
GetProjectionRef
();
outputProjectionRef
=
inputVData
->
GetProjectionRef
();
}
VectorDataPropertiesType
::
Pointer
v
dProperties
=
VectorDataPropertiesType
::
New
();
v
dProperties
->
SetVectorDataObject
(
vdReader
->
GetOutput
()
);
v
dProperties
->
ComputeBoundingRegion
();
m_V
dProperties
=
VectorDataPropertiesType
::
New
();
m_V
dProperties
->
SetVectorDataObject
(
inputVData
);
m_V
dProperties
->
ComputeBoundingRegion
();
size
[
0
]
=
parseResult
->
GetParameterDouble
(
"SizeX
"
);
size
[
1
]
=
parseResult
->
GetParameterDouble
(
"SizeY
"
);
size
[
0
]
=
GetParameterFloat
(
"szx
"
);
size
[
1
]
=
GetParameterFloat
(
"szy
"
);
if
(
parseResult
->
IsOptionPresent
(
"OriginX"
)
&&
parseResult
->
IsOptionPresent
(
"OriginY
"
))
if
(
HasValue
(
"orx"
)
&&
HasValue
(
"ory
"
))
{
origin
[
0
]
=
parseResult
->
GetParameterDouble
(
"OriginX
"
);
origin
[
1
]
=
parseResult
->
GetParameterDouble
(
"OriginY
"
);
origin
[
0
]
=
GetParameterFloat
(
"orx
"
);
origin
[
1
]
=
GetParameterFloat
(
"ory
"
);
}
else
{
origin
=
v
dProperties
->
GetBoundingRegion
().
GetIndex
();
origin
=
m_V
dProperties
->
GetBoundingRegion
().
GetIndex
();
}
if
(
parseResult
->
IsOptionPresent
(
"SpacingX"
)
&&
parseResult
->
IsOptionPresent
(
"SpacingY
"
))
if
(
HasValue
(
"spx"
)
&&
HasValue
(
"spy
"
))
{
spacing
[
0
]
=
parseResult
->
GetParameterDouble
(
"SpacingX
"
);
spacing
[
1
]
=
parseResult
->
GetParameterDouble
(
"SpacingY
"
);
spacing
[
0
]
=
GetParameterFloat
(
"spx
"
);
spacing
[
1
]
=
GetParameterFloat
(
"spy
"
);
}
else
{
spacing
[
0
]
=
v
dProperties
->
GetBoundingRegion
().
GetSize
()[
0
]
/
size
[
0
];
spacing
[
1
]
=
v
dProperties
->
GetBoundingRegion
().
GetSize
()[
1
]
/
size
[
1
];
spacing
[
0
]
=
m_V
dProperties
->
GetBoundingRegion
().
GetSize
()[
0
]
/
size
[
0
];
spacing
[
1
]
=
m_V
dProperties
->
GetBoundingRegion
().
GetSize
()[
1
]
/
size
[
1
];
}
sizePhy
[
0
]
=
size
[
0
]
*
spacing
[
0
];
...
...
@@ -214,68 +225,60 @@ int Rasterization::Execute(otb::ApplicationOptionsResult* parseResult)
}
else
{
std
::
cerr
<<
"Input entry problem "
<<
std
::
endl
<<
" if no reference image given, region size is needed "
<<
std
::
endl
;
return
EXIT_FAILURE
;
otbAppLogFATAL
(
"Input entry problem, if no reference image given, region size is needed "
);
}
// Reprojecting the VectorData
VectorDataProjectionFilterType
::
Pointer
vproj
=
VectorDataProjectionFilterType
::
New
();
vproj
->
SetInput
(
vdReader
->
GetOutput
());
//
vproj
->
SetInputProjectionRef
(
vdReader
->
GetOutput
()
->
GetProjectionRef
());
vproj
->
SetOutputProjectionRef
(
outputProjectionRef
);
if
(
parseResult
->
IsOptionPresent
(
"InputImage"
))
{
vproj
->
SetOutputKeywordList
(
referenceImage
->
GetImageKeywordlist
());
}
RemoteSensingRegionType
region
;
region
.
SetSize
(
sizePhy
);
region
.
SetOrigin
(
origin
);
region
.
SetRegionProjection
(
outputProjectionRef
);
if
(
parseResult
->
IsOptionPresent
(
"InputImage"
))
{
region
.
SetKeywordList
(
referenceImage
->
GetImageKeywordlist
());
}
VectorDataExtractROIType
::
Pointer
vdextract
=
VectorDataExtractROIType
::
New
();
vdextract
->
SetRegion
(
region
);
vdextract
->
SetInput
(
vproj
->
GetOutput
());
VectorDataToImageFilterType
::
Pointer
vectorDataRendering
=
VectorDataToImageFilterType
::
New
();
vectorDataRendering
->
SetInput
(
vdextract
->
GetOutput
());
vectorDataRendering
->
SetSize
(
size
);
vectorDataRendering
->
SetOrigin
(
origin
);
vectorDataRendering
->
SetSpacing
(
spacing
);
vectorDataRendering
->
SetVectorDataProjectionWKT
(
outputProjectionRef
);
vectorDataRendering
->
SetRenderingStyleType
(
VectorDataToImageFilterType
::
Binary
);
ImageType
::
Pointer
outputImage
=
vectorDataRendering
->
GetOutput
();
if
(
parseResult
->
IsOptionPresent
(
"InputImage"
))
{
outputImage
->
SetMetaDataDictionary
(
referenceImage
->
GetMetaDataDictionary
());
}
// Instantiate the writer
std
::
string
oFilename
=
parseResult
->
GetParameterString
(
"OutputImage"
);
WriterType
::
Pointer
oWriter
=
WriterType
::
New
();
oWriter
->
SetFileName
(
oFilename
);
oWriter
->
SetInput
(
outputImage
);
unsigned
int
ram
=
256
;
if
(
parseResult
->
IsOptionPresent
(
"AvailableMemory"
))
{
ram
=
parseResult
->
GetParameterUInt
(
"AvailableMemory"
);
// Reprojecting the VectorData
m_Vproj
=
VectorDataProjectionFilterType
::
New
();
m_Vproj
->
SetInput
(
inputVData
);
m_Vproj
->
SetInputProjectionRef
(
inputVData
->
GetProjectionRef
());
m_Vproj
->
SetOutputProjectionRef
(
outputProjectionRef
);
if
(
HasValue
(
"im"
))
{
m_Vproj
->
SetOutputKeywordList
(
referenceImage
->
GetImageKeywordlist
());
}
RemoteSensingRegionType
region
;
region
.
SetSize
(
sizePhy
);
region
.
SetOrigin
(
origin
);
region
.
SetRegionProjection
(
outputProjectionRef
);
if
(
HasValue
(
"im"
))
{
region
.
SetKeywordList
(
referenceImage
->
GetImageKeywordlist
());
}
m_Vdextract
=
VectorDataExtractROIType
::
New
();
m_Vdextract
->
SetRegion
(
region
);
m_Vdextract
->
SetInput
(
m_Vproj
->
GetOutput
());
m_VectorDataRendering
=
VectorDataToImageFilterType
::
New
();
m_VectorDataRendering
->
SetInput
(
m_Vdextract
->
GetOutput
());
m_VectorDataRendering
->
SetSize
(
size
);
m_VectorDataRendering
->
SetOrigin
(
origin
);
m_VectorDataRendering
->
SetSpacing
(
spacing
);
m_VectorDataRendering
->
SetVectorDataProjectionWKT
(
outputProjectionRef
);
m_VectorDataRendering
->
SetRenderingStyleType
(
VectorDataToImageFilterType
::
Binary
);
UInt8ImageType
::
Pointer
outputImage
=
m_VectorDataRendering
->
GetOutput
();
if
(
HasValue
(
"im"
))
{
outputImage
->
SetMetaDataDictionary
(
referenceImage
->
GetMetaDataDictionary
());
}
AddProcess
(
m_VectorDataRendering
,
"Rasterization"
);
SetParameterOutputImage
<
UInt8ImageType
>
(
"out"
,
outputImage
);
}
oWriter
->
SetAutomaticTiledStreaming
(
ram
);
otb
::
StandardWriterWatcher
watcher
(
oWriter
,
"Rasterization"
);
oWriter
->
Update
();
VectorDataPropertiesType
::
Pointer
m_VdProperties
;
VectorDataProjectionFilterType
::
Pointer
m_Vproj
;
VectorDataExtractROIType
::
Pointer
m_Vdextract
;
VectorDataToImageFilterType
::
Pointer
m_VectorDataRendering
;
};
return
EXIT_SUCCESS
;
}
}
OTB_APPLICATION_EXPORT
(
otb
::
Wrapper
::
Rasterization
)
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