[gdal-dev] OGR writing problem pl. help

user gdal userofgdal at gmail.com
Wed Jun 11 06:23:41 PDT 2014


Dear all,
I have a shape file and programmatically I have to write to an attribute
named 'production'. I use Visual; C++ 2005. I proceeded like this:

const char *DriverName = "ESRI Shapefile";
OGRSFDriver *Driver;
OGRRegisterAll();
Driver = OGRSFDriverRegistrar::GetRegistrar( )->GetDriverByName(DriverName);

if(!Driver)
{
 AfxMessageBox(_T("Driver Conf. failed"));
 (CMyApp *) AfxGetMainWnd( )->PostMessage(WM_CLOSE);
}

...

OGRDataSource *outsource;
OGRLayer *outlayer; OGRFeature *outfeature;

outsource=OGRSFDriverRegistrar::Open(chOutShapeFile, TRUE); /* char
*chOutShapeFile */
outlayer=outsource->GetLayer(0);

outfeature=outlayer->GetFeature(0);
...

 /* Create a field names production */

OGRFieldDefn prfield("production", OFTReal);  /* Want to write decimal
quantities */

prfield.SetWidth(32);
if(outlayer->CreateField(&prfield)!=OGRERR_NONE)
{
 AfxMessageBox(_T("Field named production could not be created"));
 (CMyApp *) AfxGetMainWnd( )->PostMessage(WM_CLOSE);
}

outfeature=outlayer->GetFeature(0);
 while(outfeature)  // Get the first feature
 {
  Prod=CalcProduction(...);
  outfeature->SetField("production", FALL->Production);
  outfeature=outlayer->GetNextFeature( );
 }

In the destructor: if(outsource)
OGRDataSource::DestroyDataSource(outsource);

My doubts are these:

1. At the end I find no change in the shape file. What could have gone
wrong?

2. I tried to read attributes (for example, area/shape_area). All incorrect
reads. How to tame the computer?

3. The shape file  contains only a handfull of polygons (which I checked
with ARC GIS/ERDAS) but to my horror the  MFC/Visual C++  program says
there are > 1000 features.

With many thanks,

Yours sincerely,
  B. Ramesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140611/3efe1582/attachment.html>


More information about the gdal-dev mailing list