Opened 6 years ago

Closed 4 years ago

#6730 closed enhancement (wontfix)

Setting field width and precision when generating GeoPackage files does not work properly

Reported by: rudigens Owned by: warmerdam
Priority: normal Milestone: closed_because_of_github_migration
Component: OGR_SF Version: 2.1.1
Severity: normal Keywords:


I am currently working on some Python code to generate GeoPackage files. The following code defines a very simple point file with ID, latitude and longitude fields.

ds = ogr.GetDriverByName('GPKG').CreateDataSource(gpkgFile)
layer = ds.CreateLayer('point', geom_type = ogr.wkbPoint, srs = srs)
field_ID = ogr.FieldDefn('ID', ogr.OFTString)
field_Lat = ogr.FieldDefn('Latitude', ogr.OFTReal)
field_Lon = ogr.FieldDefn('Longitude', ogr.OFTReal)

The issue is that the floating point fields don't show up with width and precision, when I use ogrinfo for the generated file.

Layer SRS WKT:
        SPHEROID["WGS 84",6378137,298.257223563,
FID Column = fid
Geometry Column = geom
ID: String (255.0)
Latitude: Real (0.0)
Longitude: Real (0.0)

The last two lines should both be 'Real (12, 5).

I have tested the code by saving the result as a shape file. That worked properly.

Change History (6)

comment:1 by Jukka Rahkonen, 6 years ago

By reading the GeoPackage standard I can't find any mention about setting width of precision for numbers. If you'll find something, please add a quotation into the description.

Generally SQLite does not really care about width and precision. Read for example However, it is possible to create a field so that it contains sort of a wish about what kind of numbers should be stored into it. It is still just a wish.

create table foo (test real(12,5));

I feel that this is not a bug, but I am not sure.

comment:2 by Even Rouault, 6 years ago

Component: PythonBindingsOGR_SF
Owner: changed from hobu to warmerdam

I agree with Jukka. Width and precision for numeric fields are not part of the GeoPackage standard. See Table 1 " GeoPackage Data Types" in Width is only for TEXT columns. Extending real to support width and precision isn't really a technical problem, but this would be an extension of the specification. And also worth to note that real field are internally stored as IEEE754 Float64 and not as decimal numbers.

comment:3 by rudigens, 6 years ago

My argument was not based on the GeoPackage standard. Strictly speaking it does not seem to be part of the standard, so I certainly see a reason not to consider this change. I am more looking for the equivalent of the shape file implementation.

The lack of defining the width and precision of floating point values gives a false sense for what the significant number actually is. For example, a latitude value should only have 4-5 decimals. You can't measure an angle more accurately than that. To me that makes a lot of sense. I don't think, in this context, it matters whether the values are actually stored as decimal numbers or not.

comment:4 by Jukka Rahkonen, 6 years ago

I agree that knowing the reasonable precision of the data is usable information. However, not all GIS formats support that natively. Shapefiles and Mapinfo files do, as well as PostGIS, Oracle and some others.

If you want to play with Geopackage or Spatialite you can edit the schema with some post-processing SQL but it may be that Geopackage is no standard compliant after such schema manipulation. Spatialite should not care, though. It may also be that you must use your own tools for interpreting the create table SQL from pragma. Please see this example:

Check the schema of an existing table 'foo' with SQL:
select sql from sqlite_master where name='foo'
CREATE TABLE foo (test real)

Set SQLite to allow fiddling with the schema
PRAGMA writable_schema=1;

Add precision to field 'test'
where name='foo';

Check the result
select sql from sqlite_master where name='foo';
CREATE TABLE foo (test real(12, 5))

Turn schema editing off
PRAGMA writable_schema=0;

Another possibility could be to save the precision model of the data into some metadata table. People reading gdal-dev mailing list may have experience and ideas about that.

Last edited 5 years ago by Even Rouault (previous) (diff)

comment:5 by Even Rouault, 6 years ago

Type: defectenhancement

comment:6 by Even Rouault, 4 years ago

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to if it is not already reported there.

Note: See TracTickets for help on using tickets.