[gdal-dev] copy features to empty shp file: extent problem

Emmiolla Emmiolla emmiolla at gmail.com
Thu Jan 27 05:08:57 EST 2011


Hey, Peter!

Thank you for the hint.

Actually no much reason, i can remake my code to create a new shp file in
ogr.

Thank you!
emmiolla.

On Thu, Jan 27, 2011 at 11:16 AM, Peter J Halls <P.Halls at york.ac.uk> wrote:

> Emmiolla,
>
>   the problem is that OGR does not rewrite the extents when updating a
> dataset; it only calculates and writes the extents when creating a new
> dataset.  This is documented behaviour.  You are creating the dataset in
> ArcCatalog and then updating it with OGR, hence your problem.
>
>   Is there any reason why you cannot create the dataset from OGR?  I do
> this regularly and have never had problems with ArcGIS reading this output.
>  It would require a few extra lines of code to define the attribute data,
> but these are very straightforward.
>
> Best wishes,
>
> Peter
>
> Emmiolla Emmiolla wrote:
>
>> Hello, all!
>>
>> I need to copy features to the empty shp file.
>>
>> The code is really simple:
>>
>>    const char *pszDriverName = "ESRI Shapefile";
>>    OGRSFDriver *poDriver;
>>
>>    OGRRegisterAll();
>>
>>    poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(
>>                pszDriverName );
>>    if( poDriver == NULL )
>>    {
>>        printf( "%s driver not available.\n", pszDriverName );
>>        exit( 1 );
>>    }
>>
>>    OGRDataSource       *poDS;
>>    poDS = OGRSFDriverRegistrar::Open(
>> "C:\\ArcProjects\\Untamo\\Test\\test.shp", TRUE );
>>    if( poDS == NULL )
>>    {
>>        printf( "Open failed.\n" );
>>        exit( 1 );
>>    }
>>
>>        OGRLayer  *poLayer;
>>    poLayer = poDS->GetLayerByName( "test" );
>>
>>
>>        OGRDataSource       *poDS1;
>>    poDS1 = OGRSFDriverRegistrar::Open(
>> "C:\\ArcProjects\\Untamo\\Test\\arbukle0ot.shp", FALSE );
>>    if( poDS1 == NULL )
>>    {
>>        printf( "Open failed.\n" );
>>        exit( 1 );
>>    }
>>
>>        OGRLayer  *featuresLayer;
>>    featuresLayer = poDS1->GetLayerByName( "arbukle0ot" );
>>
>>    OGRFeature *poFeature;
>>    featuresLayer->ResetReading();
>>    while( (poFeature = featuresLayer->GetNextFeature()) != NULL )
>>    {
>>
>>        OGRFeature *newFeature;
>>
>>        newFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
>>        newFeature->SetField( "ID", 1);
>>                newFeature->SetGeometry(poFeature->GetGeometryRef());
>>
>>        if( poLayer->CreateFeature(newFeature ) != OGRERR_NONE )
>>        {
>>           printf( "Failed to create feature in shapefile.\n" );
>>           exit( 1 );
>>        }
>>
>>                 OGRFeature::DestroyFeature( newFeature );
>>         OGRFeature::DestroyFeature( poFeature );
>>    }
>>
>>        OGRDataSource::DestroyDataSource( poDS );
>>        OGRDataSource::DestroyDataSource( poDS1 );
>> }
>>
>> arbukle0ot.shp contains features,
>> test is empty shp file, that is created with ArcCatalog.
>>
>> 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)
>>
>> 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!
>>
>> I wonder, what is a problem?
>>
>> emmiolla
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
> --
>
> --------------------------------------------------------------------------------
> Peter J Halls, GIS Advisor & Acting Team Leader Applications Support Group,
>               Information Directorate, University of York
> Telephone: 01904 323806     Fax: 01904 323740
> Snail mail: C/O IT Services, University of York, Heslington, York YO10 5DD
> This message has the status of a private and personal communication
>
> --------------------------------------------------------------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110127/a264b513/attachment.html


More information about the gdal-dev mailing list