Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Youssefi
otb
Commits
6624bb36
Commit
6624bb36
authored
14 years ago
by
Otmane Lahlou
Browse files
Options
Downloads
Patches
Plain Diff
ENH : take into account the kwl when writing shapefiles to add fields to feature
parent
e98f3fe5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/IO/otbOGRIOHelper.txx
+57
-14
57 additions, 14 deletions
Code/IO/otbOGRIOHelper.txx
with
57 additions
and
14 deletions
Code/IO/otbOGRIOHelper.txx
+
57
−
14
View file @
6624bb36
...
...
@@ -608,15 +608,33 @@ unsigned int OGRIOHelper<TVectorData>
//unsigned int m_Kept = 0;
// Get the children list from the input node
ChildrenListType children = source->GetChildrenList();
// std::cout << "Found " << children.size() << " children" << std::endl;
// For each child
for (typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it)
{
DataNodePointerType dataNode = (*it)->Get();
// std::cout << "Processing " << dataNode->GetNodeType() << " with Id: " << dataNode->GetNodeId() << std::endl;
otbGenericMsgDebugMacro(<< "Type of node " << dataNode->GetNodeType() << " id" << dataNode->GetNodeId());
++m_Kept;
// Get the kwl
otb::VectorDataKeywordlist kwl;
itk::ExposeMetaData<VectorDataKeywordlist>(dataNode->GetMetaDataDictionary(),
MetaDataKey::VectorDataKeywordlistKey,
kwl);
// Create the field once
if(ogrCurrentLayer != NULL && ogrCurrentLayer->GetFeatureCount() == 0)
{
// Take into account the fields stored in the
// vectordatakeywordlist
for(unsigned int fieldIdx = 0 ; fieldIdx < kwl.GetNumberOfFields(); fieldIdx++)
{
if( ogrCurrentLayer->CreateField(kwl.GetNthField(fieldIdx).first) != OGRERR_NONE )
{
exit( 1 );
}
}
}
switch (dataNode->GetNodeType())
{
case ROOT:
...
...
@@ -631,12 +649,13 @@ unsigned int OGRIOHelper<TVectorData>
//itkExceptionMacro(<<"Failed to create layer "<<dataNode->GetNodeId());
std::cout << "Failed to create layer " << dataNode->GetNodeId() << std::endl;
}
std::cout <<"DOCUMENT ogrCurrentLayer->GetFeatureCount() " <<ogrCurrentLayer->GetFeatureCount() << std::endl;
ProcessNodeWrite(*it, m_DataSource, ogrCollection, ogrCurrentLayer, oSRS);
break;
}
case FOLDER:
{
std::cout <<"FOLDER ogrCurrentLayer->GetFeatureCount() " <<ogrCurrentLayer->GetFeatureCount() << std::endl;
ProcessNodeWrite(*it, m_DataSource, ogrCollection, ogrCurrentLayer, oSRS);
break;
}
...
...
@@ -656,15 +675,24 @@ unsigned int OGRIOHelper<TVectorData>
if (ogrCollection == NULL)
{
OGRFeature *ogrFeature;
ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
// Add the fields to the features
for(unsigned int i = 0 ; i < kwl.GetNumberOfFields(); i++)
{
// Get the key of the Nth OGRFieldRefn
const char * key = kwl.GetNthField(i).first->GetNameRef();
// Edit the value of the field and add it to the current feature
ogrFeature->SetField(ogrFeature->GetFieldIndex(key) , kwl.GetFieldAsString(key).c_str());
}
ogrFeature->SetField("Name", dataNode->GetNodeId());
ogrFeature->SetGeometry(&ogrPoint);
if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
{
itkExceptionMacro(<< "Failed to create feature in shapefile.");
//
std::cout << "Failed to create feature in shapefile."
//
std::cout << "Failed to create feature in shapefile."
}
OGRFeature::DestroyFeature(ogrFeature);
...
...
@@ -701,8 +729,17 @@ unsigned int OGRIOHelper<TVectorData>
if (ogrCollection == NULL)
{
OGRFeature *ogrFeature;
ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
// Add the fields to the features
for(unsigned int i = 0 ; i < kwl.GetNumberOfFields(); i++)
{
// Get the key of the Nth OGRFieldRefn
const char * key = kwl.GetNthField(i).first->GetNameRef();
// Edit the value of the field and add it to the current feature
ogrFeature->SetField(ogrFeature->GetFieldIndex(key) , kwl.GetFieldAsString(key).c_str());
}
ogrFeature->SetField("Name", dataNode->GetNodeId());
ogrFeature->SetGeometry(&ogrLine);
...
...
@@ -775,20 +812,27 @@ unsigned int OGRIOHelper<TVectorData>
//Save it in the structure
if (ogrCollection == NULL)
{
{
OGRFeature *ogrFeature;
ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
ogrFeature->SetField("Name", dataNode->GetNodeId());
// Add the fields to the features
for(unsigned int i = 0 ; i < kwl.GetNumberOfFields(); i++)
{
// Get the key of the Nth OGRFieldRefn
const char * key = kwl.GetNthField(i).first->GetNameRef();
// Edit the value of the field and add it to the current feature
ogrFeature->SetField(ogrFeature->GetFieldIndex(key) , kwl.GetFieldAsString(key).c_str());
}
ogrFeature->SetGeometry(ogrPolygon);
if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
{
itkExceptionMacro(<< "Failed to create feature in shapefile.");
}
OGRFeature::DestroyFeature(ogrFeature);
}
else
{
...
...
@@ -799,7 +843,7 @@ unsigned int OGRIOHelper<TVectorData>
break;
}
case FEATURE_MULTIPOINT:
{
{
if (ogrCollection != NULL)
{
itkExceptionMacro(<< "Problem while creating multipoint.");
...
...
@@ -899,7 +943,6 @@ unsigned int OGRIOHelper<TVectorData>
return m_Kept;
}
} // end namespace otb
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment