<div dir="ltr">Hi, I'm having a strange problem that appears to be related to the GeoJSON driver in GDAL 1.11.0<div><br></div><div>When reading a polygon geometry in geographical lat/lon coordinates, all my coordinate values are returned in integer degrees. When using ogrinfo it dumps the coordinate values with correct decimals, so it must be something I have done wrong... Here is the relevant code:</div>
<div><br></div><div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">OGRDataSource</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">ds</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">OGRSFDriverRegistrar</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(0,0,0)">Open</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,0,0)">filename_</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(0,0,0)">c_str</span><span style="color:rgb(0,0,0)">(),</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">FALSE</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">num_layers</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ds</span><span style="color:rgb(0,0,0)">-></span><span style="font-style:italic;color:rgb(0,0,0)">GetLayerCount</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">for</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">num_layers</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">++)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">OGRLayer</span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">layer</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ds</span><span style="color:rgb(0,0,0)">-></span><span style="font-style:italic;color:rgb(0,0,0)">GetLayer</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">layer</span><span style="color:rgb(0,0,0)">-></span><span style="font-style:italic;color:rgb(0,0,0)">ResetReading</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">OGRFeature</span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">feature</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">while</span><span style="color:rgb(0,0,0)">((</span><span style="color:rgb(0,0,0)">feature</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">layer</span><span style="color:rgb(0,0,0)">-></span><span style="font-style:italic;color:rgb(0,0,0)">GetNextFeature</span><span style="color:rgb(0,0,0)">())</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">!=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">NULL</span><span style="color:rgb(0,0,0)">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">OGRGeometry</span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">geometry</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">feature</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">GetGeometryRef</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">if</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">geometry</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">==</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">NULL</span><span style="color:rgb(0,0,0)">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">continue</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">geom_type</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">wkbFlatten</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">geometry</span><span style="color:rgb(0,0,0)">-></span><span style="font-style:italic;color:rgb(0,0,0)">getGeometryType</span><span style="color:rgb(0,0,0)">());</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">if</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">geom_type</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">==</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">wkbPolygon</span><span style="color:rgb(0,0,0)">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">OGRPolygon</span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ogr_poly</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,0,128)">OGRPolygon</span><span style="color:rgb(0,0,0)">*)</span><span style="color:rgb(0,0,0)">geometry</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">OGRLinearRing</span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ext_ring</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ogr_poly</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">getExteriorRing</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">for</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">j</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">j</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ext_ring</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">getNumPoints</span><span style="color:rgb(0,0,0)">()</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">-</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">j</span><span style="color:rgb(0,0,0)">++)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">{</span><span style="color:rgb(192,192,192);font-family:arial"> </span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">double</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">x</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ext_ring</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">getX</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">j</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">double</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">y</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ext_ring</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">getY</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">j</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"> ...</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>Now, the x, and y values here are always truncated to integer values. This does not happen with for example shp files.</div><div><br></div><div>Any ideas what I might have done wrong here?</div>
</div>