Skip to content
Snippets Groups Projects
Commit 1086bc20 authored by Mickael Savinaud's avatar Mickael Savinaud
Browse files

WIP: add tests about vectordata extract + proj

parent a251461a
No related branches found
No related tags found
No related merge requests found
......@@ -932,15 +932,46 @@ ADD_TEST(prTvVectorDataProjectionFilterFromMapToImage ${PROJECTIONS_TESTS3}
${TEMP}/prTvVectorDataProjectionFilterFromMapToImage.kml
)
ADD_TEST(prTvVectorDataIntoImageProjectionFilter ${PROJECTIONS_TESTS3}
#--compare-ascii ${NOTOL}
#${BASELINE_FILES}/prTvVectorDataProjectionFilterFromMapToImage.kml
#${TEMP}/prTvVectorDataProjectionFilterFromMapToImage.kml
# extract from image QB and MidiPyrenees vectordata
ADD_TEST(prTvVectorData_ProjRef_ProjIntoImage_WithProjRef_Extract_Filter0 ${PROJECTIONS_TESTS3}
otbVectorDataIntoImageProjectionFilterTest
${INPUTDATA}/Classification/QB_1_ortho.tif
${INPUTDATA}/Classification/VectorData_QB1.shp
${INPUTDATA}/QB_extract_512x512.tif
${LARGEINPUT}/VECTOR/MidiPyrenees/roads.shp
${INPUTDATA}/DEM/srtm_directory
${TEMP}/prTvVectorDataProjRefProjIntoImageWithProjRef10.shp
${TEMP}/prTvVectorDataProjRefProjIntoImageWithProjRef10.txt
0
)
ADD_TEST(prTvVectorData_ProjRef_ProjIntoImage_WithProjRef_ExtractLeftUp_Filter0 ${PROJECTIONS_TESTS3}
otbVectorDataIntoImageProjectionFilterTest
${INPUTDATA}/QB_extract_leftup_256x2048.tif
${LARGEINPUT}/VECTOR/MidiPyrenees/roads.shp
${INPUTDATA}/DEM/srtm_directory
${TEMP}/prTvVectorDataProjRefProjIntoImageWithProjRef20.shp
${TEMP}/prTvVectorDataProjRefProjIntoImageWithProjRef20.txt
0
)
ADD_TEST(prTvVectorData_ProjRef_ProjIntoImage_WithProjRef_Extract_Filter1 ${PROJECTIONS_TESTS3}
otbVectorDataIntoImageProjectionFilterTest
${INPUTDATA}/QB_extract_512x512.tif
${LARGEINPUT}/VECTOR/MidiPyrenees/roads.shp
${INPUTDATA}/DEM/srtm_directory
${TEMP}/prTvVectorDataProjRefProjIntoImageWithProjRef11.shp
${TEMP}/prTvVectorDataProjRefProjIntoImageWithProjRef11.txt
1
)
ADD_TEST(prTvVectorData_ProjRef_ProjIntoImage_WithProjRef_ExtractLeftUp_Filter1 ${PROJECTIONS_TESTS3}
otbVectorDataIntoImageProjectionFilterTest
${INPUTDATA}/QB_extract_leftup_256x2048.tif
${LARGEINPUT}/VECTOR/MidiPyrenees/roads.shp
${INPUTDATA}/DEM/srtm_directory
${TEMP}/prTvVectorDataProjRefProjIntoImageWithProjRef21.shp
${TEMP}/prTvVectorDataProjRefProjIntoImageWithProjRef21.txt
1
)
ADD_TEST(prTuGeocentricTransformNew ${PROJECTIONS_TESTS3} otbGeocentricTransformNew )
......
......@@ -15,6 +15,8 @@
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <fstream>
#include "itkExceptionObject.h"
#include "otbMacro.h"
......@@ -23,61 +25,70 @@
#include "otbImageFileReader.h"
#include "otbVectorData.h"
#include "otbVectorDataFileReader.h"
#include "otbVectorDataFileWriter.h"
#include "otbVectorDataIntoImageProjectionFilter.h"
int otbVectorDataIntoImageProjectionFilterTest(int argc, char * argv[])
{
typedef float PixelType;
typedef otb::VectorImage<PixelType, 2> VectorImageType;
typedef otb::Image<PixelType, 2> ImageType;
typedef otb::VectorImage<PixelType, 2> VectorImageType;
typedef otb::Image<PixelType, 2> ImageType;
typedef otb::ImageFileReader<VectorImageType> ReaderType;
// Vector Data
typedef otb::VectorData<> VectorDataType;
typedef otb::VectorDataFileReader<VectorDataType> VectorDataReaderType;
typedef otb::VectorDataFileWriter<VectorDataType> VectorDataWriterType;
//
typedef otb::VectorDataIntoImageProjectionFilter<VectorDataType, VectorImageType>
VectorDataReProjFilter;
typedef otb::VectorDataIntoImageProjectionFilter
<VectorDataType, VectorImageType> VectorDataReProjFilter;
typedef itk::PreOrderTreeIterator<VectorDataType::DataTreeType> TreeIteratorType;
std::string imageInputFilename = argv[1];
std::string vectorDataInputFilename = argv[2];
std::string demDirectory = argv[3];
std::string vectorDataOutputFilename = argv[4];
std::string txtOutputFilename = argv[5];
std::cout << imageInputFilename << "\n"
<< vectorDataInputFilename << "\n"
<< demDirectory << "\n"
<< vectorDataOutputFilename << "\n"
<< txtOutputFilename << std::endl;
// Read the image
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->SetFileName(imageInputFilename);
reader->UpdateOutputInformation();
std::cout<<"Processing image: "<<reader->GetFileName()<<std::endl;
// read the Vector Data
VectorDataReaderType::Pointer vdReader = VectorDataReaderType::New();
vdReader->SetFileName(argv[2]);
vdReader->SetFileName(vectorDataInputFilename);
vdReader->Update();
std::cout<<"Processing vectorData: "<<vdReader->GetFileName()<<std::endl;
std::cout<<"Set input data to read data DONE"<<std::endl;
std::ofstream file;
file.open(txtOutputFilename.c_str());
file << "--- IMAGE INPUT ---" << std::endl;
file << "Spacing of the input image: "<< reader->GetOutput()->GetSpacing() << std::endl;
file << "Origin of the input image: "<< reader->GetOutput()->GetOrigin() << std::endl;
file << "Size of the input image: "<< reader->GetOutput()->GetLargestPossibleRegion() << std::endl;
file << "ProjRef of the input image: "<< reader->GetOutput()->GetProjectionRef() << std::endl;
VectorDataReProjFilter::Pointer vdReProjFilter = VectorDataReProjFilter::New();
//----------
// Display input
std::cout << "--- TEST INPUT ---" << std::endl;
TreeIteratorType itVectorInput(vdReader->GetOutput()->GetDataTree());
itVectorInput.GoToBegin();
while (!itVectorInput.IsAtEnd())
{
if (itVectorInput.Get()->IsPolygonFeature())
{
std::cout << "----------\n" <<itVectorInput.Get()->GetNodeTypeAsString() << std::endl;
std::cout << "List of vertices: " << ": " <<std::endl;
for (unsigned int itPoints = 0; itPoints < itVectorInput.Get()->GetPolygonExteriorRing()->GetVertexList()->Size(); itPoints++)
{
std::cout << "vertex[" << itPoints << "]: " << itVectorInput.Get()->GetPolygonExteriorRing()->GetVertexList()->GetElement(itPoints) <<std::endl;
}
std::cout << "Polygon region: " << itVectorInput.Get()->GetPolygonExteriorRing()->GetBoundingRegion() << std::endl;
}
++itVectorInput;
}
file << "\n--- VECTOR DATA INPUT ---" << std::endl;
file << "ProjRef of the input vector data: "<< vdReader->GetOutput()->GetProjectionRef() << std::endl;
file << "Origin of the input vector data: "<< vdReader->GetOutput()->GetOrigin() << std::endl;
file << "Spacing of the input vector data: "<< vdReader->GetOutput()->GetSpacing() << std::endl;
//----------
// Set input of the filter
......@@ -85,31 +96,44 @@ int otbVectorDataIntoImageProjectionFilterTest(int argc, char * argv[])
vdReProjFilter->SetInputVectorData(vdReader->GetOutput());
vdReProjFilter->SetUseOutputSpacingAndOriginFromImage(true);
vdReProjFilter->SetDEMDirectory(demDirectory);
std::string stateOutput ="";
if (atoi(argv[6]) == 1)
{
stateOutput = "true";
vdReProjFilter->SetUseOutputSpacingAndOriginFromImage(true);
}
else
{
stateOutput = "false";
vdReProjFilter->SetUseOutputSpacingAndOriginFromImage(false);
}
std::cout<<"Set input data for the filter DONE (" << stateOutput << ")" <<std::endl;
//----------
// UPDATE
vdReProjFilter->Update();
// WRITE
//vdReProjFilter->Update();
VectorDataWriterType::Pointer vdwriter = VectorDataWriterType::New();
vdwriter->SetFileName(vectorDataOutputFilename);
vdwriter->SetInput(vdReProjFilter->GetOutput());
vdwriter->Update();
std::cout<<"Update"<<std::endl;
//----------
// check output
std::cout << "--- TEST OUTPUT ---" << std::endl;
TreeIteratorType itVector(vdReProjFilter->GetOutput()->GetDataTree());
itVector.GoToBegin();
while (!itVector.IsAtEnd())
{
if (itVector.Get()->IsPolygonFeature())
{
std::cout << "----------\n" <<itVector.Get()->GetNodeTypeAsString() << std::endl;
std::cout << "List of vertices: " << ": " <<std::endl;
for (unsigned int itPoints = 0; itPoints < itVector.Get()->GetPolygonExteriorRing()->GetVertexList()->Size(); itPoints++)
{
std::cout << "vertex[" << itPoints << "]: " << itVector.Get()->GetPolygonExteriorRing()->GetVertexList()->GetElement(itPoints) <<std::endl;
}
std::cout << "Polygon region: " << itVector.Get()->GetPolygonExteriorRing()->GetBoundingRegion() << std::endl;
}
++itVector;
}
file << "\n--- VECTRODATA OUTPUT ---" << std::endl;
file << "ProjRef of the output vector data: "<< vdReProjFilter->GetOutput()->GetProjectionRef() << std::endl;
file << "Origin of the output vector data: "<< vdReProjFilter->GetOutput()->GetOrigin() << std::endl;
file << "Spacing of the output vector data: "<< vdReProjFilter->GetOutput()->GetSpacing() << std::endl;
file.close();
std::cout<<"END"<<std::endl;
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment