<div>Dear all,</div>
<div>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:</div>
<div> </div>
<div>const char *DriverName = "ESRI Shapefile";<br>OGRSFDriver *Driver;</div>
<div>OGRRegisterAll();</div>
<div>Driver = OGRSFDriverRegistrar::GetRegistrar( )->GetDriverByName(DriverName);</div>
<div> </div>
<div>if(!Driver)<br>{<br> AfxMessageBox(_T("Driver Conf. failed"));<br> (CMyApp *) AfxGetMainWnd( )->PostMessage(WM_CLOSE);<br>}</div>
<div> </div>
<div>...</div>
<div> </div>
<div>OGRDataSource *outsource;</div>
<div>OGRLayer *outlayer; OGRFeature *outfeature;</div>
<div> </div>
<div>outsource=OGRSFDriverRegistrar::Open(chOutShapeFile, TRUE); /* char *chOutShapeFile */</div>
<div>outlayer=outsource->GetLayer(0); </div>
<div> </div>
<div>outfeature=outlayer->GetFeature(0);</div>
<div>...</div>
<div> </div>
<div>
<div>/* Create a field names production */</div></div>
<div> </div>
<div>OGRFieldDefn prfield("production", OFTReal);  /* Want to write decimal quantities */</div>
<div> </div>
<div>prfield.SetWidth(32);<br>if(outlayer->CreateField(&prfield)!=OGRERR_NONE)<br>{<br> AfxMessageBox(_T("Field named production could not be created"));<br> (CMyApp *) AfxGetMainWnd( )->PostMessage(WM_CLOSE);   <br>
}</div>
<div> </div>
<div>outfeature=outlayer->GetFeature(0);</div>
<div> while(outfeature)  // Get the first feature<br> {</div>
<div>  Prod=CalcProduction(...);</div>
<div>  outfeature->SetField("production", FALL->Production);<br>  outfeature=outlayer->GetNextFeature( );</div>
<div> }</div>
<div> </div>
<div>In the destructor: if(outsource) OGRDataSource::DestroyDataSource(outsource);</div>
<div> </div>
<div>My doubts are these:</div>
<div> </div>
<div>1. At the end I find no change in the shape file. What could have gone wrong?</div>
<div> </div>
<div>2. I tried to read attributes (for example, area/shape_area). All incorrect reads. How to tame the computer?</div>
<div> </div>
<div>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. </div>
<div> </div>
<div>With many thanks,</div>
<div> </div>
<div>Yours sincerely,</div>
<div>  B. Ramesh</div>