diff --git a/Code/Common/otbDataNode.txx b/Code/Common/otbDataNode.txx index 86b41bff87633280f543455bca2472c4313168a7..bd21d74087f627785758fe7cf30305c321c1169c 100644 --- a/Code/Common/otbDataNode.txx +++ b/Code/Common/otbDataNode.txx @@ -227,11 +227,7 @@ DataNode<TPrecision,VDimension,TValuePrecision> { VectorDataKeywordlist kwl; itk::ExposeMetaData<VectorDataKeywordlist>(GetMetaDataDictionary(), MetaDataKey::VectorDataKeywordlistKey, kwl); - oss<< " -> Metadata: " << kwl; - } - else - { - oss<< " -> No metadata"; + oss<< "\n -> Metadata: " << kwl; } return oss.str(); } diff --git a/Code/IO/otbSHPVectorDataIO.txx b/Code/IO/otbSHPVectorDataIO.txx index 476980c99a99c1664481d9e4b5537fe8bfc1044e..b0a191ecc355e49b8b07c9a96789403405a19024 100644 --- a/Code/IO/otbSHPVectorDataIO.txx +++ b/Code/IO/otbSHPVectorDataIO.txx @@ -214,7 +214,7 @@ SHPVectorDataIO<TData> std::cout << "Inserting " << feature->GetFieldCount() << " fields." << std::endl; for (int fieldNum=0; fieldNum< feature->GetFieldCount(); ++fieldNum) { - kwl.AddField(feature->GetFieldDefnRef((fieldNum), feature->GetRawFieldRef((fieldNum)); + kwl.AddField(feature->GetFieldDefnRef(fieldNum), feature->GetRawFieldRef(fieldNum)); } diff --git a/Code/IO/otbVectorDataKeywordlist.cxx b/Code/IO/otbVectorDataKeywordlist.cxx index 411dca43185a70dbff6580164676712368276445..a597e7835bb24dad097cd1f6dcec5ca4b16b905f 100644 --- a/Code/IO/otbVectorDataKeywordlist.cxx +++ b/Code/IO/otbVectorDataKeywordlist.cxx @@ -33,14 +33,16 @@ VectorDataKeywordlist { for (unsigned int i = 0; i < m_FieldList.size(); ++i) { - delete(m_FieldList[i]); + delete(m_FieldList[i].first); } } void VectorDataKeywordlist:: - AddField(OGRFieldDefn* field) + AddField(OGRFieldDefn* fieldDefn, OGRField* field) { - OGRFieldDefn* newField = new OGRFieldDefn(field);//this ogr construction does a clone + FieldType newField; + newField.first = new OGRFieldDefn(fieldDefn); + newField.second = *field; m_FieldList.push_back(newField); }; @@ -50,7 +52,9 @@ VectorDataKeywordlist:: { for (unsigned int i = 0; i < p.m_FieldList.size(); ++i) { - OGRFieldDefn* newField = new OGRFieldDefn(p.m_FieldList[i]);//this ogr construction does a clone + FieldType newField; + newField.first = new OGRFieldDefn(p.m_FieldList[i].first); + newField.second = p.m_FieldList[i].second; m_FieldList.push_back(newField); } } @@ -66,15 +70,89 @@ void VectorDataKeywordlist:: PrintSelf(std::ostream& os, itk::Indent indent) const { - os << indent << " VectorData Keyword list:"<<std::endl; - os << indent << " - Size: " << m_FieldList.size() << std::endl; + os << indent << " VectorData Keyword list: "; + os << indent << " - Size: " << m_FieldList.size() << std::endl; for (unsigned int i = 0; i < m_FieldList.size(); ++i) { - os << indent << " " << m_FieldList[i]->GetNameRef (); - os << " : " << (*(m_FieldList[i]->GetDefaultRef())).Integer; + os << indent << " " << PrintField(m_FieldList[i]); } } +std::string +VectorDataKeywordlist:: + PrintField(FieldType field) const +{ + std::stringstream output; + output << field.first->GetNameRef() << " ("; + output << field.first->GetFieldTypeName(field.first->GetType()) << "): "; + switch(field.first->GetType()) + { + case OFTInteger: + { + output << field.second.Integer; + break; + } + case OFTIntegerList: + { + output << "Type not handled for printing"; + break; + } + case OFTReal: + { + output << field.second.Real; + break; + } + case OFTRealList: + { + output << "Type not handled for printing"; + break; + } + case OFTString: + { + output << field.second.String; + break; + } + case OFTStringList: + { + output << "Type not handled for printing"; + break; + } + case OFTWideString: + { + output << "Type not handled for printing"; + break; + } + case OFTWideStringList: + { + output << "Type not handled for printing"; + break; + } + case OFTBinary: + { + output << "Type not handled for printing"; + break; + } + case OFTDate: + { + output << field.second.Date.Year << field.second.Date.Month << field.second.Date.Day; + break; + } + case OFTTime: + { + output << field.second.Date.Hour << field.second.Date.Minute << field.second.Date.Second; + break; + } + case OFTDateTime: + { + output << field.second.Date.Year << field.second.Date.Month << field.second.Date.Day << "-" + << field.second.Date.Hour << field.second.Date.Minute << field.second.Date.Second; + break; + } + } + output << std::endl; + return output.str(); +} + std::ostream & operator<<(std::ostream &os, const VectorDataKeywordlist &kwl) { diff --git a/Code/IO/otbVectorDataKeywordlist.h b/Code/IO/otbVectorDataKeywordlist.h index aabb6ce7246cced58f5951418abba58c9467abff..123dfd602244b352ebbecf44190c514b3d942e89 100644 --- a/Code/IO/otbVectorDataKeywordlist.h +++ b/Code/IO/otbVectorDataKeywordlist.h @@ -46,11 +46,11 @@ class VectorDataKeywordlist // /** Run-time type information (and related methods). */ // itkTypeMacro(VectorDataKeywordlist, LightObject); + typedef std::pair<OGRFieldDefn*,OGRField> FieldType; + typedef std::vector< FieldType > FieldListType; - typedef std::vector<OGRFieldDefn*> FieldListType; - - void AddField(OGRFieldDefn* field); + void AddField(OGRFieldDefn* fieldDefn, OGRField* field); virtual void Print(std::ostream& os, itk::Indent indent=0) const; @@ -66,6 +66,7 @@ class VectorDataKeywordlist private: + std::string PrintField(FieldType field) const; FieldListType m_FieldList;