diff --git a/Code/IO/otbSHPVectorDataIO.h b/Code/IO/otbSHPVectorDataIO.h index 3aee2d692e6e3dd1c9f26d5f6c1d065a72341876..42b55c9b298eb8fb4cc21bf3b129b72a117eab20 100644 --- a/Code/IO/otbSHPVectorDataIO.h +++ b/Code/IO/otbSHPVectorDataIO.h @@ -30,7 +30,7 @@ namespace otb /** \class SHPVectorDataIO * - * \brief ImageIO object for reading (not writing) SHP format vector data + * \brief ImageIO object for reading and writing SHP format vector data * */ template <class TData> class ITK_EXPORT SHPVectorDataIO @@ -76,8 +76,6 @@ public: typedef typename Superclass::SpacingType SpacingType; typedef typename Superclass::PointType OriginType; - /** */ - /*-------- This part of the interface deals with reading data. ------ */ @@ -103,7 +101,7 @@ public: * file specified. */ virtual bool CanWriteFile(const char*); - /** Determine the file type. Returns true if the ImageIO can stream write the specified file */ + /** Determine the file type. Returns true if the VectorDataIO can stream write the specified file */ virtual bool CanStreamWrite() { return false; @@ -113,8 +111,7 @@ public: /* * 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. */ + /** Writes the data to disk from the memory buffer provided */ virtual void Write(VectorDataConstPointerType data); protected: @@ -148,9 +145,9 @@ private: unsigned int m_Kept; - /** Is this necessary ? */ + /* Is this necessary ? */ - /** Internal method to read header informations */ + /* Internal method to read header informations */ /* bool InternalReadHeaderInformation(std::fstream & file, const bool reportError); */ /* bool m_FlagWriteVectorDataInformation; */ diff --git a/Code/IO/otbSHPVectorDataIO.txx b/Code/IO/otbSHPVectorDataIO.txx index e88b2f69e73cb712ba8ccf607f0ac5f4c3a335df..38b241724f148cf1c522481af32eea1b66077af6 100644 --- a/Code/IO/otbSHPVectorDataIO.txx +++ b/Code/IO/otbSHPVectorDataIO.txx @@ -36,12 +36,12 @@ namespace otb { template<class TData> SHPVectorDataIO<TData> -::SHPVectorDataIO() +::SHPVectorDataIO(): + m_DataSource(NULL), + m_Kept(0) { // OGR factory registration OGRRegisterAll(); - m_DataSource = NULL; - } template<class TData> @@ -57,8 +57,6 @@ template<class TData> bool SHPVectorDataIO<TData>::CanReadFile( const char* filename ) { - - OGRDataSource * poDS = OGRSFDriverRegistrar::Open(filename, FALSE); if (poDS == NULL) { @@ -556,6 +554,9 @@ SHPVectorDataIO<TData> }//end While feature otbMsgDevMacro(<<layer->GetFeatureCount()<<" features read, average insertion time "<<chrono.GetMeanTime()<<" s"); }// end For each layer + + OGRDataSource::DestroyDataSource(m_DataSource); + m_DataSource = NULL; } @@ -578,9 +579,13 @@ SHPVectorDataIO<TData> otbPoint[1] = static_cast<typename DataNodeType::PrecisionType>(ogrPoint->getY()); if (DataNodeType::Dimension > 2) + { + if (PointType::PointDimension != 3) { - otbPoint[2]=static_cast<typename DataNodeType::PrecisionType>(ogrPoint->getZ()); + itkGenericExceptionMacro(<<"OTB vector data can't contain the OGR information (2D instead of 2.5D)"); } + otbPoint[2]=static_cast<typename DataNodeType::PrecisionType>(ogrPoint->getZ()); + } DataNodePointerType node = DataNodeType::New(); node->SetPoint(otbPoint); @@ -615,9 +620,13 @@ SHPVectorDataIO<TData> vertex[1] = ogrTmpPoint->getY(); if (DataNodeType::Dimension > 2) + { + if (LineType::VertexType::PointDimension != 3) { - vertex[2]= ogrTmpPoint->getZ(); + itkGenericExceptionMacro(<<"OTB vector data can't contain the OGR information (2D instead of 2.5D)"); } + vertex[2]= ogrTmpPoint->getZ(); + } line->AddVertex(vertex); } @@ -657,6 +666,10 @@ SHPVectorDataIO<TData> if (DataNodeType::Dimension > 2) { + if (PolygonType::VertexType::PointDimension != 3) + { + itkGenericExceptionMacro(<<"OTB vector data can't contain the OGR information (2D instead of 2.5D)"); + } vertex[2]= ogrTmpPoint->getZ(); } @@ -678,6 +691,10 @@ SHPVectorDataIO<TData> vertex[1] = ogrTmpPoint->getY(); if (DataNodeType::Dimension > 2) { + if (PolygonType::VertexType::PointDimension != 3) + { + itkGenericExceptionMacro(<<"OTB vector data can't contain the OGR information (2D instead of 2.5D)"); + } vertex[2]= ogrTmpPoint->getZ(); } ring->AddVertex(vertex); @@ -787,39 +804,18 @@ void SHPVectorDataIO<TData>::Write(const VectorDataConstPointerType data) OGRGeometryCollection * ogrCollection = NULL; // OGRGeometry * ogrCurrentGeometry = NULL; -// TreeIteratorType it(tree); -// it.GoToBegin(); // Get the input tree root InternalTreeNodeType * inputRoot = const_cast<InternalTreeNodeType *>(tree->GetRoot()); ProcessNodeWrite(inputRoot, ogrCollection, ogrCurrentLayer, oSRS); - -// 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(); - OGRDataSource::DestroyDataSource( m_DataSource ); m_DataSource = NULL; + if (oSRS != NULL) + { + delete oSRS; + } + chrono.Stop(); std::cout<<"SHPVectorDataIO: file saved in "<<chrono.GetMeanTime()<<" seconds. (" << m_Kept << " elements)"<<std::endl; diff --git a/Code/IO/otbSHPVectorDataIOFactory.txx b/Code/IO/otbSHPVectorDataIOFactory.txx index 46a57387c511cda5e54af5b35e2e12b8af313fb6..3296392fa11b8bc7e053b5eb134250d4d7dabbf5 100644 --- a/Code/IO/otbSHPVectorDataIOFactory.txx +++ b/Code/IO/otbSHPVectorDataIOFactory.txx @@ -49,7 +49,7 @@ template<class TData> const char* SHPVectorDataIOFactory<TData>::GetDescription() const { - return "SHP VectorDataIO Factory, allows the loading of SHP vector data into OTB"; + return "SHP VectorDataIO Factory, allows the loading of ESRI shapefile vector data into OTB"; } } // end namespace otb diff --git a/Code/IO/otbVectorDataFileReader.h b/Code/IO/otbVectorDataFileReader.h index 4337903c1cdf721203bcc89be90738730baf0009..57b0b02bf2be92dd073b84ff15efba6bdf579a98 100644 --- a/Code/IO/otbVectorDataFileReader.h +++ b/Code/IO/otbVectorDataFileReader.h @@ -71,7 +71,7 @@ public: * appropriate suffix is enough to get the reader to instantiate the * correct VectorDataIO and read the file properly. However, some files (like * raw binary format) have no accepted suffix, so you will have to - * manually create the ImageIO instance of the write type. + * manually create the VectorDataIO instance of the write type. * * \sa VectorDataIOBase * diff --git a/Code/IO/otbVectorDataFileReader.txx b/Code/IO/otbVectorDataFileReader.txx index 47b72438f2b4ac564b143c85ced70e2273b1a291..ca29e5c25fd351996cda36f16924da0951596682 100644 --- a/Code/IO/otbVectorDataFileReader.txx +++ b/Code/IO/otbVectorDataFileReader.txx @@ -33,12 +33,13 @@ namespace otb */ template <class TOutputVectorData> VectorDataFileReader<TOutputVectorData> -::VectorDataFileReader() +::VectorDataFileReader() : + m_VectorDataIO(NULL), + m_UserSpecifiedVectorDataIO(false), + m_FileName("") { - m_VectorDataIO = 0; - m_FileName = ""; - m_UserSpecifiedVectorDataIO = false; } + /** * Destructor */ @@ -72,7 +73,9 @@ VectorDataFileReader<TOutputVectorData> } // Test if the file can be open for reading access. - //Only if m_FileName speciy a filname (not a dirname) + //Only if m_FileName speciy a filename (not a dirname) + // FIXME shapefile should be able to open a directory and load the + // individual shapefiles as layers if ( System::IsAFileName( this->m_FileName ) == true ) { std::ifstream readTester;