본문 바로가기
English Guidance/QGIS Basics

[QGIS Basics] Refactor Fields - Changing the Field Type

by CaptainJ 2024. 4. 4.
반응형

Hello,

In this post, we'll explore how to change the field types within the attribute table of a layer.

 

 

A "field" refers to the group of values that appear when you open the attribute table of a vector layer in QGIS. Think of it as columns in Excel. QGIS software provides the functionality to change the type of each field to various types such as Text, Number, etc.

 

To illustrate this, let's load a CSV file containing the location and generating capacity of power plants in Vietnam. (For instructions on opening a CSV file, please refer to the previous post: https://qgis-jaehee.tistory.com/5?category=586300) 

 

 

Using Ctrl+L, open the CSV file in SHP format as follows:

Right-click > Properties > Symbology > Use the Graduated function to apply styles based on Design Capacity. (For details on changing symbol properties and setting legends, refer to the previous post: https://qgis-jaehee.tistory.com/6?category=586300)

 

 

Before changing the field types, let's open the attribute table to see the original structure.

 

 

 

Now, let's change the 'Design Capacity (MWe)' field, which consists of numbers, to a Text type.

 

 

Return to the QGIS main screen and follow these steps to execute the "Refactor fields" function:

Menu > Processing > Processing Tool Box > Refactor fields

 

 

Select the CSV file you loaded as the Input layer, then find the field "Design Capacity" in the Fields mapping section.

 

 

Once found, change the Type on the right side.

 

We'll change the current Decimal number (double) type to Text. Then click 'Run'.

 

 

 

 

Once the operation is complete, a new layer named "Refactored" will be added to the QGIS main layer panel.

Now let's apply the same properties to this file as the original.

 

Right-click on the layer > Properties > Symbology > Click Graduated, then search for 'Design Capacity' under Value.

 

 

However, if you find that 'Design Capacity' is missing in the Value dropdown, it's because we changed the field type to Text. Revert the field type back to Decimal number using the 'Refactor fields' function, and 'Design Capacity' will reappear in the Value tab.

 

In situations where you want to set legends and styles based on a specific field, but can't find the field you're looking for in the Symbology menu, using the Refactor fields function to check the field types can be helpful.

 

 

That concludes our explanation of how to use the Refactor fields function.

 

 

 

Thank you.

반응형

댓글