Hello, all!
<br><br>I need to copy features to the empty shp file.
<br><br>The code is really simple:
<br><br> const char *pszDriverName = "ESRI Shapefile";
<br> OGRSFDriver *poDriver;
<br><br> OGRRegisterAll();
<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> OGRDataSource *poDS;
<br> poDS = OGRSFDriverRegistrar::Open( "C:\\ArcProjects\\Untamo\\Test\\test.shp", TRUE );
<br> if( poDS == NULL )
<br> {
<br> printf( "Open failed.\n" );
<br> exit( 1 );
<br> }
<br><br> OGRLayer *poLayer;
<br> poLayer = poDS->GetLayerByName( "test" );
<br><br><br> OGRDataSource *poDS1;
<br> poDS1 = OGRSFDriverRegistrar::Open( "C:\\ArcProjects\\Untamo\\Test\\arbukle0ot.shp", FALSE );
<br> if( poDS1 == NULL )
<br> {
<br> printf( "Open failed.\n" );
<br> exit( 1 );
<br> }
<br><br> OGRLayer *featuresLayer;
<br> featuresLayer = poDS1->GetLayerByName( "arbukle0ot" );
<br><br> OGRFeature *poFeature;
<br> featuresLayer->ResetReading();
<br> while( (poFeature = featuresLayer->GetNextFeature()) != NULL )
<br> {
<br><br> OGRFeature *newFeature;
<br><br> newFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
<br> newFeature->SetField( "ID", 1);
<br> newFeature->SetGeometry(poFeature->GetGeometryRef());
<br><br> if( poLayer->CreateFeature(newFeature ) != OGRERR_NONE )
<br> {
<br> printf( "Failed to create feature in shapefile.\n" );
<br> exit( 1 );
<br> }
<br>
<br> OGRFeature::DestroyFeature( newFeature );
<br> OGRFeature::DestroyFeature( poFeature );
<br> }
<br>
<br> OGRDataSource::DestroyDataSource( poDS );
<br> OGRDataSource::DestroyDataSource( poDS1 );
<br>}
<br><br>arbukle0ot.shp contains features,
<br>test is empty shp file, that is created with ArcCatalog.
<br><br>Now if you run this code, features will be copied, however the
extent of the shp file will be strange, as the MinX and MinY will be 0
and 0. (however it should not be, the extent of each feature differs
from zero)
<br><br>The most interesting thing, that if you will take this test.shp,
draw some features in ArcMap, check extent (it will be the right one),
than delete this features to make shp file again empty, and run the
code, the extent of the output file be the correct!
<br><br>I wonder, what is a problem?<br><br>emmiolla<br>