[gdal-dev] Clarification of OGR write tutorial code
Tim Keitt
tkeitt at gmail.com
Tue Aug 24 13:14:32 EDT 2010
I made my first foray into OGR today and want to be sure I understand
the following code from the tutorial.
In particular, I am wondering why the feature is created and destroyed
in each loop. Could one instead create a single feature object and
simply update its x and y values repeatedly? Clearly the feature
created in the layer does not reference poFeature, because it is
destroyed, right? Can the OGRFeature::CreateFeature and
OGRFeature::DestroyFeature calls be moved outside the loop?
Thanks.
THK
while( !feof(stdin)
&& fscanf( stdin, "%lf,%lf,%32s", &x, &y, szName ) == 3 )
{
OGRFeature *poFeature;
poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
poFeature->SetField( "Name", szName );
OGRPoint pt;
pt.setX( x );
pt.setY( y );
poFeature->SetGeometry( &pt );
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
{
printf( "Failed to create feature in shapefile.\n" );
exit( 1 );
}
OGRFeature::DestroyFeature( poFeature );
}
--
Timothy H. Keitt
http://www.keittlab.org/
More information about the gdal-dev
mailing list