diff --git a/Code/Common/otbDataNode.h b/Code/Common/otbDataNode.h index 0818f94bae9f80eee7d92e072951c62644454890..41e277204a242ae191d1a2c5da959460820d7ae0 100644 --- a/Code/Common/otbDataNode.h +++ b/Code/Common/otbDataNode.h @@ -233,6 +233,8 @@ public: * \param key The name of the field. */ bool HasField(std::string key) const; + + /** * \return the nth field of the node as a std::pair of (key,value). * \param index the index of the field to return. @@ -242,6 +244,12 @@ public: * \return the number of fields in the node. */ // unsigned int GetNumberOfFields() const; + + /** + * \return the name of fields in the node. + */ + std::vector<string> GetFieldList() const; + /** * Clear all fields. */ diff --git a/Code/Common/otbDataNode.txx b/Code/Common/otbDataNode.txx index bb46fcf0f2c139cfea74b8ea6d768922be140663..e7c28384efecee71c8b54ef29e42740384951b9e 100644 --- a/Code/Common/otbDataNode.txx +++ b/Code/Common/otbDataNode.txx @@ -354,6 +354,8 @@ DataNode<TPrecision, VDimension, TValuePrecision> return false; } + + /* template <class TPrecision, unsigned int VDimension, class TValuePrecision> typename DataNode<TPrecision,VDimension,TValuePrecision> @@ -380,6 +382,25 @@ DataNode<TPrecision,VDimension,TValuePrecision> { return m_FieldMap.size(); } +*/ + +template <class TPrecision, unsigned int VDimension, class TValuePrecision> +std::vector<std::string> +DataNode<TPrecision, VDimension, TValuePrecision> +::GetFieldList() const +{ + VectorDataKeywordlist keywordlist; + if (this->GetMetaDataDictionary().HasKey(MetaDataKey::VectorDataKeywordlistKey)) + { + itk::ExposeMetaData<VectorDataKeywordlist>(this->GetMetaDataDictionary(), + MetaDataKey::VectorDataKeywordlistKey, keywordlist); + return keywordlist.GetFieldList(); + } + std::vector<std::string> empty; + return empty; +} + +/* template <class TPrecision, unsigned int VDimension, class TValuePrecision> void DataNode<TPrecision,VDimension,TValuePrecision> @@ -387,6 +408,9 @@ DataNode<TPrecision,VDimension,TValuePrecision> { m_FieldMap.clear(); }*/ + + + template <class TPrecision, unsigned int VDimension, class TValuePrecision> bool DataNode<TPrecision, VDimension, TValuePrecision> diff --git a/Code/IO/otbVectorDataKeywordlist.cxx b/Code/IO/otbVectorDataKeywordlist.cxx index c6fd90bcf463ab0065ba1a4e334b76e1c4c56c57..0f1ac4a7549207ee27360b1d7da484e72e68f606 100644 --- a/Code/IO/otbVectorDataKeywordlist.cxx +++ b/Code/IO/otbVectorDataKeywordlist.cxx @@ -166,6 +166,18 @@ VectorDataKeywordlist return m_FieldList.size(); } +std::vector<std::string> +VectorDataKeywordlist +::GetFieldList() const +{ + std::vector<std::string> res; + for (int i = 0; i < m_FieldList.size(); ++i) + { + res.push_back((m_FieldList[i].first)->GetNameRef()); + } + return res; +} + void VectorDataKeywordlist ::operator =(const Self& p) diff --git a/Code/IO/otbVectorDataKeywordlist.h b/Code/IO/otbVectorDataKeywordlist.h index 060a186057d41272c0d4f02af7a0ce87f5d1782b..8be523d627dc3d5f567ae0421260fcfc73452c45 100644 --- a/Code/IO/otbVectorDataKeywordlist.h +++ b/Code/IO/otbVectorDataKeywordlist.h @@ -88,6 +88,11 @@ public: */ unsigned int GetNumberOfFields() const; + /** + * \return the name of fields in the node. + */ + std::vector<std::string> GetFieldList() const; + /** * Print the keyword list */