From 5822a648e6680ab29c5929b22bcbb09ab265ab5d Mon Sep 17 00:00:00 2001 From: Thomas Feuvrier <thomas.feuvrier@c-s.fr> Date: Wed, 17 Sep 2008 16:03:01 +0000 Subject: [PATCH] ENH: Initialisation of KMLVectorDataIO files + tu testing. --- Code/IO/otbKMLVectorDataIO.h | 150 ++++++ Code/IO/otbKMLVectorDataIO.txx | 554 ++++++++++++++++++++++ Code/IO/otbKMLVectorDataIOFactory.h | 72 +++ Code/IO/otbKMLVectorDataIOFactory.txx | 57 +++ Testing/Code/IO/CMakeLists.txt | 6 +- Testing/Code/IO/otbIOTests15.cxx | 3 +- Testing/Code/IO/otbKMLVectorDataIONew.cxx | 29 ++ 7 files changed, 869 insertions(+), 2 deletions(-) create mode 100755 Code/IO/otbKMLVectorDataIO.h create mode 100755 Code/IO/otbKMLVectorDataIO.txx create mode 100644 Code/IO/otbKMLVectorDataIOFactory.h create mode 100644 Code/IO/otbKMLVectorDataIOFactory.txx create mode 100644 Testing/Code/IO/otbKMLVectorDataIONew.cxx diff --git a/Code/IO/otbKMLVectorDataIO.h b/Code/IO/otbKMLVectorDataIO.h new file mode 100755 index 0000000000..e66cabe5e1 --- /dev/null +++ b/Code/IO/otbKMLVectorDataIO.h @@ -0,0 +1,150 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#ifndef __otbKMLVectorDataIO_h +#define __otbKMLVectorDataIO_h + +#include "otbVectorDataIOBase.h" +#include <fstream> +#include <string> +#include <vector> + +namespace otb +{ + +/** \class KMLVectorDataIO + * + * \brief ImageIO object for reading/writing KML format vector data + * + */ +template <class TData> +class ITK_EXPORT KMLVectorDataIO + : public VectorDataIOBase<TData> + { +public: + + /** Standard class typedefs. */ + typedef KMLVectorDataIO Self; + typedef VectorDataIOBase<TData> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(KMLVectorDataIO, VectorDataIOBase); + + /** Byte order typedef */ + typedef typename Superclass::ByteOrder ByteOrder; + + /** Data typedef */ + typedef TData VectorDataType; + typedef typename VectorDataType::DataTreeType DataTreeType; + typedef typename DataTreeType::Pointer DataTreePointerType; + typedef typename DataTreeType::ConstPointer DataTreeConstPointerType; + typedef typename VectorDataType::DataNodeType DataNodeType; + typedef typename DataNodeType::Pointer DataNodePointerType; + typedef typename DataNodeType::PointType PointType; + typedef typename DataNodeType::LineType LineType; + typedef typename LineType::VertexListType VertexListType; + typedef typename VertexListType::ConstPointer VertexListConstPointerType; + typedef typename LineType::Pointer LinePointerType; + typedef typename DataNodeType::PolygonType PolygonType; + typedef typename PolygonType::Pointer PolygonPointerType; + typedef typename DataNodeType::PolygonListType PolygonListType; + typedef typename PolygonListType::Pointer PolygonListPointerType; + typedef typename VectorDataType::Pointer VectorDataPointerType; + typedef typename VectorDataType::ConstPointer VectorDataConstPointerType; + + + /*-------- This part of the interface deals with reading data. ------ */ + + /** Determine the file type. Returns true if this VectorDataIO can read the + * file specified. */ + virtual bool CanReadFile(const char*); + + /** Determine the file type. Returns true if the VectorDataIO can stream read the specified file */ + virtual bool CanStreamRead(){ return false; }; + +/* /\** Set the spacing and dimention information for the set filename. *\/ */ +/* virtual void ReadVectorDataInformation(); */ + + /** Reads the data from disk into the memory buffer provided. */ + virtual void Read(VectorDataPointerType data); + + /*-------- This part of the interfaces deals with writing data. ----- */ + + /** Determine the file type. Returns true if this ImageIO can read the + * file specified. */ + virtual bool CanWriteFile(const char*); + + /** Determine the file type. Returns true if the ImageIO can stream write the specified file */ + virtual bool CanStreamWrite() { return false; }; + +/* /\** Writes the spacing and dimentions of the image. */ +/* * Assumes SetFileName has been called with a valid file name. *\/ */ +/* virtual void WriteVectorDataInformation(); */ + + /** Writes the data to disk from the memory buffer provided. Make sure + * that the IORegion has been set properly. */ + virtual void Write(VectorDataConstPointerType data); + +protected: + /** Construtor.*/ + KMLVectorDataIO(); + /** Destructor.*/ + virtual ~KMLVectorDataIO(); + + /* virtual void InternalReadVectorDataInformation(){}; */ + + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + + + /** Conversion tools */ + +/* static DataNodePointerType ConvertGeometryToPointNode(const OGRGeometry * ogrGeometry); + + static DataNodePointerType ConvertGeometryToLineNode(const OGRGeometry * ogrGeometry); + + static DataNodePointerType ConvertGeometryToPolygonNode(const OGRGeometry * ogrGeometry); +*/ + /** end conversion tools */ + +private: + KMLVectorDataIO(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + + /** Is this necessary ? */ + + /** Internal method to read header informations */ + /* bool InternalReadHeaderInformation(std::fstream & file, const bool reportError); */ + + /* bool m_FlagWriteVectorDataInformation; */ + /* typename VectorDataIOBase<TData>::ByteOrder m_FileByteOrder; */ + /* std::fstream m_File; */ + +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbKMLVectorDataIO.txx" +#endif + +#endif // __otbKMLVectorDataIO_h diff --git a/Code/IO/otbKMLVectorDataIO.txx b/Code/IO/otbKMLVectorDataIO.txx new file mode 100755 index 0000000000..330ef6c7d1 --- /dev/null +++ b/Code/IO/otbKMLVectorDataIO.txx @@ -0,0 +1,554 @@ +/*========================================================================= + +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. + +=========================================================================*/ +#ifndef __otbKMLVectorDataIO_txx +#define __otbKMLVectorDataIO_txx + +#include "otbKMLVectorDataIO.h" + +//#include <itksys/SystemTools.hxx> +#include "itkExceptionObject.h" +//#include "itkByteSwapper.h" +#include "otbMacro.h" +#include "otbSystem.h" +#include "otbDataNode.h" +//#include "itkPreOrderTreeIterator.h" +#include "kml/base/file.h" + +namespace otb +{ + template<class TData> + KMLVectorDataIO<TData> + ::KMLVectorDataIO() + { + } + template<class TData> + KMLVectorDataIO<TData>::~KMLVectorDataIO() + { + } + template<class TData> + bool + KMLVectorDataIO<TData>::CanReadFile( const char* filename ) + { + std::string lFileName(filename); + if( System::IsADirName(lFileName) == true ) + { + return false; + } + if( System::SetToLower(System::GetExtension(lFileName)) != "kml" ) + { + return false; + } + if( kmlbase::File::Exists(lFileName) == false ) + { + return false; + } + + std::string kml; + return (kmlbase::File::ReadFileToString(lFileName, &kml) ); + } + + + // Used to print information about this object + template<class TData> + void + KMLVectorDataIO<TData>::PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + } + + // Read vector data + template<class TData> + void + KMLVectorDataIO<TData> + ::Read(VectorDataPointerType data) + { + std::string kml; + bool r = kmlbase::File::ReadFileToString(this->m_FileName, &kml); + if( r == false ) + { + itkExceptionMacro(<<"Failed to open KML data file "<<this->m_FileName); + } + + otbMsgDebugMacro( <<"Driver to read: KML"); + otbMsgDebugMacro( <<"Reading file: "<< this->m_FileName); + +#if 0 + + // Retrieving root node + DataTreePointerType tree = data->GetDataTree(); + DataNodePointerType root = tree->GetRoot()->Get(); + + + + /** Create the document node */ + DataNodePointerType document = DataNodeType::New(); + document->SetNodeType(DOCUMENT); + document->SetNodeId(dfn->GetName()); + +// document->SetField(field->GetNameRef(),OGRFieldDefn::GetFieldTypeName(field->GetType())); + // std::cout<<"Document "<<document->GetNodeId()<<": Adding field "<<field->GetNameRef()<<" "<<OGRFieldDefn::GetFieldTypeName(field->GetType())<<std::endl; + + /** Adding the layer to the data tree */ +// tree->Add(document,root); + + /** Temporary pointer to store the feature */ + DataNodePointerType folder = DataNodeType::New(); + folder->SetNodeType(FOLDER); + folder->SetNodeId(feature->GetDefnRef()->GetName()); + +folder->SetField(field->GetNameRef(),feature->GetFieldAsString(fieldIndex)); + // std::cout<<"Folder "<<folder->GetNodeId()<<": Adding field "<<field->GetNameRef()<<" "<<feature->GetFieldAsString(fieldIndex)<<std::endl; + } + + + tree->Add(folder,document); +#endif + } + + +/* + template<class TData> + typename KMLVectorDataIO<TData> + ::DataNodePointerType + KMLVectorDataIO<TData> + ::ConvertGeometryToPointNode(const OGRGeometry * ogrGeometry) + { + OGRPoint * ogrPoint = (OGRPoint *) ogrGeometry; + + if(ogrPoint == NULL) + { + itkGenericExceptionMacro(<<"Failed to convert OGRGeometry to OGRPoint"); + } + + PointType otbPoint; + otbPoint.Fill(0); + otbPoint[0] = static_cast<typename DataNodeType::PrecisionType>(ogrPoint->getX()); + otbPoint[1] = static_cast<typename DataNodeType::PrecisionType>(ogrPoint->getY()); + + if(DataNodeType::Dimension > 2) + { + otbPoint[2]=static_cast<typename DataNodeType::PrecisionType>(ogrPoint->getZ()); + } + + DataNodePointerType node = DataNodeType::New(); + node->SetPoint(otbPoint); + return node; + } + + template<class TData> + typename KMLVectorDataIO<TData> + ::DataNodePointerType + KMLVectorDataIO<TData> + ::ConvertGeometryToLineNode(const OGRGeometry * ogrGeometry) + { + OGRLineString * ogrLine = (OGRLineString *)ogrGeometry; + + if(ogrLine == NULL) + { + itkGenericExceptionMacro(<<"Failed to convert OGRGeometry to OGRLine"); + } + + + LinePointerType line = LineType::New(); + + OGRPoint * ogrTmpPoint = new OGRPoint(); + + for(int pIndex = 0;pIndex<ogrLine->getNumPoints();++pIndex) + { + + ogrLine->getPoint(pIndex,ogrTmpPoint); + + typename LineType::VertexType vertex; + + vertex[0] = ogrTmpPoint->getX(); + vertex[1] = ogrTmpPoint->getY(); + + if(DataNodeType::Dimension > 2) + { + vertex[2]= ogrTmpPoint->getZ(); + } + + line->AddVertex(vertex); + } + delete ogrTmpPoint; + + DataNodePointerType node = DataNodeType::New(); + node->SetLine(line); + + return node; + } + + template<class TData> + typename KMLVectorDataIO<TData> + ::DataNodePointerType + KMLVectorDataIO<TData> + ::ConvertGeometryToPolygonNode(const OGRGeometry * ogrGeometry) + { + OGRPolygon * ogrPolygon = (OGRPolygon *)ogrGeometry; + + if(ogrPolygon == NULL) + { + itkGenericExceptionMacro(<<"Failed to convert OGRGeometry to OGRPolygon"); + } + + OGRPoint * ogrTmpPoint = new OGRPoint(); + + OGRLinearRing * ogrRing = ogrPolygon->getExteriorRing(); + + PolygonPointerType extRing = PolygonType::New(); + + for(int pIndex = 0;pIndex<ogrRing->getNumPoints();++pIndex) + { + ogrRing->getPoint(pIndex,ogrTmpPoint); + typename PolygonType::VertexType vertex; + vertex[0] = ogrTmpPoint->getX(); + vertex[1] = ogrTmpPoint->getY(); + + if(DataNodeType::Dimension > 2) + { + vertex[2]= ogrTmpPoint->getZ(); + } + + extRing->AddVertex(vertex); + } + + PolygonListPointerType intRings = PolygonListType::New(); + + for(int intRingIndex = 0;intRingIndex<ogrPolygon->getNumInteriorRings();++intRingIndex) + { + PolygonPointerType ring = PolygonType::New(); + ogrRing = ogrPolygon->getInteriorRing(intRingIndex); + for(int pIndex = 0;pIndex<ogrRing->getNumPoints();++pIndex) + { + ogrRing->getPoint(pIndex,ogrTmpPoint); + typename PolygonType::VertexType vertex; + + vertex[0] = ogrTmpPoint->getX(); + vertex[1] = ogrTmpPoint->getY(); + if(DataNodeType::Dimension > 2) + { + vertex[2]= ogrTmpPoint->getZ(); + } + ring->AddVertex(vertex); + } + intRings->PushBack(ring); + } + + delete ogrTmpPoint; + + DataNodePointerType node = DataNodeType::New(); + node->SetPolygonExteriorRing(extRing); + node->SetPolygonInteriorRings(intRings); + + return node; + } +*/ + + template<class TData> + bool KMLVectorDataIO<TData>::CanWriteFile( const char* filename ) + { + std::string lFileName(filename); + if( System::IsADirName(lFileName) == true ) + { + return false; + } + if( System::SetToLower(System::GetExtension(lFileName)) != "kml" ) + { + return false; + } + return true; + } + + template<class TData> + void KMLVectorDataIO<TData>::Write(const VectorDataConstPointerType data) + { + +/* + // // try to create an ogr driver + OGRSFDriver * ogrDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("ESRI Shapefile"); + + if(ogrDriver == NULL) + { + itkExceptionMacro(<<"No OGR driver found to write file "<<this->m_FileName); + } + + // free an existing previous data source, if any + if(m_DataSource != NULL) + { + OGRDataSource::DestroyDataSource(m_DataSource); + } + // m_DataSource = OGRSFDriverRegistrar::Open(this->m_FileName.c_str(), TRUE); + m_DataSource = ogrDriver->CreateDataSource(this->m_FileName.c_str(),NULL); + + + // check the created data source + if(m_DataSource == NULL) + { + itkExceptionMacro(<<"Failed to create OGR data source for file "<<this->m_FileName<<". Since OGR can not overwrite existing file, be sure that this file does not already exist"); + } + + // Retrieving root node + DataTreeConstPointerType tree = data->GetDataTree(); + DataNodePointerType root = tree->GetRoot()->Get(); + + typedef itk::PreOrderTreeIterator<DataTreeType> TreeIteratorType; + + OGRLayer * ogrCurrentLayer = NULL; + std::vector<OGRFeature *> ogrFeatures; + OGRGeometryCollection * ogrCollection = NULL; + // OGRGeometry * ogrCurrentGeometry = NULL; + + + TreeIteratorType it(tree); + it.GoToBegin(); + + while(!it.IsAtEnd()) + { + switch(it.Get()->GetNodeType()) + { + case ROOT: + { + break; + } + case DOCUMENT: + { + if(ogrCurrentLayer!=NULL && ogrFeatures.size()>0) + { + std::vector<OGRFeature*>::iterator fIt = ogrFeatures.begin(); + + while(fIt!=ogrFeatures.end()) + { + if(ogrCurrentLayer->CreateFeature(*fIt) != OGRERR_NONE) + { + itkExceptionMacro(<<"Failed to create ogr feature in file "<<this->m_FileName); + } + OGRFeature::DestroyFeature(*fIt); + ++fIt; + } + } + ogrFeatures.clear(); + ogrCurrentLayer = m_DataSource->CreateLayer(it.Get()->GetNodeId(),NULL,wkbUnknown,NULL); + if(ogrCurrentLayer == NULL) + { + itkExceptionMacro(<<"Failed to create layer "<<it.Get()->GetNodeId()); + } + break; + } + case FOLDER: + { + if(ogrCurrentLayer!=NULL && ogrCollection != NULL && !ogrFeatures.empty()) + { + ogrFeatures.back()->SetGeometry(ogrCollection); + delete ogrCollection; + ogrCollection = NULL; + } + + ogrFeatures.push_back(OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn())); + ogrFeatures.back()->SetField("Name",it.Get()->GetNodeId()); + + break; + } + case FEATURE_POINT: + { + OGRPoint ogrPoint; + ogrPoint.setX(it.Get()->GetPoint()[0]); + ogrPoint.setY(it.Get()->GetPoint()[1]); + + if(DataNodeType::Dimension>2) + { + ogrPoint.setZ(it.Get()->GetPoint()[2]); + } + + if(ogrCollection == NULL) + { + ogrFeatures.back()->GetDefnRef()->SetGeomType(wkbPoint); + ogrFeatures.back()->SetGeometry(&ogrPoint); + } + else + { + ogrCollection->addGeometry(&ogrPoint); + } + + break; + } + case FEATURE_LINE: + { + OGRLineString ogrLine; + VertexListConstPointerType vertexList = it.Get()->GetLine()->GetVertexList(); + + typename VertexListType::ConstIterator vIt = vertexList->Begin(); + + while(vIt != vertexList->End()) + { + OGRPoint ogrPoint; + ogrPoint.setX(vIt.Value()[0]); + ogrPoint.setY(vIt.Value()[1]); + if(DataNodeType::Dimension>2) + { + ogrPoint.setZ(vIt.Value()[2]); + } + ogrLine.addPoint(&ogrPoint); + ++vIt; + } + + if(ogrCollection == NULL) + { + ogrFeatures.back()->GetDefnRef()->SetGeomType(wkbLineString); + ogrFeatures.back()->SetGeometry(&ogrLine); + } + else + { + ogrCollection->addGeometry(&ogrLine); + } + + break; + } + case FEATURE_POLYGON: + { + OGRPolygon * ogrPolygon = new OGRPolygon(); + OGRLinearRing * ogrExternalRing = new OGRLinearRing(); + VertexListConstPointerType vertexList = it.Get()->GetPolygonExteriorRing()->GetVertexList(); + + typename VertexListType::ConstIterator vIt = vertexList->Begin(); + + while(vIt != vertexList->End()) + { + OGRPoint ogrPoint; + ogrPoint.setX(vIt.Value()[0]); + ogrPoint.setY(vIt.Value()[1]); + if(DataNodeType::Dimension>2) + { + ogrPoint.setZ(vIt.Value()[2]); + } + + ogrExternalRing->addPoint(&ogrPoint); + ++vIt; + } + ogrPolygon->addRing(ogrExternalRing); + delete ogrExternalRing; + + // Retrieving internal rings as well + for(typename PolygonListType::Iterator pIt = it.Get()->GetPolygonInteriorRings()->Begin(); + pIt!=it.Get()->GetPolygonInteriorRings()->End();++pIt) + { + OGRLinearRing * ogrInternalRing = new OGRLinearRing(); + vertexList = pIt.Get()->GetVertexList(); + vIt = vertexList->Begin(); + + while(vIt != vertexList->End()) + { + OGRPoint ogrPoint; + ogrPoint.setX(vIt.Value()[0]); + ogrPoint.setY(vIt.Value()[1]); + if(DataNodeType::Dimension>2) + { + ogrPoint.setZ(vIt.Value()[2]); + } + ogrInternalRing->addPoint(&ogrPoint); + ++vIt; + } + ogrPolygon->addRing(ogrInternalRing); + delete ogrInternalRing; + } + if(ogrCollection == NULL) + { + ogrFeatures.back()->GetDefnRef()->SetGeomType(wkbPolygon); + ogrFeatures.back()->SetGeometry(ogrPolygon); + } + else + { + ogrCollection->addGeometry(ogrPolygon); + } + + delete ogrPolygon; + break; + } + case FEATURE_MULTIPOINT: + { + if(ogrCollection != NULL || ogrFeatures.empty()) + { + itkExceptionMacro(<<"Problem while creating multipoint."); + } + ogrCollection = new OGRMultiPoint(); + ogrFeatures.back()->GetDefnRef()->SetGeomType(wkbMultiPoint); + break; + } + case FEATURE_MULTILINE: + { + if(ogrCollection != NULL || ogrFeatures.empty()) + { + itkExceptionMacro(<<"Problem while creating multiline."); + } + ogrCollection = new OGRMultiLineString(); + ogrFeatures.back()->GetDefnRef()->SetGeomType(wkbMultiLineString); + break; + } + case FEATURE_MULTIPOLYGON: + { + if(ogrCollection != NULL || ogrFeatures.empty()) + { + itkExceptionMacro(<<"Problem while creating multipolygon."); + } + ogrCollection = new OGRMultiPolygon(); + ogrFeatures.back()->GetDefnRef()->SetGeomType(wkbMultiPolygon); + break; + } + case FEATURE_COLLECTION: + { + if(ogrCollection != NULL || ogrFeatures.empty()) + { + itkExceptionMacro(<<"Problem while creating collection."); + } + ogrCollection = new OGRMultiPoint(); + ogrFeatures.back()->GetDefnRef()->SetGeomType(wkbGeometryCollection); + break; + } + } + ++it; + } + if(ogrCurrentLayer!=NULL && ogrCollection != NULL && !ogrFeatures.empty()) + { + ogrFeatures.back()->SetGeometry(ogrCollection); + delete ogrCollection; + ogrCollection = NULL; + } + + if(ogrCurrentLayer!=NULL && ogrFeatures.size()>0) + { + std::vector<OGRFeature*>::iterator fIt = ogrFeatures.begin(); + + while(fIt!=ogrFeatures.end()) + { + if(ogrCurrentLayer->CreateFeature(*fIt) != OGRERR_NONE) + { + itkExceptionMacro(<<"Failed to create ogr feature in file "<<this->m_FileName); + } + OGRFeature::DestroyFeature(*fIt); + ++fIt; + } + } + ogrFeatures.clear(); + + otbMsgDevMacro( <<" KMLVectorDataIO::Write() "); +*/ + + } + + } // end namespace otb + +#endif diff --git a/Code/IO/otbKMLVectorDataIOFactory.h b/Code/IO/otbKMLVectorDataIOFactory.h new file mode 100644 index 0000000000..fbbfb5aaf0 --- /dev/null +++ b/Code/IO/otbKMLVectorDataIOFactory.h @@ -0,0 +1,72 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#ifndef __otbKMLVectorDataIOFactory_h +#define __otbKMLVectorDataIOFactory_h + +#include "itkObjectFactoryBase.h" + +namespace otb +{ +/** \class KMLVectorDataIOFactory + * \brief Creation d'un instance d'un objet VectorDataImageIO utilisant les object factory. + */ +template <class TData> class ITK_EXPORT KMLVectorDataIOFactory : public itk::ObjectFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef KMLVectorDataIOFactory Self; + typedef itk::ObjectFactoryBase Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Class methods used to interface with the registered factories. */ + virtual const char* GetITKSourceVersion(void) const; + virtual const char* GetDescription(void) const; + + /** Method for class instantiation. */ + itkFactorylessNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(KMLVectorDataIOFactory, itk::ObjectFactoryBase); + + /** Register one factory of this type */ + static void RegisterOneFactory(void) + { + typename KMLVectorDataIOFactory<TData>::Pointer SHPFactory = KMLVectorDataIOFactory<TData>::New(); + itk::ObjectFactoryBase::RegisterFactory(SHPFactory); + } + +protected: + KMLVectorDataIOFactory(); + ~KMLVectorDataIOFactory(); + +private: + KMLVectorDataIOFactory(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; + + +} // end namespace otb + + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbKMLVectorDataIOFactory.txx" +#endif + +#endif diff --git a/Code/IO/otbKMLVectorDataIOFactory.txx b/Code/IO/otbKMLVectorDataIOFactory.txx new file mode 100644 index 0000000000..a5d1eefa42 --- /dev/null +++ b/Code/IO/otbKMLVectorDataIOFactory.txx @@ -0,0 +1,57 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#ifndef __otbKMLVectorDataIOFactory_txx +#define __otbKMLVectorDataIOFactory_txx + +#include "otbKMLVectorDataIOFactory.h" + +#include "itkCreateObjectFunction.h" +#include "itkVersion.h" +#include "otbKMLVectorDataIO.h" + +namespace otb +{ +template<class TData> +KMLVectorDataIOFactory<TData>::KMLVectorDataIOFactory() +{ + this->RegisterOverride("otbVectorDataIOBase", + "otbKMLVectorDataIO", + "SHP Vectordata IO", + 1, + itk::CreateObjectFunction<KMLVectorDataIO<TData> >::New()); +} +template<class TData> +KMLVectorDataIOFactory<TData>::~KMLVectorDataIOFactory() +{ +} +template<class TData> +const char* +KMLVectorDataIOFactory<TData>::GetITKSourceVersion(void) const +{ + return ITK_SOURCE_VERSION; +} +template<class TData> +const char* +KMLVectorDataIOFactory<TData>::GetDescription() const +{ + return "SHP VectorDataIO Factory, allows the loading of SHP vector data into OTB"; +} + +} // end namespace otb + +#endif diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index 3d37e379c0..9da6ca0647 100755 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -1412,6 +1412,9 @@ ADD_TEST(ioTvVectorDataFileReaderWriter ${IO_TESTS15} ${TEMP}/ioTvVectorDataFileReaderWriterOutput.shp ) +ADD_TEST(ioTuKMLVectorDataIO ${IO_TESTS15} + otbKMLVectorDataIONew ) + #---------------------------------------------------------------------------------- SET(BasicIO_SRCS1 @@ -1522,6 +1525,7 @@ otbVectorDataFileWriterNew.cxx otbVectorDataFileWriter.cxx otbVectorDataFileReaderWriter.cxx otbSHPVectorDataIONew.cxx +otbKMLVectorDataIONew.cxx ) @@ -1577,7 +1581,7 @@ ADD_EXECUTABLE(otbIOTests14 otbIOTests14.cxx ${BasicIO_SRCS14}) TARGET_LINK_LIBRARIES(otbIOTests14 OTBIO OTBCommon gdal ITKIO ITKCommon dxf) ADD_EXECUTABLE(otbIOTests15 otbIOTests15.cxx ${BasicIO_SRCS15}) -TARGET_LINK_LIBRARIES(otbIOTests15 OTBIO OTBCommon gdal ITKIO ITKCommon dxf) +TARGET_LINK_LIBRARIES(otbIOTests15 OTBIO OTBCommon gdal ITKIO ITKCommon dxf otbkml) ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING ) diff --git a/Testing/Code/IO/otbIOTests15.cxx b/Testing/Code/IO/otbIOTests15.cxx index a9424c1830..31a6c3ea1a 100755 --- a/Testing/Code/IO/otbIOTests15.cxx +++ b/Testing/Code/IO/otbIOTests15.cxx @@ -33,6 +33,7 @@ REGISTER_TEST(otbVectorDataFileReaderNew); REGISTER_TEST(otbVectorDataFileReader); REGISTER_TEST(otbVectorDataFileWriterNew); REGISTER_TEST(otbVectorDataFileWriter); - REGISTER_TEST(otbVectorDataFileReaderWriter); +REGISTER_TEST(otbVectorDataFileReaderWriter); REGISTER_TEST(otbSHPVectorDataIONew); +REGISTER_TEST(otbKMLVectorDataIONew); } diff --git a/Testing/Code/IO/otbKMLVectorDataIONew.cxx b/Testing/Code/IO/otbKMLVectorDataIONew.cxx new file mode 100644 index 0000000000..f9686b6187 --- /dev/null +++ b/Testing/Code/IO/otbKMLVectorDataIONew.cxx @@ -0,0 +1,29 @@ +/*========================================================================= + + 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 "otbKMLVectorDataIO.h" +#include "otbVectorData.h" + +int otbKMLVectorDataIONew(int argc, char * argv[]) +{ + typedef otb::VectorData<> VectorDataType; + typedef otb::KMLVectorDataIO<VectorDataType> KMLVectorDataIOType; + KMLVectorDataIOType::Pointer object = KMLVectorDataIOType::New(); + + return EXIT_SUCCESS; +} -- GitLab