I'm creating a shapefile with a field type of real, but I want to lower the standard precision from 15 decimal places to 10, here is my code:

dst_filename = "Polygonized.shp"
drv = ogr.GetDriverByName("ESRI Shapefile")
dst_ds = drv.CreateDataSource( dst_filename )      
dst_layer = dst_ds.CreateLayer("layer", geom_type=ogr.wkbPolygon )   

fd = ogr.FieldDefn( str(Polygonize_Field_Name), ogr.OFTReal )

dst_layer.CreateField( fd )                
gdal.FPolygonize( band,band1, dst_layer,0, [], callback=None )
dst_ds = None

(I'm also polygonizing, but that works fine.)

When I go to open up the file and return the precision using:

ds = ogr.Open("Polygonized.shp")
lyr = ds.GetLayer()
lyr_dfn = lyr.GetLayerDefn()
lyr_fld = lyr_dfn.GetFieldDefn(0)

It clearly returns a precision of 15.

Am I doing something wrong when specifying the precision?

  • Having the same issue. Did you ever resolve?
    – EnE_
    Aug 7, 2019 at 1:52
  • 1
    Unfortunately I never managed to resolve this, I believe it was due to how shapefiles work and the .DBF file not accepting varying precision.
    – Francis
    Aug 7, 2019 at 8:30


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.