[gdal-dev] Recalculating spatial index with FileGDB driver
Jon Morris
Jon.Morris at jbarisk.com
Wed Aug 25 09:13:49 PDT 2021
Hi Even,
Thanks for looking into it. I suspected it might be something we have to live with, but thanks for confirming.
I can get round the problem by creating a dummy feature using the input layer extent then deleting it later, but it's an ugly workaround.
Weirdly, once you've hit the error, you can't then use CreateFeature to add a large feature, it also fails. You have to add the large feature before attempting the update.
Jon
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.
From: Even Rouault <even.rouault at spatialys.com>
Sent: 25 August 2021 16:13
To: Jon Morris <Jon.Morris at jbarisk.com>; gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] Recalculating spatial index with FileGDB driver
Jon,
I believe this is a bug/feature of the (closed source) FileGDB SDK itself when it . Not sure we can do much about that. Or according to some mysterious parts of the documentation of the SDK perhaps we could offer to the user, as layer creation options, the possibility to specify the values of the 3 grid sizes used to compute the spatial index instead of letting the SDK guess it, but I'm not sure if this is really possible and if users could reasonably infer such values. I've tried to modify the driver to not disable bulk-loading in SetFeature() as the SDK doc suggested this might be possible, but this resulted in another error.
Even
Le 25/08/2021 à 16:29, Jon Morris a écrit :
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<mailto:Jon.Morris at jbarisk.com>
t:
+44 (0)1756 799919<tel:+44%20(0)1756%20799919>
www.jbarisk.com<http://www.jbarisk.com/>
[cid:image001.png at 01D799D4.90C27AE0]
[Facebook]<https://www.facebook.com/TheFloodPeople>
[LinkedIn]<https://www.linkedin.com/company/jba-risk-management/>
[Twitter]<https://twitter.com/JBARisk>
[YouTube]<https://www.youtube.com/channel/UC0iatom2jYbW96voW0rlpCw>
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 at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
https://lists.osgeo.org/mailman/listinfo/gdal-dev
--
http://www.spatialys.com
My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 9886 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0010.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 651 bytes
Desc: image002.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0011.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 715 bytes
Desc: image003.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0012.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 966 bytes
Desc: image004.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0013.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 784 bytes
Desc: image005.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0014.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image707752.png
Type: image/png
Size: 9886 bytes
Desc: image707752.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0015.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image178087.png
Type: image/png
Size: 651 bytes
Desc: image178087.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0016.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image313640.png
Type: image/png
Size: 715 bytes
Desc: image313640.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0017.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image889875.png
Type: image/png
Size: 966 bytes
Desc: image889875.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0018.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image935680.png
Type: image/png
Size: 784 bytes
Desc: image935680.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210825/ea308be5/attachment-0019.png>
More information about the gdal-dev
mailing list