[gdal-dev] Recalculating spatial index with FileGDB driver

Jon Morris Jon.Morris at jbarisk.com
Wed Aug 25 07:29:27 PDT 2021


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.Morris at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/d9241347/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image733132.png
Type: image/png
Size: 9886 bytes
Desc: image733132.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/d9241347/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image909374.png
Type: image/png
Size: 651 bytes
Desc: image909374.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/d9241347/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image836014.png
Type: image/png
Size: 715 bytes
Desc: image836014.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/d9241347/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image407826.png
Type: image/png
Size: 966 bytes
Desc: image407826.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/d9241347/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image616029.png
Type: image/png
Size: 784 bytes
Desc: image616029.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/d9241347/attachment-0009.png>


More information about the gdal-dev mailing list