From d6e3790d9346a34a76f110b31189f0d170652bbe Mon Sep 17 00:00:00 2001
From: Guillaume Borrut <guillaume.borrut@c-s.fr>
Date: Wed, 1 Apr 2009 11:29:25 +0200
Subject: [PATCH] ENH: Adding test which shows that several polygons can be
 written in a shapefile in the same folder

---
 Testing/Code/IO/CMakeLists.txt                | 12 +++
 Testing/Code/IO/otbIOTests15.cxx              |  1 +
 .../IO/otbVectorDataFileWriterPolygons.cxx    | 93 +++++++++++++++++++
 3 files changed, 106 insertions(+)
 create mode 100644 Testing/Code/IO/otbVectorDataFileWriterPolygons.cxx

diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt
index 813dc06bbe..0d5a5b7792 100755
--- a/Testing/Code/IO/CMakeLists.txt
+++ b/Testing/Code/IO/CMakeLists.txt
@@ -1538,6 +1538,17 @@ ADD_TEST(ioTvVectorDataFileWriterTwice ${IO_TESTS15}
 # If the file exists, try remove it to prevent test failure
 FILE(REMOVE ${TEMP}/ioTvVectorDataFileReaderWriterOutput.shp)
 
+
+ADD_TEST(ioTvVectorDataFileWriterPolygons ${IO_TESTS15}
+        otbVectorDataFileWriterPolygons
+    ${TEMP}/ioTvVectorDataFileWriterOutput.shp
+    )
+
+# If the file exists, try remove it to prevent test failure
+FILE(REMOVE ${TEMP}/ioTvVectorDataFileReaderWriterOutput.shp)
+
+
+
 IF(OTB_DATA_USE_LARGEINPUT)
 ADD_TEST(ioTvVectorDataFileReaderWriter ${IO_TESTS15}
         --compare-n-binary 4
@@ -1824,6 +1835,7 @@ otbVectorDataFileReaderNew.cxx
 otbVectorDataFileReader.cxx
 otbVectorDataFileWriterNew.cxx
 otbVectorDataFileWriter.cxx
+otbVectorDataFileWriterPolygons.cxx
 otbVectorDataFileReaderWriter.cxx
 otbVectorDataFileGeoReaderWriter.cxx
 otbSHPVectorDataIONew.cxx
diff --git a/Testing/Code/IO/otbIOTests15.cxx b/Testing/Code/IO/otbIOTests15.cxx
index 7a62aaa3d7..b6b6f55dec 100644
--- a/Testing/Code/IO/otbIOTests15.cxx
+++ b/Testing/Code/IO/otbIOTests15.cxx
@@ -33,6 +33,7 @@ void RegisterTests()
   REGISTER_TEST(otbVectorDataFileReader);
   REGISTER_TEST(otbVectorDataFileWriterNew);
   REGISTER_TEST(otbVectorDataFileWriter);
+  REGISTER_TEST(otbVectorDataFileWriterPolygons);
   REGISTER_TEST(otbVectorDataFileReaderWriter);
   REGISTER_TEST(otbVectorDataFileGeoReaderWriter);
   REGISTER_TEST(otbSHPVectorDataIONew);
diff --git a/Testing/Code/IO/otbVectorDataFileWriterPolygons.cxx b/Testing/Code/IO/otbVectorDataFileWriterPolygons.cxx
new file mode 100644
index 0000000000..9f0899ac48
--- /dev/null
+++ b/Testing/Code/IO/otbVectorDataFileWriterPolygons.cxx
@@ -0,0 +1,93 @@
+/*=========================================================================
+
+  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 "itkExceptionObject.h"
+#include "otbMacro.h"
+
+#include "otbVectorData.h"
+#include "otbVectorDataFileWriter.h"
+
+int otbVectorDataFileWriterPolygons(int argc, char * argv[])
+{
+
+  typedef otb::VectorData<double,2> VectorDataType;
+  typedef VectorDataType::DataNodeType DataNodeType;
+  typedef otb::VectorDataFileWriter<VectorDataType> WriterType;
+  typedef DataNodeType::PointType PointType;
+  typedef DataNodeType::LineType LineType;
+  typedef DataNodeType::PolygonType PolygonType;
+  typedef LineType::VertexType VertexType;
+
+  //Instantiation
+  WriterType::Pointer writer = WriterType::New();
+  VectorDataType::Pointer data = VectorDataType::New();
+
+  DataNodeType::Pointer document = DataNodeType::New();
+  DataNodeType::Pointer folder = DataNodeType::New();
+
+  DataNodeType::Pointer polygon1 = DataNodeType::New();
+  DataNodeType::Pointer polygon2 = DataNodeType::New();
+  DataNodeType::Pointer polygon3 = DataNodeType::New();
+  DataNodeType::Pointer polygon4 = DataNodeType::New();
+  DataNodeType::Pointer polygon5 = DataNodeType::New();
+
+  document->SetNodeType(otb::DOCUMENT);
+  folder->SetNodeType(otb::FOLDER);
+  polygon1->SetNodeType(otb::FEATURE_POLYGON);
+
+  document->SetNodeId("DOCUMENT");
+  folder->SetNodeId("THE_FOLDER");
+  polygon1->SetNodeId("FEATURE_POLYGON");
+
+  VertexType p1;
+  p1.Fill(5);
+
+  VertexType p3;
+  p3.Fill(0);
+
+  VertexType p2;
+  p2[0]=0;
+  p2[1]=10;
+
+
+  PolygonType::Pointer poly = PolygonType::New();
+  poly->AddVertex(p1);
+  poly->AddVertex(p2);
+  poly->AddVertex(p3);
+  polygon1->SetLine(poly);
+
+  polygon2=polygon1;
+  polygon3=polygon1;
+  polygon4=polygon1;
+  polygon5=polygon1;
+
+  DataNodeType::Pointer root = data->GetDataTree()->GetRoot()->Get();
+
+  data->GetDataTree()->Add(document,root);
+  data->GetDataTree()->Add(folder,document);
+  data->GetDataTree()->Add(polygon1,folder);
+  data->GetDataTree()->Add(polygon2,folder);
+  data->GetDataTree()->Add(polygon3,folder);
+  data->GetDataTree()->Add(polygon4,folder);
+  data->GetDataTree()->Add(polygon5,folder);
+
+  writer->SetFileName(argv[1]);
+  writer->SetInput(data);
+  writer->Update();
+
+  return EXIT_SUCCESS;
+}
-- 
GitLab