2

I'm working with the Python console of QGIS 3.16.6, trying to write a script that will quickly allow me to refactor a layer fields. I'm using the console because it's a process that I have to repeat several times on layers with the same fields and I need to refield them always in the same way. After defining the path for the input and utput layer, that's what I coded:

processing.run("native:refactorfields", {'INPUT': input, 'FIELDS_MAPPING': 

[{'expression':"ID_OGGETTO",
'length':17,
'name':"ID_OGGETTO_COMPARTO",  
'precision':0,
'type':10},

{'expression':"Comune",
'length':255, 
'name':"NOME_COMUNE",
'precision':0, 
'type':10},

{'expression':"Sezione",
'length':255, 
'name':"NOME_SEZIONE",
'precision':0, 
'type':10},

{'expression':"No_Fiscale",
'length':5, 
'name':"COMUNE_FISCALE",
'precision':0, 
'type':2},

{'expression':"No_Sezione",
'length':3, 
'name':"SEZIONE",
'precision':0, 
'type':2},

{'expression':"Numero_FON",
'length':255, 
'name':"NUMERO_FONDO",
'precision':0, 
'type':2},

{'expression': '\"SUPMQ_FON\"',
'length': 10,
'name': 'SUPERFICIE_MQ_FONDO',
'field_precision': 5,
'type': 6}], 
'OUTPUT': output})

The algorithm runs correctly, but if I analyze the output layer (.gpkg) fields, that's what I get:

fields after refactorization

As you can see, both length and precisions of the numbers (integers and reals) has been set to 0, while the code clearly explicits other values. Someone can explain me why this happens?

2
  • Your Question is missing a question.
    – Vince
    May 5 at 11:15
  • You're right. As you can see in the code, I've set values for length and precision that are not the ones I got in the results. I'll update the question.
    – MiroD
    May 5 at 11:56

1 Answer 1

5

GeoPackage only have a length limit for String an Blob as you can see in the OGC® Geo Package Encoding Standard's table of data types. Same thing for precision, Decimal numbers doesn't have any limit.

In QGIS when you add an attribute to a GeoPackage, the length is only required for a Text/String type attribute. Example below :

enter image description here

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.