[gdal-dev] Add a new filed to an existing shapefile

Mateusz Loskot mateusz at loskot.net
Fri May 16 10:08:32 EDT 2008


On May 16, 2008, at 3:19 PM, Limei Ran wrote:
>  //create weight item to the attribute
>  OGRFieldDefn oField( itemName.c_str(), OFTReal);
>  printf ("\tBuiled field item: %s\n", itemName.c_str() );
>
>  if( poLayer->CreateField( &oField, TRUE ) != OGRERR_NONE )
>  {
>     printf( "\tFailed to create field: %s\n",itemName.c_str() );
>     exit( 1 );
>  }


Limei,

If you are trying to add field to a non-empty shapefile with features,  
then it won't work.

 From the OGR tutorial [1]:
"Fields must be added to the layer before any features are written."

[1] http://gdal.org/ogr/ogr_apitut.html

-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org






More information about the gdal-dev mailing list