Using the class & method reference for OGR Spatial Reference in combination with OGR tutorial, one should set a spatial reference and supply that (instead of NULL
) as argument upon layer creation:
OGRLayer *poLayer2;
OGRSpatialReference *spatialReference;
//spatialReference.SetWellKnownGeogCS( "WGS84" );
spatialReference.SetWellKnownGeogCS( "EPSG:4326" );
poLayer2 = poDS2->CreateLayer( "layerName", spatialReference, wkbPoint, NULL );
if( poLayer2 == NULL ) {
printf( "Layer creation failed PODS2.\n" );
exit( 1 );
}
When cloning a layer, one can copy the spatial reference directly from original layer:
OGRLayer *poLayer;
OGRLayer *poLayer2;
... get poLayer from shapefile (not scope of this answer)
poLayer2 = poDS2->CreateLayer( poLayer->GetName(), poLayer->GetSpatialRef(), wkbPoint, NULL );