<div class="gmail_extra">diegogb,<br><br>I too got a similar error, but with python code. I am working on a patch for this.<br><br><div class="gmail_quote">On Sat, Apr 28, 2012 at 10:46 PM, diegogb <span dir="ltr"><<a href="mailto:diego.gnesi@gmail.com" target="_blank">diego.gnesi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok, I executed many tests and I found something strange.<br>
I tried:<br>
<br>
- QT Creator,<br>
- CodeLite,<br>
- Python<br>
<br>
I wrote the following programs;<br>
<br>
// C++ CodeLite version.<br>
#include "gdal/ogrsf_frmts.h"<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
OGRRegisterAll();<br>
OGRSFDriver *driver =<br>
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("ESRI Shapefile");<br>
OGRDataSource *dSource =<br>
driver->CreateDataSource("/home/diego/Documenti/P2/test.shp", NULL);<br>
OGRLayer *layer = dSource->CreateLayer("TestLayer", NULL, wkbPoint,<br>
NULL);<br>
OGRFieldDefn elevField("Elev", OFTReal);<br>
layer->CreateField(&elevField);<br>
<div class="im"> OGRFeature *pointFeature =<br>
OGRFeature::CreateFeature(layer->GetLayerDefn());<br>
OGRPoint thePoint;<br>
</div> double x=1.1, y=1.2, z=1.3;<br>
thePoint.setX(x);<br>
thePoint.setY(y);<br>
thePoint.setZ(z);<br>
pointFeature->SetGeometry(&thePoint);<br>
pointFeature->SetField("Elev", z);<br>
layer->CreateFeature(pointFeature);<br>
OGRFeature::DestroyFeature(pointFeature);<br>
OGRDataSource::DestroyDataSource(dSource);<br>
return 0;<br>
}<br>
<br>
<br>
<br>
//C++ Qt Creator version.<br>
// (same code as above, but written as implementation of the class method<br>
AltConverter.createFile().<br>
#include "altconverter.h"<br>
#include "gdal/ogrsf_frmts.h"<br>
<br>
void AltConverter::createFile() {<br>
OGRRegisterAll();<br>
OGRSFDriver *driver =<br>
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("ESRI Shapefile");<br>
OGRDataSource *dSource =<br>
driver->CreateDataSource("/home/diego/Documenti/P2/test.shp", NULL);<br>
OGRLayer *layer = dSource->CreateLayer("TestLayer", NULL, wkbPoint,<br>
NULL);<br>
OGRFieldDefn elevField("Elev", OFTReal);<br>
layer->CreateField(&elevField);<br>
<div class="im"> OGRFeature *pointFeature =<br>
OGRFeature::CreateFeature(layer->GetLayerDefn());<br>
OGRPoint thePoint;<br>
</div> double x=1.1, y=1.2, z=1.3;<br>
thePoint.setX(x);<br>
thePoint.setY(y);<br>
thePoint.setZ(z);<br>
pointFeature->SetGeometry(&thePoint);<br>
pointFeature->SetField("Elev", z);<br>
layer->CreateFeature(pointFeature);<br>
OGRFeature::DestroyFeature(pointFeature);<br>
OGRDataSource::DestroyDataSource(dSource);<br>
}<br>
<br>
<br>
<br>
#! /usr/bin/python<br>
# Python version.<br>
import osgeo.ogr, osgeo.osr<br>
<br>
driver = osgeo.ogr.GetDriverByName('ESRI Shapefile')<br>
dSource = driver.CreateDataSource ('sample.shp')<br>
layer = dSource.CreateLayer('TestLayer', geom_type=osgeo.ogr.wkbPoint)<br>
fieldDefn = osgeo.ogr.FieldDefn('Elev', osgeo.ogr.OFTReal)<br>
layer.CreateField(fieldDefn)<br>
layerDefn = layer.GetLayerDefn()<br>
newPoint = osgeo.ogr.Geometry(osgeo.ogr.wkbPoint)<br>
newPoint.SetPoint(0, 1.1, 1.2)<br>
newFeature = osgeo.ogr.Feature(layer.GetLayerDefn())<br>
newFeature.SetGeometry(newPoint)<br>
newFeature.SetField('Elev', 1.3)<br>
layer.CreateFeature(newFeature)<br>
newFeature.Destroy()<br>
dSource.Destroy()<br>
<br>
<br>
*Now, Python and CodeLite code work fine, and produce the value 1.3 for the<br>
Elev field, Qt Creator code don't and the saved value is read as 1 (because<br>
is codified as "1,3" and not as "1.3")!!!*<br>
<br>
Now, I took a look inside the source code of the GDAL library.<br>
The method that writes real values to the dbf file is<br>
DBFWriteDoubleAttribute (inside the ogr/ogr_frmts/shape/dbfopen.c file).<br>
I think that there must be a sprintf that writes values using local settings<br>
while it shouldn't, but I don't know the library and I'm not able to check.<br>
I think it's a bug to correct.<br>
<br>
--<br>
View this message in context: <a href="http://osgeo-org.1560.n6.nabble.com/OFTReal-values-truncated-to-integer-tp4933952p4936894.html" target="_blank">http://osgeo-org.1560.n6.nabble.com/OFTReal-values-truncated-to-integer-tp4933952p4936894.html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the GDAL - Dev mailing list archive at Nabble.com.<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br><br>+91-9494447584<br>17.2416N 80.1426E<br>
</div>