[gdal-dev] OGR C API Help needed
Stephen Woodbridge
woodbri at swoodbridge.com
Fri Sep 17 19:42:50 EDT 2010
Hi all,
I am stumped by this. I am trying to copy a shapefile and append a new
attribute column to it. The loop below adds all the existing fields, but
the code following does not add the new field. I have been trying to
figure this out for hours and I assume it is something really stupid
that I am missing, but ...
I would appreciate a hint on this.
-Steve
/* this loop works fine and adds all the existing fields */
for( iField = 0; iField < OGR_FD_GetFieldCount(hFDefnIn); iField++ ) {
OGRFieldDefnH hFieldDefnIn = OGR_FD_GetFieldDefn( hFDefnIn, iField );
OGRFieldDefnH hFieldDefnOut = OGR_Fld_Create(
OGR_Fld_GetNameRef(hFieldDefnIn), OFTString );
OGR_Fld_SetType( hFieldDefnOut, OGR_Fld_GetType(hFieldDefnIn));
OGR_Fld_SetWidth( hFieldDefnOut, OGR_Fld_GetWidth(hFieldDefnIn));
OGR_Fld_SetPrecision( hFieldDefnOut,
OGR_Fld_GetPrecision(hFieldDefnIn));
if( OGR_L_CreateField( hLayerOut, hFieldDefnOut, TRUE ) !=
OGRERR_NONE ) {
printf( "Creating %s field failed.\n",
OGR_Fld_GetNameRef(hFieldDefnIn) );
exit(1);
}
OGR_Fld_Destroy(hFieldDefnOut);
}
/* I want to append a new field but it is not written to the
like the above fields are !!!!
*/
hFldElevUp = OGR_Fld_Create( "ELEV_UP", OFTString );
OGR_Fld_SetType( hFldElevUp, OFTReal );
OGR_Fld_SetWidth( hFldElevUp, 8);
OGR_Fld_SetPrecision( hFldElevUp, 1);
if( OGR_L_CreateField( hLayerOut, hFldElevUp, TRUE ) != OGRERR_NONE ) {
printf( "Creating ELEV_UP field failed.\n");
exit(1);
}
OGR_Fld_Destroy( hFldElevUp );
More information about the gdal-dev
mailing list