diff --git a/Code/Common/otbDataNode.h b/Code/Common/otbDataNode.h index ab72258d3b993e25c3bc0f14559a1d756e2a27ce..fbc78fd800d8e038b81df8743f9439fe7cb98a64 100644 --- a/Code/Common/otbDataNode.h +++ b/Code/Common/otbDataNode.h @@ -236,11 +236,11 @@ public: */ double GetFieldAsDouble(std::string key) const; - /** - * Remove the field associated with the given key, if possible. - * \param key The name of the field. - */ -// void RemoveField(std::string key); + // /** + // * Remove the field associated with the given key, if possible. + // * \param key The name of the field. + // */ + // void RemoveField(std::string key); /** * \return True if the node contains the field named after the given key. * \param key The name of the field. @@ -248,17 +248,13 @@ public: 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. + * Copy the field list from a DataNode + * \param datanode where to get the keywordlist to copy. */ -// FieldType GetNthField(unsigned int index) const; -/** - * \return the number of fields in the node. - */ -// unsigned int GetNumberOfFields() const; + void CopyFieldList(const DataNode * dataNode); /** - * \return the name of fields in the node. + * \return the field list in the node. */ std::vector<std::string> GetFieldList() const; diff --git a/Code/Common/otbDataNode.txx b/Code/Common/otbDataNode.txx index b4cd1f9ed1b9e369babd1691e19c23df35d5484c..963586d220b9160f30e290eb53749e1ae1556b07 100644 --- a/Code/Common/otbDataNode.txx +++ b/Code/Common/otbDataNode.txx @@ -266,9 +266,7 @@ DataNode<TPrecision, VDimension, TValuePrecision> itk::ExposeMetaData<VectorDataKeywordlist>(this->GetMetaDataDictionary(), MetaDataKey::VectorDataKeywordlistKey, kwl); - std::ostringstream os; - os << value; - kwl.SetFieldAsString(key, os.str()); //FIXME the int is currently saved as string in the OGR data + kwl.SetFieldAsInt(key, value); itk::EncapsulateMetaData<VectorDataKeywordlist>(this->GetMetaDataDictionary(), MetaDataKey::VectorDataKeywordlistKey, kwl); @@ -347,10 +345,8 @@ DataNode<TPrecision, VDimension, TValuePrecision> { itk::ExposeMetaData<VectorDataKeywordlist>(this->GetMetaDataDictionary(), MetaDataKey::VectorDataKeywordlistKey, keywordlist); - std::istringstream is(keywordlist.GetFieldAsString(key)); - int value; - is >> value; - return value; + + return keywordlist.GetFieldAsInt(key); } return 0; } @@ -415,6 +411,29 @@ DataNode<TPrecision, VDimension, TValuePrecision> } */ +template <class TPrecision, unsigned int VDimension, class TValuePrecision> +void +DataNode<TPrecision, VDimension, TValuePrecision> +::CopyFieldList(const DataNode * dataNode) +{ + // The source keywordlist where to get the feature list to copy + otb::VectorDataKeywordlist srcKwl; + itk::ExposeMetaData<VectorDataKeywordlist>(dataNode->GetMetaDataDictionary(), + MetaDataKey::VectorDataKeywordlistKey, + srcKwl); + + otb::VectorDataKeywordlist kwl; + itk::ExposeMetaData<VectorDataKeywordlist>(this->GetMetaDataDictionary(), + MetaDataKey::VectorDataKeywordlistKey, + kwl); + + kwl.CopyFieldList(srcKwl); + std::cout << " kwl "<< kwl << std::endl; + itk::EncapsulateMetaData<VectorDataKeywordlist>(this->GetMetaDataDictionary(), + MetaDataKey::VectorDataKeywordlistKey, + kwl); +} + template <class TPrecision, unsigned int VDimension, class TValuePrecision> std::vector<std::string> DataNode<TPrecision, VDimension, TValuePrecision>