<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">You need to do a CreateField() on your
      destination, something like: <br>
      <tt><br>
      </tt><tt>    poFDefn = poLayer->GetLayerDefn();</tt><tt><br>
      </tt><tt>    for( int iField = 0; iField <
        poFDefn->GetFieldCount(); iField++ )</tt><tt> </tt><tt>{</tt><tt><br>
      </tt><tt>        OGRFieldDefn *poFieldDefn =
        poFDefn->GetFieldDefn( iField );</tt><tt><br>
      </tt><tt><br>
      </tt><tt>        if( poDstLayer->CreateField( poFieldDefn ) !=
        OGRERR_NONE )</tt><tt> </tt><tt>{</tt><tt><br>
      </tt><tt>            printf( "Creation of field failed.\n" );</tt><tt><br>
      </tt><tt>        }</tt><tt><br>
      </tt><tt>    </tt>}<br>
      <br>
      <pre class="moz-signature" cols="72">Best Regards,
Brent Fraser</pre>
      On 12/4/2012 4:53 AM, SIVA RAMA KRISHNA wrote:<br>
    </div>
    <blockquote
cite="mid:CAP-zkzdgMU_Vapa3yCWxNAdRhL93VN2_LHtog4XuU4Bi1HQGLg@mail.gmail.com"
      type="cite">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>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/gdal-dev">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a></pre>
    </blockquote>
    <br>
  </body>
</html>