Skip to content
Snippets Groups Projects
Commit afe6579a authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

DOC: add example for VectorDataExtractROI (WIP)

parent 3edb1909
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,10 @@ ENDIF( OTB_USE_CURL )
ADD_EXECUTABLE(VectorDataProjectionExample VectorDataProjectionExample.cxx )
TARGET_LINK_LIBRARIES(VectorDataProjectionExample OTBProjections OTBCommon OTBIO)
ADD_EXECUTABLE(VectorDataExtractROIExample VectorDataExtractROIExample.cxx )
TARGET_LINK_LIBRARIES(VectorDataExtractROIExample OTBProjections OTBCommon OTBIO)
IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
SET(BASELINE ${OTB_DATA_ROOT}/Baseline/Examples/Projections)
......
/*=========================================================================
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
// Software Guide : BeginLatex
//
// There is some vector data sets widely available on the internet. These data
// sets can be huge, covering an entire country, with hundreds of thousands
// objects.
//
// Most of the time, you won't be interested in the whole area and would like
// to focuss only on the area corresponding to your satellite image.
//
//
// This example demonstrates the use of the
// \doxygen{otb}{VectorDataExtractROI}.
//
// Software Guide : EndLatex
#include "otbVectorData.h"
#include "otbVectorDataExtractROI.h"
#include "otbCartographicRegion.h"
#include "otbVectorDataFileReader.h"
#include "otbVectorDataFileWriter.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
int main( int argc, char* argv[] )
{
if (argc < 4 )
{
std::cout << argv[0] <<" <input vector filename> <input image name> <output vector filename> " << std::endl;
return EXIT_FAILURE;
}
const char * inVectorName = argv[1];
const char * inImageName = argv[2];
const char * outVectorName = argv[3];
typedef double Type;
typedef otb::VectorData<> VectorDataType;
typedef otb::VectorDataExtractROI< VectorDataType > FilterType;
typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType;
typedef otb::VectorDataFileWriter<VectorDataType> VectorDataWriterType;
typedef otb::CartographicRegion<Type> TypedRegion;
typedef otb::Image<unsigned char, 2> ImageType;
typedef otb::ImageFileReader<ImageType> ImageReaderType;
ImageReaderType::Pointer imageReader = ImageReaderType::New();
imageReader->SetFileName(inImageName);
imageReader->UpdateOutputInformation();
FilterType::Pointer filter = FilterType::New();
VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New();
VectorDataWriterType::Pointer writer = VectorDataWriterType::New();
TypedRegion region;
TypedRegion::SizeType size;
TypedRegion::IndexType index;
size[0] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]
* imageReader->GetOutput()->GetSpacing()[0];
size[1] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]
* imageReader->GetOutput()->GetSpacing()[1];
index[0] = imageReader->GetOutput()->GetOrigin()[0]
- 0.5 * imageReader->GetOutput()->GetSpacing()[0];
index[1] = imageReader->GetOutput()->GetOrigin()[1]
- 0.5 * imageReader->GetOutput()->GetSpacing()[1];
region.SetSize(size);
region.SetOrigin(index);
otb::ImageMetadataInterface::Pointer imageMetadataInterface = otb::ImageMetadataInterface::New();
region.SetRegionProjection(imageMetadataInterface->GetProjectionRef(imageReader->GetOutput()->GetMetaDataDictionary()));
reader->SetFileName(inVectorName);
filter->SetInput(reader->GetOutput());
filter->SetRegion(region);
writer->SetFileName(outVectorName);
writer->SetInput(filter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
......@@ -47,7 +47,7 @@
int main( int argc, char* argv[] )
{
if (argc < 3 )
if (argc < 4 )
{
std::cout << argv[0] <<" <input vector filename> <input image name> <output vector filename> " << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment