[gdal-dev] GeoJSON coordinate values truncated to integers

Thomas Sevaldrud thomas at silentwings.no
Sat Jul 26 17:16:23 PDT 2014


Hi, I'm having a strange problem that appears to be related to the GeoJSON
driver in GDAL 1.11.0

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:

   OGRDataSource *ds = OGRSFDriverRegistrar::Open(filename_.c_str(), FALSE );


   int num_layers = ds->GetLayerCount();

   for(int i = 0; i < num_layers; i++)

   {

      OGRLayer* layer = ds->GetLayer(i);

      layer->ResetReading();


      OGRFeature* feature;

      while((feature = layer->GetNextFeature()) != NULL)

      {

         OGRGeometry* geometry = feature->GetGeometryRef();

         if(geometry == NULL)

            continue;


         int geom_type = wkbFlatten(geometry->getGeometryType());


         if(geom_type == wkbPolygon)

         {

            OGRPolygon* ogr_poly = (OGRPolygon*)geometry;

            OGRLinearRing* ext_ring = ogr_poly->getExteriorRing();


            for(int j = 0; j < ext_ring->getNumPoints() - 1; j++)

            {

               double x = ext_ring->getX(j);

               double y = ext_ring->getY(j);

               ...


Now, the x, and y values here are always truncated to integer values. This
does not happen with for example shp files.

Any ideas what I might have done wrong here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140727/a4ae5cd6/attachment.html>


More information about the gdal-dev mailing list