[gdal-dev] Forcing the rounded of coordinates

Even Rouault even.rouault at mines-paris.org
Wed Jun 22 03:56:39 EDT 2011


Le lundi 20 juin 2011 23:49:18, Sylvain Maffren a écrit :

This might be just a rounding effect that appears at display time when ogrinfo 
outputs the WKT representation, but not affect the output data itself. Likely 
993366.00000000058 and 993366 are 2 decimal representations for the same 
binary representation. There's no generation option to control the coordinate 
precision of the output in ogr2ogr. A few drivers/formats that are text-based 
have a layer/dataset creation option to control it, but this is driver/format 
dependant. You might want (or not!) to hack into the ugly logic of 
OGRFormatDouble() in ogr/ogrutils.cpp that is the main responsible for what 
you observe...

> Hi !
> 
> I apologize in advance for my english which I not very fluent. I have
> some questions about the tool ogr2ogr (and also about gdalwarp and
> gdal_translate) and the rounding of coordinates.
> 
> 
> Let me explain:
> 
> Some databases (particularly IGN -- France databases) have coordinates
> rounded to the meter (BD CARTO for example) or the decimeter (BD TOPO
> for example).
> 
> I will explain my comment with for bases the coordinates of a point of
> BD CARTO to support my comments :
> 
> In an original *.shp in Lambert93 - France, a point has the following
> coordinates (provided by ogrinfo):
> 
> X = 993366 m Y = 6304044 m
> 
> We import this in PostGIS with shp2pgsql, and the point has always these
> coordinates:
> 
> X = 993366 m Y = 6304044 m
> 
> It's good !
> 
> If we try to export this PostGIS layer through ogr2ogr (in *.shp, *.tab
> or *.mif), a ogrinfo gives us the same point of the layer resulting,
> with the following coordinates:
> 
> X = and Y = 993366.00000000058 6304043.9999999898)
> 
> This means that ogr2ogr (identical tests performed on a raster layer
> bounding box with reprojection (gdalwarp) or without (gdal_translate))
> changes the number of decimal coordinates of origin, which can be
> annoying in some cases (when we need to recover a given output with the
> same number of decimal than in entry.
> 
> I tried to find a setting to force ogr2ogr (or gdal and related
> functions) to round the coordinates to a given number of decimal (as can
> be done with CS2CS) and I have not found any answer.
> 
> Is it possible to set the number of decimal places in output (and
> ideally keep the same as input) ? And if so, how?
> 
> Thank you in advance to all who have good ideas and / or directions to
> follow.
> 
> 
> Sylvain Maffren


More information about the gdal-dev mailing list