พื้นฐานการปรับแต่ง Vector

Warning

This tutorial is now obsolete. A new and updated version is available at Basic Vector Styling (QGIS3)

ในการสร้างแผนที่นั้น การแสดงผลข้อมูล GIS ที่สื่อให้เห็นข้อมูลที่ชัดเจนนั้นเป็นสิ่งสำคัญ ใน QGIS มีตัวเลือกในการแสดงผลมากมายให้เลือกใช้ ในบทนี้เราจะมาลองใช้เครื่องมือเหล่านี้ในระดับพื้นฐานกัน

ภาพรวมของงาน

เราจะแสดงผลข้อมูล vector เพื่อดูข้อมูลสิ่งมีชีวติในแต่ละประเทศในโลก

สิ่งอื่นๆ ที่คุณจะได้เรียนรู้

  • สามารถดูตาราง attribute ของชั้นข้อมูลของ vector ได้

ข้อมูลที่ต้องใช้

ข้อมูลที่เราจะใช้มาจาก Center for Sustainability and the Global Environment (SAGE) University of Wisconsin-Madison

คุณสามารถดาวน์โหลดข้อมูล Life Expectancy GIS Grid data จากชุดข้อมูล human impact

เพื่อความสะดวก คุณสามารถดาวน์โหลดไฟล์ได้โดยตรงจากลิงค์ด้านล่างนี้

lifeexpectancy.zip

แหล่งข้อมูล [SAGE]

ขั้นตอนการทำงาน

  1. เปิดโปรแกรม QGIS แล้วไปที่เมนู Layer ‣ Add Vector Layer..

../_images/1158.png
  1. เลือกข้อมูล lifeexpectancy.zip ที่ได้โหลดมา จากนั้นคลิกที่ปุ่ม Open เลือกไฟล์ newsweek_data.shp และคลิกที่ปุ่ม Open ถัดมาคุณจะเห็นหน้าต่างให้คุณเลือก CRS ให้เลือก WGS84 EPSG:4326 เป็น ระบบอ้างอิงพิกัด (CRS).

../_images/2131.png
  1. shapefile ที่อยู่ในไฟล์ zip จะถูกโหลดเข้ามาและคุณจะเห็นว่าจะแสดงผลโดยใช้ default style

../_images/367.png
  1. คลิกขวาที่ชื่อของชั้นข้อมูลจากนั้นเลือก Open Attribute Table

../_images/437.png
  1. จะพบว่ามีข้อมูลหลากหลาย attribute การที่เราจะทำ style กับชั้นข้อมูล เราจะต้องเลือกที่ attribute หรือ column ที่มีข้อมูลที่จะใช้แสดงบนแผนที่ที่เราต้องการจะสร้าง ตอนนี้เราต้องการสร้างชั้นข้อมูลที่สื่อถึงการพยากรณ์การมีชีวิต เช่น อายุเฉลี่ยของแต่ละบุคคลในแต่ละประเทศ ในจุดนี้ คอลัมน์ LIFEXPCT จึงเป็น attribute ที่เราควรนำมาใช้

../_images/536.png
  1. ปิดหน้าต่างตางราง attribute คลิกขวาที่ชั้นข้อมูลอีกครั้งจากนั้นเลือก Properties

../_images/635.png
  1. จะเห็นได้ว่าที่แท็บ Style ในหน้าต่าง Properties จะมีตัวเลือกให้เราปรับแต่งมากมาย คลิกที่กล่องตัวเลือกดังรูป คุณจะเห็นว่ามีห้าตัวเลือกให้ใช้ ได้แก่ Single Symbol, Categorized, Graduated, Rule Based และ Point displacement เราจะลองใช้สามอันแรกดูในบทนี้

../_images/735.png
  1. Select Single Symbol. This option allows you to choose a single style that will be applied to all the features in the layer. Since this is a polygon dataset, you have two basic choices. You can fill the polygon, or you can style with only outline. You can choose the dotted pattern fill and click OK.

../_images/834.png
  1. คุณจะเห็นได้ว่ารูปแบบการแสดงผลข้อมูลได้เปลี่ยนเป็นแบบ pattern ตามที่คุณเลือก

../_images/935.png
  1. You will see that this Single Symbol style isn’t useful in communicating the life expectancy data we are trying to map. Let us explore another styling option. Right-click the layer again and choose Properties. This time choose Categorized from the Style tab. Categorized means the features in the layer will be shown in different shades of a color based on unique values in an attribute field. Choose LIFEXPCT value as the Column. Choose a color ramp of your choice and click Classify at the bottom. Click OK.

../_images/1042.png
  1. You will see different countries appearing in shades of blue. Lighter shades meaning lower life expectancy and darker shades meaning higher life expectancy. This representation of the data is more useful and clearly show how life expectancy in developed countries vs. developing countries. This would be the type of style we set out to create.

../_images/1159.png
  1. Let us explore the Graduated symbology type in the Style dialog now. Graduated symbology type allows you to break down the data in a column in unique classes and choose a different style for each of the classes. We can think of classifying our life expectancy data into 3 classes, LOW, MEDIUM and HIGH. Choose LIFEXPCT as the Column and choose 3 as the classes. You will see there are many Mode optionsa vailable. Let us see the logic behind each of these modes. There are 5 modes available. Equal Interval, Quantile, Natural Breaks (Jenks), Standard Deviation and Pretty Breaks. These modes use different statistical algorithms to break down the data into separate classes.

    • Equal Interval: As the name suggests, this method will will create classes which are at the same size. If our data ranges from 0-100 and we want 10 classes, this method would create a class from 0-10, 10-20, 20-30 and so on , keeping each class the same size of 10 units.

    • Quantile - This method will decide the classes such that number of values in each class are the same. If there are 100 values and we want 4 classes, quantile method will decide the classes such that each class will have 25 values.

    • Natural Breaks (Jenks) - This algorithm tries to find natural groupings of data to create classes. The resulting classes will be such that there will be maximum variance between individual classes and least variance within each class.

    • Standard Deviation - This method will calculate the mean of the data, and create classes based on standard deviation from the mean.

    • Pretty Breaks - This is based on the statistical package R’s pretty algorithm. It is a bit complex, but the pretty in the name means it creates class boundaries that are round numbers.

    To keep things simple, let’s use the Quantile method. Click Classify at the bottom and you will see 3 classes show up with their corresponding values. Click OK.

Note

For an attribute to be used in Graduated style, it must be a numeric field. Integer and Real values are fine, but if the attribute field type is String, it cannot be used with this styling option.

../_images/1245.png
  1. คุณจะเห็นแผนที่แสดงถึงประเทศแบ่งเป็น 3 สี ที่บ่งบอกถึงอายุเฉลี่ยของประชากรในแต่ละประเทศ

../_images/1343.png
  1. Now go back to the Style dialog by right clicking the layer and choosing Properties. There are some more styling options available. You can click on the Symbol for each of the classes and choose a different style. We will choose Red, Yellow and Green fill colors to indicate low, medium and high life expectancy.

../_images/1440.png
  1. ในหน้าต่าง Symbol Selector คลิกที่ตัวเลือก Color

../_images/1537.png
  1. คลิกเลือกสีจากหน้าต่าง Select Color

../_images/1635.png
  1. Back in the Layer Properties dialog, you can double-click on the Label column next to each value and enter the text that you want to display. Similarly, you may double-click on the Value column to edit the selected ranges. Click OK once you are satisfied with the classes.

../_images/1732.png
  1. This style definitely conveys a lot more useful map than the previous two attempts. There are clearly marked class names and colors to represent our interpretation of the life expectancy values.

../_images/1830.png

If you want to report any issues with this tutorial, please comment below. (requires GitHub account)