To All,<br><br>I am using the following code for creating a shape file from another with the attributes value;<br>i am unable to fetch attribute values from source and change the features from newly created <br>shape files<br>
<br><br><br>Any Sort of help is greatly appriciated<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>#include "main.h"<br>#include<QList><br>#include<QStringList><br>#include<QDebug><br>
//OGRFeature* TranslateFeature(OGRFeature* poSrcFeature,OGRFeatureDefn *poFeatureDefn);<br>OGRLayer *poSrcLayer;<br>OGRLayer *poDstLayer;<br>OGRDataSource *poDS;<br>OGRDataSource *poODS=NULL;<br>
OGRFeature *poDstFeature;<br>OGRFeature *poSrcFeature;<br>OGRFeatureDefn *poFeatureDefn;<br><br>int main()<br>{<br><br> int iField;<br> const char *pszDriverName = "ESRI Shapefile";<br>
OGRSFDriver *poDriver;<br><br> OGRRegisterAll();<br> QList<double>fieldid;<br> QList<QString>fieldname;<br> const char* str="indiaaa" ;<br><br> poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(<br>
pszDriverName );<br> if( poDriver == NULL )<br> {<br> printf( "%s driver not available.\n", pszDriverName );<br> exit( 1 );<br> }<br><br> poDS = poDriver->Open( "/home/support/Images/IND_adm (3)/IND_adm1.shp" );<br>
poSrcLayer=poDS->GetLayerByName("IND_adm1");<br> poDriver->DeleteDataSource("firsts1.shp");<br> poODS = poDriver->CreateDataSource( "firsts1.shp", NULL );<br> poDstLayer = poODS->CreateLayer( "firsts1",NULL,wkbPolygon);<br>
poSrcLayer->ResetReading();<br> int i;<br> OGRGeometry *poGeometry;<br> // OGRGeometry *bufferGeometry;<br> poDstFeature = OGRFeature::CreateFeature(poDstLayer->GetLayerDefn());<br> poDstLayer->CreateFeature(poDstFeature);<br>
poSrcFeature=poSrcLayer->GetNextFeature();<br> do{<br> i=1;<br><br> OGRFeatureDefn *poFDefn = poSrcLayer->GetLayerDefn();<br> int iField;<br><br> for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )<br>
{<br> qDebug()<<"fieldcount"<<poFDefn->GetFieldCount();<br> printf("\n");<br> OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );<br>
<br> if( poFieldDefn->GetType() == OFTInteger )<br> {<br> printf( "%d,", poSrcFeature->GetFieldAsInteger( iField ) );<br><br><br> }<br>
else if( poFieldDefn->GetType() == OFTReal )<br> {<br> printf( "%.3f,", poSrcFeature->GetFieldAsDouble(iField) );<br> fieldid.append(poSrcFeature->GetFieldAsDouble( iField ));<br>
<br> }<br> else if( poFieldDefn->GetType() == OFTString )<br> {<br> printf( "%s, Name", poSrcFeature->GetFieldAsString(iField) );<br>
fieldname.append(poSrcFeature->GetFieldAsString(iField));<br><br> }<br> else<br> {<br> printf( "%s,name1", poSrcFeature->GetFieldAsString(iField) );<br>
fieldname.append(poSrcFeature->GetFieldAsString(iField));<br><br> }<br> }<br> poGeometry=poSrcFeature->GetGeometryRef();<br> poDstFeature->SetGeometryDirectly(poGeometry);<br>
poDstLayer->CreateFeature(poDstFeature);<br> poDstFeature->SetFID(100);<br>// poDstFeature->SetField(i,str); // this is not modifying <br>// i++;<br>
// //poDstFeature->SetFrom(poSrcFeature,true);<br><br><br> }while( (poSrcFeature = poSrcLayer->GetNextFeature()) != NULL );<br><br><br><br> poDstLayer->ResetReading();<br><br> qDebug()<<"size"<<fieldname.size();<br>
<br> OGRDataSource::DestroyDataSource(poODS);<br> }<br><br><br>