Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Temporary scratch layer made permanent is not editable. #38834

Closed
ValPinnaSardinia opened this issue Sep 17, 2020 · 13 comments · Fixed by #41075
Closed

Empty Temporary scratch layer made permanent is not editable. #38834

ValPinnaSardinia opened this issue Sep 17, 2020 · 13 comments · Fixed by #41075
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Vectors Related to general vector layer handling (not specific data formats)

Comments

@ValPinnaSardinia
Copy link
Contributor

ValPinnaSardinia commented Sep 17, 2020

Issue

After recording a weird behaviour with some layers, I have realised that when a new Temporary scratch layer is made permanent (as .shp) before adding to it any new feature or field, it becomes not editable.
The new layer does not accept new features or new fields. Also, trying to use the Field calculator to create a new field, it appears the message This layer does not support adding new provider fields. You can only add virtual fields.

Also removing and readding the layer to the project doesn't solve the problem.

How to Reproduce

  1. Create a new Temporary scratch layer (with any geometry type) without adding any field.
  2. Make it permanent as shapefile .shp clicking in the icon in the Layers Panel or using the voice in the menu.
  3. Toggle off the editing mode.
  4. Toggle on the editing mode.
  5. The Add Feature icon it will be not selectable.
  6. Open the Attribute Table: the add new Field icon is not selectable.
  7. Open the Field Calculator: it will appear the message This layer does not support adding new provider fields. You can only add virtual fields.

QGIS and OS versions

Tried on QGIS 3.10.10, 3.14.16 and dev 3.15 on Windows 8 and 10

@ValPinnaSardinia ValPinnaSardinia added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Sep 17, 2020
@gioman gioman added the Feedback Waiting on the submitter for answers label Sep 17, 2020
@gioman
Copy link
Contributor

gioman commented Sep 17, 2020

@ValPinnaSardinia Cannot confirm here, at least on Linux.

@pigreco
Copy link
Sponsor Contributor

pigreco commented Sep 17, 2020

I confirm

OSGeo4W64 WIn 10

@gioman
Copy link
Contributor

gioman commented Sep 17, 2020

@pigreco @ValPinnaSardinia works fine on Windows too here. Please try with a new QGIS profile.

@ValPinnaSardinia
Copy link
Contributor Author

I have tried with a new clean profile and I confirm that I have the same problem.

@gioman
Copy link
Contributor

gioman commented Sep 17, 2020

Ok, probably I'm doing it wrong, I will test again later.

@bellanz80
Copy link

I confirm

@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Sep 17, 2020

@gioman I can confirm also with 3.4 (GDAL/OGR 2.4.0) and 2.18 (GDAL/OGR 2.2.4) on Windows.

Minimal procedure:

  1. Create a new Temporary scratch layer (with any geometry type) without adding any field.
  2. Make it permanent as shapefile .shp clicking in the icon in the Layers Panel or using the voice in the menu.
  3. The Add Feature icon it will be not selectable.
  4. Open the Attribute Table: the add new Field icon is not selectable.
  5. Open the Field Calculator: it will appear the message This layer does not support adding new provider fields. You can only add virtual fields.

It seems that in QGIS it is not possible to add a geometry feature or a field to a shapefile without at least 1 field. So it's not editable de facto.

If the shapefile without at least 1 field contains geometries, then is possible to edit the feature geometries but not to add new feature geometries or fields.

Another way to generate a shapefile without at least 1 field is: create a shapefile with 1 field (it is not possible to create a shapefile without at least 1 field using the QGIS GUI) and then remove the field and remove and readd the shapefile.

In https://gdal.org/drivers/vector/shapefile.html it is stated that:
".dbf files are required to have at least one field. If none are created by the application an “FID” field will be automatically created and populated with the record number."

Anyway I think this is a bug. It should be possible to add fields to a shapefile without fields (or, at least, a warning should be displayed when a vector layer without fields is "made permanent" or saved to a shapefile" or when all the fields are deleted from a shapefile).

With ArcGIS/ArcMap 9 it is possible without problem to add features and fields to a shapefile without fields.

In the ESRI Shapefile Technical Description there are no constraints on the number of field in the dbf attribute table.

The problem should be in the ogr data provider and in the way it calculates the layer capabilities.

For a shapefile layer without at least 1 field the following capabilities are reported by the ogr data provider:
'Rename Attributes, Create Spatial Index, Create Attribute Indexes, Fast Access to Features at ID, Change Geometries'
so it lacks of the 'Add Attributes' capability.

@gioman
Copy link
Contributor

gioman commented Sep 17, 2020

The problem should be in the ogr data provider and in the way it calculates the layer capabilities.

@agiudiceandrea or ogr itself? from what you describe seems an upstream issue(?).

@agiudiceandrea
Copy link
Contributor

or ogr itself? from what you describe seems an upstream issue(?).

Using ogrinfo cli tool it is possible to add a field to a shapefile without fields.

@gioman gioman added Vectors Related to general vector layer handling (not specific data formats) and removed Feedback Waiting on the submitter for answers labels Sep 17, 2020
@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Sep 18, 2020

Confirmed also with QGIS 3.14 on Ubuntu Linux 18.04 (GDAL/OGR 2.2.3) and 20.04 (GDAL/OGR 3.0.4).

@elpaso elpaso self-assigned this Sep 18, 2020
@agiudiceandrea
Copy link
Contributor

It seems the relevant code is at

// OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
if ( mGDALDriverName == QLatin1String( "ESRI Shapefile" ) )
{
ability |= CreateSpatialIndex;
ability |= CreateAttributeIndex;
if ( mAttributeFields.size() == 0 )
{
QgsMessageLog::logMessage( tr( "Shapefiles without attribute are considered read-only." ), tr( "OGR" ) );
ability &= ~( AddFeatures | DeleteFeatures | ChangeAttributeValues | AddAttributes | DeleteAttributes );
}
if ( ( ability & ChangeAttributeValues ) == 0 )
{
// on readonly shapes OGR reports that it can delete features although it can't RandomWrite
ability &= ~( AddAttributes | DeleteFeatures );
}
}

The capability limitation for shapefiles w/o attributes was introduced a long long time ago: bf62b39
Probably the OGR driver is improved in the mean time...

@elpaso
Copy link
Contributor

elpaso commented Sep 18, 2020

@rouault is this a limitation of the GDAL/OGR library or can we fix it QGIS-side?

@agiudiceandrea
Copy link
Contributor

Hi @elpaso and @rouault, any news about this issue?

elpaso added a commit to elpaso/QGIS that referenced this issue Jan 19, 2021
nyalldawson pushed a commit that referenced this issue Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Vectors Related to general vector layer handling (not specific data formats)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants