[gdal-dev] OGR API for ESRI Shapefile writer

Chandra Shekhar Kumar chandra.kumar at flagstonere.bm
Mon Jun 29 13:54:45 EDT 2009


Hi All,

 

I was trying to create a shapefile using the code below:

It looks like though the fieldnames are getting created but the values
(I tried just one row) are not getting created:

 

OGRRegisterAll();

    OGRSFDriver *poDriver =
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("ESRI Shapefile");

 

    OGRDataSource *poDS = poDriver->CreateDataSource("point_out.shp",
0);

 

    OGRLayer *poLayer = poDS->CreateLayer("point_out", 0, wkbPoint, 0);

 

    OGRFieldDefn oField1("Longitude", OFTReal);

    OGRFieldDefn oField2("Latitude", OFTReal);

    OGRFieldDefn oField3("Speed", OFTReal);

 

    if(poLayer->CreateField(&oField1) != OGRERR_NONE)

    {

        std::cout << "creation of Longitude failed" << std::endl;

        exit(1);

    }

    if(poLayer->CreateField(&oField2) != OGRERR_NONE)

    {

        std::cout << "creation of Latitude failed" << std::endl;

        exit(1);

    }

    if(poLayer->CreateField(&oField3) != OGRERR_NONE)

    {

        std::cout << "creation of Speed failed" << std::endl;

        exit(1);

    }

 

        OGRFeature *poFeature = OGRFeature::CreateFeature(
poLayer->GetLayerDefn() );

        poFeature->SetField("Longitude", 1.1);

        poFeature->SetField("Latitude", 2.2);

        poFeature->SetField("Speed", 3.3);

 

        if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )

        {

           std::cout <<  "Failed to create feature in shapefile" <<
std::endl;

           exit( 1 );

        }

 

       OGRFeature::DestroyFeature( poFeature );

 

 

Am I missing something basic here ?

 

Thanks,

Chandra


**********************************************************************
This communication contains information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s), disclosure, copying, distribution, or other use of, or action taken or omitted to be taken in reliance upon, this communication or the information in it is prohibited and maybe unlawful. If you have received this communication in error please notify the sender by return email, delete it from your system and destroy any copies.
**********************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090629/aedce8b5/attachment.html


More information about the gdal-dev mailing list