<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">&lt;<a href="mailto:diego.gnesi@gmail.com" target="_blank">diego.gnesi@gmail.com</a>&gt;</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 &quot;gdal/ogrsf_frmts.h&quot;<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
    OGRRegisterAll();<br>
    OGRSFDriver *driver =<br>
OGRSFDriverRegistrar::GetRegistrar()-&gt;GetDriverByName(&quot;ESRI Shapefile&quot;);<br>
    OGRDataSource *dSource =<br>
driver-&gt;CreateDataSource(&quot;/home/diego/Documenti/P2/test.shp&quot;, NULL);<br>
    OGRLayer *layer = dSource-&gt;CreateLayer(&quot;TestLayer&quot;, NULL, wkbPoint,<br>
NULL);<br>
    OGRFieldDefn elevField(&quot;Elev&quot;, OFTReal);<br>
    layer-&gt;CreateField(&amp;elevField);<br>
<div class="im">    OGRFeature *pointFeature =<br>
OGRFeature::CreateFeature(layer-&gt;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-&gt;SetGeometry(&amp;thePoint);<br>
    pointFeature-&gt;SetField(&quot;Elev&quot;, z);<br>
    layer-&gt;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 &quot;altconverter.h&quot;<br>
#include &quot;gdal/ogrsf_frmts.h&quot;<br>
<br>
void AltConverter::createFile() {<br>
        OGRRegisterAll();<br>
        OGRSFDriver *driver =<br>
OGRSFDriverRegistrar::GetRegistrar()-&gt;GetDriverByName(&quot;ESRI Shapefile&quot;);<br>
        OGRDataSource *dSource =<br>
driver-&gt;CreateDataSource(&quot;/home/diego/Documenti/P2/test.shp&quot;, NULL);<br>
        OGRLayer *layer = dSource-&gt;CreateLayer(&quot;TestLayer&quot;, NULL, wkbPoint,<br>
NULL);<br>
        OGRFieldDefn elevField(&quot;Elev&quot;, OFTReal);<br>
        layer-&gt;CreateField(&amp;elevField);<br>
<div class="im">        OGRFeature *pointFeature =<br>
OGRFeature::CreateFeature(layer-&gt;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-&gt;SetGeometry(&amp;thePoint);<br>
        pointFeature-&gt;SetField(&quot;Elev&quot;, z);<br>
        layer-&gt;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(&#39;ESRI Shapefile&#39;)<br>
dSource = driver.CreateDataSource (&#39;sample.shp&#39;)<br>
layer = dSource.CreateLayer(&#39;TestLayer&#39;,  geom_type=osgeo.ogr.wkbPoint)<br>
fieldDefn = osgeo.ogr.FieldDefn(&#39;Elev&#39;,  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(&#39;Elev&#39;,  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&#39;t and the saved value is read as 1 (because<br>
is codified as &quot;1,3&quot; and not as &quot;1.3&quot;)!!!*<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&#39;t, but I don&#39;t know the library and I&#39;m not able to check.<br>
I think it&#39;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>