-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Describe the bug
The Refactor Fields processing tool ignore’s the user’s selection of a field’s type, instead using the existing type for fields loaded from an existing layer, or always using String for new fields.
How to Reproduce
Sample geojson:
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"LineString","coordinates":[[102,0],[103,1],[104,0],[105,1]]},"properties":{"prop0":"value0","prop1":0}}]}
Can’t change the type of an existing field:
- Load a vector layer, such as the one above. If prompted to reset the field mapping, accept
- In the Processing toolbox, open the Refactor Fields tool
- Select the vector layer as the input
- Change the type of one of the fields
- Click Run
- Open the Properties of the new layer
- Select the Fields tab
- Note that the field type has not changed
The following can be found in the output log. On line 3, the type should be ’10’, as string was selected, but instead the type is ‘6’, showing that the user’s selection is not being used
{ 'FIELDS_MAPPING' : [
{'expression': '"prop0"', 'length': 0, 'name': 'prop0', 'precision': 0, 'type': 10},
{'expression': '"prop1"', 'length': 0, 'name': 'prop1', 'precision': 0, 'type': 6}
], 'INPUT' : 'sample.geojson', 'OUTPUT' : 'TEMPORARY_OUTPUT' }
Type of new field always defaults to String:
- Load a vector layer, such as the one above. If prompted to reset the field mapping, accept
- In the Processing toolbox, open the Refactor Fields tool
- Select the vector layer as the input
- Click the add field button.
- Add a source expression such as
prop1 + 4, and a field name such asprop2 - Select a type other than String, such as double, and a length and precision, such as 4 and 1
- Click Run
- Open the Properties of the new layer
- Select the Fields tab
- Note that the new field's type is String
The output log shows that the user’s selection for the new field’s type is not being used. Line 4 should have a type of 6, but instead has a type of 0:
{ 'FIELDS_MAPPING' : [
{'expression': '"prop0"', 'length': 0, 'name': 'prop0', 'precision': 0, 'type': 10},
{'expression': '"prop1"', 'length': 0, 'name': 'prop1', 'precision': 0, 'type': 6},
{'expression': 'prop1 + 4', 'length': 10, 'name': 'prop2', 'precision': 1, 'type': 0}
], 'INPUT' : '/Users/primaryuser/Downloads/sample.geojson', 'OUTPUT' : 'TEMPORARY_OUTPUT' }
These problems persist even when casting the source to the desired type within the source expression, with a function such as to_real(), and when saving the output to file formats such as geojson or geopackage.
QGIS and OS versions
QGIS Version 3.10 (also present in 3.8 and 3.4)
Only the default .dmg installers from qgis.org have been tested. (Have not tested the KyngChaos or osgeo4mac distributions)
macOS version 10.14 Mojave