diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt index cb1f467fe225ba5ac4aa350800bc40d0f055aafe..e131c4cde5f6fb307738349aa2975f3a16310747 100755 --- a/Testing/Code/Common/CMakeLists.txt +++ b/Testing/Code/Common/CMakeLists.txt @@ -753,6 +753,20 @@ ADD_TEST(coTvVectorDataToImageFilterSensorModel ${COMMON_TESTS9} ) ENDIF(OTB_DATA_USE_LARGEINPUT) +ADD_TEST(coTvVectorDataToImageFilterWorld ${COMMON_TESTS9} + --compare-image ${NOTOL} + ${BASELINE}/coTvVectorDataToImageFilterWorld.png + ${TEMP}/coTvVectorDataToImageFilterWorld.png + otbVectorDataToImageFilterWorld + ${INPUTDATA}/world_boundaries/world_boundaries_m.shp + ${INPUTDATA}/world_boundaries/places.shp + ${TEMP}/coTvVectorDataToImageFilterWorld.png + 500 500 #Size + -20 60 #lon/lat + 0.1 -0.1 #spacing lon/lat +) + + ENDIF(OTB_USE_MAPNIK) # ------- Fichiers sources CXX ----------------------------------- @@ -864,6 +878,7 @@ SET(BasicCommon_SRCS9 otbVectorDataToImageFilterNew.cxx otbVectorDataToImageFilter.cxx otbVectorDataToImageFilterSensorModel.cxx +otbVectorDataToImageFilterWorld.cxx ) ENDIF(OTB_USE_MAPNIK) diff --git a/Testing/Code/Common/otbCommonTests9.cxx b/Testing/Code/Common/otbCommonTests9.cxx index f1851edeefebf99c7ca2097324484c31b9e686ae..66b5f509efad4c4a3975a45b000b36e42279b1ea 100644 --- a/Testing/Code/Common/otbCommonTests9.cxx +++ b/Testing/Code/Common/otbCommonTests9.cxx @@ -29,4 +29,5 @@ void RegisterTests() REGISTER_TEST(otbVectorDataToImageFilterNew); REGISTER_TEST(otbVectorDataToImageFilter); REGISTER_TEST(otbVectorDataToImageFilterSensorModel); +REGISTER_TEST(otbVectorDataToImageFilterWorld); } diff --git a/Testing/Code/Common/otbVectorDataToImageFilterWorld.cxx b/Testing/Code/Common/otbVectorDataToImageFilterWorld.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4d7316e3e02dbf5b7cedb2b9268a10bbb89ac927 --- /dev/null +++ b/Testing/Code/Common/otbVectorDataToImageFilterWorld.cxx @@ -0,0 +1,103 @@ +/*========================================================================= + +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. + +=========================================================================*/ + +#include "otbVectorDataFileReader.h" +#include "otbImageFileWriter.h" +#include "otbVectorData.h" +#include "otbVectorDataProjectionFilter.h" +#include "otbVectorDataExtractROI.h" +#include <fstream> +#include <iostream> + +#include "itkRGBAPixel.h" +#include "otbImage.h" +#include "otbVectorDataToImageFilter.h" + +int otbVectorDataToImageFilterWorld(int argc, char * argv[]) +{ + + if (argc < 10 ) + { + std::cout << argv[0] <<" <input vector filename> <input image filename>" + << " <output vector filename> " + << " <sizeX> <sizeY> " + << " <origin lon> <origin lat> " + << " <spacing lon> <spacing lat> " << std::endl; + return EXIT_FAILURE; + } + + //Read the vector data + typedef otb::VectorData<> VectorDataType; + typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; + + //Reproject the vector data in the proper projection + typedef otb::VectorDataProjectionFilter<VectorDataType, VectorDataType> ProjectionFilterType; + + + VectorDataFileReaderType::Pointer reader0 = VectorDataFileReaderType::New(); + reader0->SetFileName(argv[1]); + ProjectionFilterType::Pointer projection0 = ProjectionFilterType::New(); + projection0->SetInput(reader0->GetOutput()); + + VectorDataFileReaderType::Pointer reader1 = VectorDataFileReaderType::New(); + reader1->SetFileName(argv[2]); + ProjectionFilterType::Pointer projection1 = ProjectionFilterType::New(); + projection1->SetInput(reader1->GetOutput()); + + + //Convert the vector data into an image + typedef itk::RGBAPixel< unsigned char > PixelType; + typedef otb::Image<PixelType,2> ImageType; + + ImageType::SizeType size; + size[0] = atoi(argv[4]); + size[1] = atoi(argv[5]); + + ImageType::PointType origin; + origin[0] = atof(argv[6]); + origin[1] = atof(argv[7]); + + ImageType::SpacingType spacing; + spacing[0] = atof(argv[8]); + spacing[1] = atof(argv[9]); + + + + typedef otb::VectorDataToImageFilter<VectorDataType, ImageType> VectorDataToImageFilterType; + VectorDataToImageFilterType::Pointer vectorDataRendering = VectorDataToImageFilterType::New(); + vectorDataRendering->SetInput(0,projection0->GetOutput()); + vectorDataRendering->SetInput(1,projection1->GetOutput()); + + vectorDataRendering->SetSize(size); + vectorDataRendering->SetOrigin(origin); + vectorDataRendering->SetSpacing(spacing); + vectorDataRendering->AddStyle("world"); + vectorDataRendering->AddStyle("city"); + vectorDataRendering->UseAsOverlayOff(); + + //Save the image in a file + typedef otb::ImageFileWriter<ImageType> WriterType; + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(vectorDataRendering->GetOutput()); + writer->SetFileName(argv[3]); + writer->Update(); + + + + return EXIT_SUCCESS; +}