mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[OGR provider] Mark special Shape_Area/Shape_Length FileGDB fields as read-only
This commit is contained in:
parent
ded31e1b73
commit
40ed58bffe
@ -875,7 +875,16 @@ void QgsOgrProvider::loadFields()
|
||||
|
||||
// check if field has default value
|
||||
QString defaultValue = textEncoding()->toUnicode( OGR_Fld_GetDefault( fldDef ) );
|
||||
if ( !defaultValue.isEmpty() && !OGR_Fld_IsDefaultDriverSpecific( fldDef ) )
|
||||
if ( defaultValue == QLatin1String( "FILEGEODATABASE_SHAPE_LENGTH" ) ||
|
||||
defaultValue == QLatin1String( "FILEGEODATABASE_SHAPE_AREA" ) )
|
||||
{
|
||||
// FileGeodatabase may have special fields with autocomputed geometry
|
||||
// length and area. Their content is generated by the driver. The
|
||||
// user must not fill it (if they do, it will be overridden by the
|
||||
// driver)
|
||||
newField.setReadOnly( true );
|
||||
}
|
||||
else if ( !defaultValue.isEmpty() && !OGR_Fld_IsDefaultDriverSpecific( fldDef ) )
|
||||
{
|
||||
if ( defaultValue.startsWith( '\'' ) )
|
||||
{
|
||||
|
@ -3597,6 +3597,18 @@ class PyQgsOGRProvider(QgisTestCase):
|
||||
self.assertAlmostEqual(vl.extent3D().zMaximum(), 105.6, places=3)
|
||||
del vl
|
||||
|
||||
@unittest.skipIf(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(3, 6, 0), "GDAL 3.6 required")
|
||||
def testReadOnlyFieldsFileGeodatabase(self):
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
dest_file_name = os.path.join(temp_dir, 'testReadOnlyFieldsFileGeodatabase.gdb')
|
||||
ds = ogr.GetDriverByName("OpenFileGDB").CreateDataSource(dest_file_name)
|
||||
ds.CreateLayer("test", geom_type=ogr.wkbPolygon, options=["CREATE_SHAPE_AREA_AND_LENGTH_FIELDS=YES"])
|
||||
ds = None
|
||||
|
||||
vl = QgsVectorLayer(dest_file_name, 'vl')
|
||||
self.assertTrue(vl.fields()["Shape_Area"].isReadOnly())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user