Hello all,

I'm using GDAL 3.2.1 on Python 3.6.8 and am looking for more information on 
FileGDB spatial indexes. I have a File GDB layer containing some features and 
where the geometry is below a certain size, I'm trying to replace it with a 
larger geometry. However, I'm getting the error RuntimeError: Failed updating 
row  (The spatial index grid size is invalid.).

I found this ticket https://github.com/Toblerity/Fiona/issues/388 which 
suggests that the spatial index is being calculated using the first feature 
added to the layer, then when you add a much larger feature, it is not 
compatible. Is it possible to recalculate the index using OGR? All the results 
I have found suggest you need to use Esri tools to update the spatial index.

As a workaround, I can delete the layer and start again, or I can write a large 
dummy feature to the layer first, but I wondered if there was a better 
solution. There is a repro case below if anyone wants to see the issue.

    srs = osr.SpatialReference()
    srs.ImportFromEPSG(27700)
    drv = gdal.GetDriverByName('FileGDB')
    temp_name = f"/tmp/{uuid.uuid4()}.gdb"
    ds = drv.Create(temp_name, 0, 0, 0)
    lyr = ds.CreateLayer('lyr1', srs=srs, geom_type=ogr.wkbPolygon)
    ftr1 = ogr.Feature(lyr.GetLayerDefn())
    geom1 = ogr.CreateGeometryFromWkt('POLYGON ((0 10000,10 10000,10 10010,0 
10010,0 10000))')
    geom2 = ogr.CreateGeometryFromWkt('POLYGON ((-5000 7000,600000 7000,600000 
1200000,-5000 1200000,-5000 7000))')
    ftr1.SetGeometry(geom1)
    print(f'Add small feature (area = {geom1.Area()})')
    lyr.CreateFeature(ftr1)
    ftr1.SetGeometry(geom2)
    print(f'Update feature (area = {geom2.Area()})')
    lyr.SetFeature(ftr1)

If you add a feature with the larger geom before doing the update, it works 
fine. The error is only when you try and update the existing small feature.

Thanks,

Jon

Jon Morris
Software Developer



e: jon.mor...@jbarisk.com
t: +44 (0)1756 799919
www.jbarisk.com
All JBA Risk Management's email messages contain confidential information and 
are intended only for the individual(s) named. If you are not the named 
addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by email if you have received this email 
by mistake and delete this email from your system.
JBA Risk Management Limited is registered in England, company number 07732946, 
1 Broughton Park, Old Lane North, Broughton, Skipton, North Yorkshire, BD23 
3FD, England.
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to