Skip to content
Snippets Groups Projects
Commit 7a6de62b authored by Luc Hermitte's avatar Luc Hermitte
Browse files

BUG: OTB-151/GeometriesProjectionFilter -- fields copy tricks to circumvent...

BUG: OTB-151/GeometriesProjectionFilter -- fields copy tricks to circumvent OGR drivers singularities
parent 6317041a
No related branches found
No related tags found
No related merge requests found
......@@ -188,3 +188,36 @@ std::vector<std::string> otb::GeometriesToGeometriesFilter::DoDefineNewLayerOpti
{
return std::vector<std::string>();
}
/*===========================================================================*/
/*========================[ FieldCopyTransformation ]========================*/
/*===========================================================================*/
void otb::FieldCopyTransformation::DefineFields(
otb::ogr::Layer const& source, otb::ogr::Layer & dest) const
{
OGRFeatureDefn & inDefinition = source.GetLayerDefn();
OGRFeatureDefn & outDefinition = dest.GetLayerDefn();
for (int i=0,N=inDefinition.GetFieldCount(); i!=N; ++i)
{
dest.CreateField(*inDefinition.GetFieldDefn(i));
// assume the definition is updated automatically
m_SourceToDestFieldIndicesMap[i] = outDefinition.GetFieldCount()-1;
}
}
void otb::FieldCopyTransformation::fieldsTransform(
otb::ogr::Feature const& inFeature, otb::ogr::Feature & outFeature) const
{
// default => copy all fields for copy transformation
// The following can't be assumed because of Drivers like KML that always add
// two fields: "Description" and "Name"
//assert(inFeature.GetSize() == outFeature.GetSize());
for (size_t i=0,N=inFeature.GetSize(); i!=N; ++i)
{
int const indexNewField = m_SourceToDestFieldIndicesMap[i];
outFeature[indexNewField].Assign(inFeature[i]);
}
}
......@@ -19,6 +19,7 @@
#define __otbGeometriesToGeometriesFilter_h
#include "otbGeometriesSource.h"
#include <map>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include "otbOGRFeatureWrapper.h"
......@@ -165,32 +166,28 @@ struct FieldCopyTransformation
*
* \throw itk::ExceptionObject if the fields cannot be copied.
*/
void fieldsTransform(ogr::Feature const& inFeature, ogr::Feature & outFeature) const
{
// default => copy all fields for copy transformation
//assert(inFeature.GetSize() == outFeature.GetSize());
for (size_t i=0,N=inFeature.GetSize(); i!=N; ++i)
{
outFeature[inFeature[i].GetName()].Assign(inFeature[i]);
}
}
void fieldsTransform(ogr::Feature const& inFeature, ogr::Feature & outFeature) const;
/**
* Defines the fields in the destination layer.
* The default action is to copy all fieds from one layer to another.
* \param[in] source source \c Layer
* \param[in,out] dest destination \c Layer
* \throw itk::ExceptionObject in case the operation can't succeed.
*/
void DefineFields(ogr::Layer const& source, ogr::Layer & dest) const
{
OGRFeatureDefn & inDefinition = source.GetLayerDefn();
for (int i=0,N=inDefinition.GetFieldCount(); i!=N; ++i)
{
dest.CreateField(*inDefinition.GetFieldDefn(i));
}
}
void DefineFields(ogr::Layer const& source, ogr::Layer & dest) const;
private:
/** Associative table to know how fields are mapped from one layer to another.
* This table is necesary as:
* - some data source drivers add their own fields (as a consequence, the
* number of fields differ between two layers).
* - other data source drivers truncate the name of the fields (as a
* consequence, we can't rely on field names).
* \todo \c std::map may not be the fastest structure available => use a
* (sorted?) vector of pairs of ints, and search with a simple \c std::find
* (as we can expect the number of fields to be quite low).
*/
mutable std::map<int,int> m_SourceToDestFieldIndicesMap;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment