Lấy mẫu dữ liệu raster bằng điểm hoặc vùng - Points or Polygons¶
Cảnh báo
This tutorial is now obsolete. A new and updated version is available at Sampling Raster Data using Points or Polygons (QGIS3)
Có rất nhiều tập dữ liệu khoa học và môi trường ở định dạng các ô lưới raster. Dữ liệu độ cao (DEM) cũng có dạng raster. Trong các file raster này, một tham số đang được thể hiện cần nhập code là giá trị của từng pixel trong raster. Thông thường, người ta cần xuất giá trị pixel ở một địa điểm cụ thể hoặc gộp chúng vào theo từng khu vực. Chức năng này có trong QGIS với 2 plugin là Point Sampling Tool và``Zonal Statistics plugin``.
Tổng quan về nhiệm vụ¶
Với một lớp dữ liệu raster về nhiệt độ tối cao ở nước Mỹ, ta cần xuất các giá trị nhiệt độ tại tất cả các vùng đô thị và đồng thời tính toán nhiệt độ trung bình của từng hạt trong nước Mỹ.
Các kỹ năng bạn sẽ học được¶
Thay đổi lưới chiếu của dữ liệu vector.
Lựa chọn và bỏ nhiều lớp từ danh sách lớp trong QGIS - QGIS Table of Contents.
Nhận dữ liệu¶
NOAA’s Climate Prediction Center cung cấp dữ liệu GIS liên quan đến nhiệt độ và lượng mưa ở nước Mỹ. Tải xuống `file raster mới nhất về nhiệt độ tối cao <ftp://ftp.cpc.ncep.noaa.gov/GIS/GRADS_GIS/GeoTIFF/TEMP/us_tmax/>
We will use a CSV file from 2013 US Gazetteer representing urban areas in the US. Download the Urban Areas Gazetteer File.
As we want to aggregate temperature over counties, we will use 2013 TIGER/Line Shapefiles. Download the Counties (and equivalents) shapefile.
For convenience, you may directly download a copy of the datasets from the links below:
us.tmax_nohads_ll_20140525_float.tif
Nguồn dữ liệu: [NOAACPC], [USGAZETTEER] [TIGER]
Các bước thực hiện¶
Go to and browse to the downloaded
us.tmax_nohads_ll_{YYYYMMDD}_float.tiffile and click Open.
Once the layer is loaded, select the Identify tool and click anywhere on the layer. You will see the temperature value in celsius as the value or Band 1 at that location.
Now unzip the downloaded
2013_Gaz_ua_national.zipfile and extract the2013_Gaz_ua_national.txtfile on your disk. Go to .
In the Create a Layer from Delimited Text File dialog, click Browse and open
2013_Gaz_ua_national.txt. Choose Tab under Custom delimiters. The point coordinates are in Latitude and Longitude, so select INTPTLONG as X field and INTPTLAT as Y field. Check the Use spatial index box and click OK.
Now we are ready to extract the temperature values from the raster layer. Install the
Point Sampling Toolplugin. See Using Plugins for details on how to install plugins.
Open the plugin dialog from .
In the Point Sampling Tool dialog, select
2013_Gaz_ua_nationalas the Layer containing sampling points. We must explicitely pick the fields from the input layer that we want in the output layer. ChooseGEOIDandNAMEfields from the2013_Gaz_ua_nationallayer. We can sample values from multiple raster band at once, but since our raster has only 1 band, choose theus.tmax_nohads_ll_{YYYYMMDD}_float: Band 1. Name the output vector layer asmax_temparature_at_urban_locations.shp. Click the OK to start the sampling process. Click Close once the process finishes.
You will see a new layer
max_temparature_at_urban_locationsloaded in QGIS. Use the Identify tool to click on any point to see the attributes. You will see theus.tmax_nofield - which contains the raster pixel value at the location of the point.
First part of our analysis is over. Let's remove the unnecessary layers. Hold the Shift key and select
max_temparature_at_urban_locationsand2013_Gaz_ua_nationallayers. Right-click and select Remove to remove them from QGIS TOC.
Go to . Browse to the downloaded
tl_2013_us_county.zipfile and click Open. Select thetl_2013_us_county.shpas the layer and click OK.
The
tl_2013_us_countywill be added to QGIS. This layer is inEPSG:4269 NAD83projection. This doesn't match the projection of the raster layer. We will re-project this layer toEPSG:4326 WGS84projection.
Right-click the
tl_2013_us_countylayer and select Save As...
In the Save Vector layer as.. dialog, click Browse and name the output file as
counties.shp. Choose Selected CRS from the CRS dropdown menu. Click Browse and selectWGS 84as the CRS. Check the Add saved file to map and click OK.
Một lớp dữ liệu mới có tên
countiessẽ được nhập vào trong QGIS.
Enable the
Zonal Statistics Plugins. This is a core plugin so it is already installed. See Using Plugins to know to how enable core plugins.
Go to .
Select
us.tmax_nohads_ll_{YYYYMMDD}_floatas the Raster layer andcountiesas the Polygon layer containing the zones. EnterZS_as the Output column prefix. Click OK.
The analysis may take some time depending on the size of the dataset.
Once the processing finishes, select the
countieslayer. Use the Identify tool and click on any county polygon. You will see three new attributes added to the layer:ZS_count,ZS_meanandZS_sum. These attributes contain the count of raster pixels, mean of raster pixel values and sum of raster pixel values respectively. Since we are interested in average temperature, theZS_meanfield will be the one to use.
Let's style this layer to create a temperature map. Right-click the
countieslayer and select Properties.
Switch to the Style tab. Choose Graduated style and select
ZS_meanas the Column. Choose a Color Ramp and Mode of your chose. Click Classify to create the classes. Click OK. (See Trình bày vector cơ bản for more details on styling.)
You will see the county polygons styled using average maximum temperature extracted from the raster grid.
If you want to report any issues with this tutorial, please comment below. (requires GitHub account)