Skip to content
Snippets Groups Projects
Commit f8e7b1b6 authored by Thomas Feuvrier's avatar Thomas Feuvrier
Browse files

Ajout SHP VectorDataIO

parent 56fbfa26
Branches
Tags
No related merge requests found
/*=========================================================================
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 "otbSHPVectorDataIO.h"
#include <itksys/SystemTools.hxx>
#include "itkExceptionObject.h"
#include "itkByteSwapper.h"
#include "otbMacro.h"
#include "otbSystem.h"
namespace otb
{
SHPVectorDataIO::SHPVectorDataIO()
{
// By default set number of dimensions to two.
if ( itk::ByteSwapper<char>::SystemIsLittleEndian() == true)
{
m_ByteOrder = LittleEndian;
}
else
{
m_ByteOrder = BigEndian;
}
m_FileByteOrder = BigEndian;
}
SHPVectorDataIO::~SHPVectorDataIO()
{
if( m_File.is_open() )
{
m_File.close();
}
}
bool SHPVectorDataIO::CanReadFile( const char* filename )
{
std::string lFileName(filename);
if( System::IsADirName(lFileName) == true )
{
return false;
}
if( m_File.is_open() )
{
m_File.close();
}
std::fstream header_file;
header_file.open( filename, std::ios::in | std::ios::binary );
if( header_file.fail() )
{
otbMsgDevMacro(<<"SHPVectorDataIO::CanReadFile() failed header open ! " );
return false;
}
//Read header informations
bool lResult = InternalReadHeaderInformation(header_file,false);
header_file.close();
return (lResult);
}
// Used to print information about this object
void SHPVectorDataIO::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
// Read vector data
void SHPVectorDataIO::Read(VectorDataBase* buffer)
{
VectorDataBase * p = buffer;
}
void SHPVectorDataIO::ReadVectorDataInformation()
{
if( m_File.is_open() )
{
m_File.close();
}
m_File.open( m_FileName.c_str(), std::ios::in | std::ios::binary );
if( m_File.fail() )
{
itkExceptionMacro(<<"SHPVectorDataIO::ReadVectorDataInformation() failed header open ! " );
}
//Read header informations
InternalReadHeaderInformation(m_File,true);
otbMsgDebugMacro( <<"Driver to read: SHP");
otbMsgDebugMacro( <<" Read file : "<< m_FileName);
}
bool SHPVectorDataIO::InternalReadHeaderInformation(std::fstream & file, const bool reportError)
{
}
bool SHPVectorDataIO::CanWriteFile( const char* filename )
{
std::string lFileName(filename);
if( System::IsADirName(lFileName) == true )
{
return false;
}
const std::string Extension = System::GetExtension(filename);
if( (Extension == "shp") || (Extension == "SHP") )
{
return true;
}
else
{
return false;
}
}
void SHPVectorDataIO::Write(const VectorDataBase* buffer)
{
if( m_FlagWriteVectorDataInformation == true )
{
this->WriteVectorDataInformation();
m_FlagWriteVectorDataInformation = false;
}
otbMsgDevMacro( <<" SHPVectorDataIO::Write() ");
}
void SHPVectorDataIO::WriteVectorDataInformation()
{
if ( m_FileName == "" )
{
itkExceptionMacro(<<"A FileName must be specified.");
}
if( CanWriteFile(m_FileName.c_str()) == false)
{
itkExceptionMacro(<< "The file "<<m_FileName.c_str()<<" is not defined as a SHP file");
}
// Close file from any previous vector data
if ( m_File.is_open() )
{
m_File.close();
}
// Open the new file for writing
// Actually open the file
m_File.open( m_FileName.c_str(), std::ios::out | std::ios::trunc | std::ios::binary );
if( m_File.fail() )
{
itkExceptionMacro(<< "Cannot write requested file "<<m_FileName.c_str()<<".");
}
otbMsgDebugMacro( <<"Driver to write: SHP");
otbMsgDebugMacro( <<" Write file : "<< m_FileName);
}
} // end namespace otb
/*=========================================================================
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 __otbSHPVectorDataIO_h
#define __otbSHPVectorDataIO_h
#include "otbVectorDataIOBase.h"
#include <fstream>
#include <string>
#include <vector>
namespace otb
{
/** \class SHPVectorDataIO
*
* \brief ImageIO object for reading (not writing) SHP format vector data
*
*/
class ITK_EXPORT SHPVectorDataIO : public VectorDataIOBase
{
public:
/** Standard class typedefs. */
typedef SHPVectorDataIO Self;
typedef VectorDataIOBase Superclass;
typedef itk::SmartPointer<Self> Pointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(SHPVectorDataIO, VectorDataIOBase);
/** Byte order typedef */
typedef Superclass::ByteOrder ByteOrder;
/*-------- 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 true; };
/** 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(VectorDataBase* buffer);
/*-------- 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 true; };
/** 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(const VectorDataBase* buffer);
protected:
/** Construtor.*/
SHPVectorDataIO();
/** Destructor.*/
~SHPVectorDataIO();
void InternalReadVectorDataInformation();
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
SHPVectorDataIO(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/** Internal method to read header informations */
bool InternalReadHeaderInformation(std::fstream & file, const bool reportError);
bool m_FlagWriteVectorDataInformation;
VectorDataIOBase::ByteOrder m_FileByteOrder;
std::fstream m_File;
};
} // end namespace otb
#endif // __otbSHPVectorDataIO_h
/*=========================================================================
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 "otbSHPVectorDataIOFactory.h"
#include "itkCreateObjectFunction.h"
#include "itkVersion.h"
#include "otbSHPVectorDataIO.h"
namespace otb
{
SHPVectorDataIOFactory::SHPVectorDataIOFactory()
{
this->RegisterOverride("otbVectorDataIOBase",
"otbSHPVectorDataIO",
"SHP Vectordata IO",
1,
itk::CreateObjectFunction<SHPVectorDataIO>::New());
}
SHPVectorDataIOFactory::~SHPVectorDataIOFactory()
{
}
const char*
SHPVectorDataIOFactory::GetITKSourceVersion(void) const
{
return ITK_SOURCE_VERSION;
}
const char*
SHPVectorDataIOFactory::GetDescription() const
{
return "SHP VectorDataIO Factory, allows the loading of SHP vector data into OTB";
}
} // end namespace otb
/*=========================================================================
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 __otbSHPVectorDataIOFactory_h
#define __otbSHPVectorDataIOFactory_h
#include "itkObjectFactoryBase.h"
namespace otb
{
/** \class SHPVectorDataIOFactory
* \brief Creation d'un instance d'un objet VectorDataImageIO utilisant les object factory.
*/
class ITK_EXPORT SHPVectorDataIOFactory : public itk::ObjectFactoryBase
{
public:
/** Standard class typedefs. */
typedef SHPVectorDataIOFactory 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(SHPVectorDataIOFactory, itk::ObjectFactoryBase);
/** Register one factory of this type */
static void RegisterOneFactory(void)
{
SHPVectorDataIOFactory::Pointer SHPFactory = SHPVectorDataIOFactory::New();
itk::ObjectFactoryBase::RegisterFactory(SHPFactory);
}
protected:
SHPVectorDataIOFactory();
~SHPVectorDataIOFactory();
private:
SHPVectorDataIOFactory(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
} // end namespace otb
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment