7.4. Lesson: 空間統計¶
注釈
LinfinitiとS Motala(ケープ半島工科大学)が開発したレッスン
空間統計によって、与えられたベクターデータセットで何が起こっているかを分析し理解できます。 QGISは、この点で有用であることが分かる統計分析のためのいくつかの標準的なツールが含まれています。
The goal for this lesson: To know how to use QGIS' spatial statistics tools within the Processing toolbox.
7.4.1. Follow Along: テストデータセットの作成¶
ポイントデータセットの操作を知るために、ポイントのランダムセットを作成します。
そのためには、ポイントを作成したいエリアの範囲を定義するポリゴンデータセットが必要です。
ストリートで覆われているエリアを使います。
Start a new project.
Add your roads layer, as well as the srtm_41_19 raster file (elevation data) found in
exercise_data/raster/SRTM/
.注釈
You might find that your SRTM DEM layer has a different CRS to that of the roads layer. QGIS is reprojecting both layers in a single CRS. For the following exercises this difference does not matter, but feel free to reproject a layer in another CRS as shown in this module.
Open Processing toolbox.
Use the
tool to generate an area enclosing all the roads by selectingConvex Hull
as the Geometry Type parameter:As you know, if you don't specify the output, Processing creates temporary layers. It is up to you to save the layers immediately or in a second moment.
7.4.1.1. ランダム点群の作成¶
Create random points in this area using the tool at
:注釈
The yellow warning sign is telling you that that parameter concerns something about the distance. The Bounding geometry layer is in a Geographical Coordinate System and the algorithm is just reminding you this. For this example we won't use this parameter so you can ignore it.
If needed, move the generated random point at the top of the legend to see them better:
7.4.1.2. データのサンプリング¶
To create a sample dataset from the raster, you'll need to use the Processing toolbox. This tool samples the raster at the points locations and copies the raster values in other field(s) depending on how many bands the raster is made of.
algorithm withinOpen the Sample raster values algorithm dialog
Select random_points as the layer containing sampling points, and the SRTM raster as the band to get values from. The default name of the new field is
rvalue_N
, whereN
is the number of the raster band. You can change the name of the prefix if you want:Press Run
Now you can check the sampled data from the raster file in the attributes table of the Random points layer, they will be in a new field with the name you have chosen.
サンプルレイヤーはここに示すとおりです:
The sample points are classified by their rvalue_1
field such that red
points are at a higher altitude.
残りの統計の練習ではこのサンプルレイヤーを使用します。
7.4.2. Follow Along: 基本統計¶
さて、このレイヤに対して基本統計を取得しましょう。
Click on the icon in the Attributes Toolbar of QGIS main dialog. A new panel will pop up.
In the dialog that appears, specify the Sampled Points layer as the source.
Select the rvalue_1 field in the field combo box which is the field you will calculate statistics for.
The Statistics Panel will be automatically updated with the calculated statistics:
Close the Statistics Panel when done.
Many different statistics are available, below some description:
- Count
サンプル/値の量です。
- 合計
すべての値を加算します。
- 平均
平均(平均)値は、単純な値の量で割った値の合計です。
- 中間値
最小から最大までのすべての値を整列させた場合、真ん中の値(またはNが偶数である場合は真ん中の2つの値の平均)は値の中央値です。
- St Dev (pop)
標準偏差。値が平均値の周りのどの程度近くに密集しているかの指標を与えます。標準偏差が小さいほど、値が平均値により近づく傾向があります。
- Minimum
値の最小値です。
- Maximum
値の最大値です。
- レンジ
最小および最大値間の差です。
- Q1
First quartile of the data.
- Q3
Third quartile of the data.
- Missing (null) values
Total count of values with missing data-
7.4.3. Follow Along: Compute statistics on distances between points using the Distance Matrix tool¶
Create a new point layer as a
Temporary layer
.Enter edit mode and digitize three points somewhere among the other points.
Alternatively, use the same random point generation method as before, but specify only three points.
Save your new layer as distance_points in the format you prefer.
To generate statistics on the distances between points in the two layers:
Open the tool
.Select the distance_points layer as the input layer, and the Sampled Points layer as the target layer.
このように設定します:
If you want you can save the output layer as a file or just run the algorithm and save the temporary output layer in a second moment.
Click Run to generate the distance matrix layer.
Open the attribute table of the generated layer: values refer to the distances between the distance_points features and their two nearest points in the Sampled Points layer:
With these parameters, the Distance Matrix
tool calculates distance
statistics for each point of the input layer with respect to the nearest points
of the target layer. The fields of the output layer contains the mean, standard
deviation, minimum and maximum for the distances to the nearest neighbors of the
points in the input layer.
7.4.4. Follow Along: Nearest Neighbor Analysis (within layer)¶
To do a nearest neighbor analysis of a point layer:
Click on the menu item
.In the dialog that appears, select the Random points layer and click Run.
The results will appear in the Processing Result Viewer Panel.
Click on the blue link to open the
html
page with the results:
7.4.5. Follow Along: 平均座標¶
データセットの平均座標を取得するために:
Click on the
menu item.In the dialog that appears, specify Random points as the input layer, but leave the optional choices unchanged.
Click Run.
ランダムなサンプルを作成するために使用されたポリゴンの座標の中央にこれを比較してみましょう。
Click on the
menu item.In the dialog that appears, select Bounding geometry as the input layer.
As you can see from the example below, the mean coordinates (pink point) and the center of the study area (in green) don't necessarily coincide.
The centroid is the barycenter of the layer (the barycenter of a square is the center of the square) while the mean coordinates represent the average of all node coordinates.
7.4.6. Follow Along: 画像ヒストグラム¶
The histogram of a dataset shows the distribution of its values. The simplest way to demonstrate this in QGIS is via the image histogram, available in the Layer Properties dialog of any image layer (raster dataset).
In your Layers panel, right-click on the srtm_41_19 layer.
を選択します。
ヒストグラム タブを選択します。 グラフィックを生成するには ヒストグラム計算 ボタンをクリックする必要があるかもしれません。画像内の値の度数を記述するグラフが表示されます。
それを画像として出力できます:
Select the Information tab, you can see more detailed information of the layer.
The mean value is 332.8
, and the maximum value is 1699
! But those
values don't show up on the histogram. Why not? It's because there are so few
of them, compared to the abundance of pixels with values below the mean. That's
also why the histogram extends so far to the right, even though there is no
visible red line marking the frequency of values higher than about 250
.
注釈
If the mean and maximum values are not the same as those of the example, it can be due to the min/max value calculation. Open the Symbology tab and expand the Min / Max Value Settings menu. Choose Min / max and click on Apply.
ですから、ヒストグラムは値の分布を示しており、すべての値がグラフに必ずしも表示されているではないことを覚えておいてください。
7.4.7. Follow Along: 空間的補間¶
Let's say you have a collection of sample points from which you would like to extrapolate data. For example, you might have access to the Sampled points dataset we created earlier, and would like to have some idea of what the terrain looks like.
To start, launch the Processing toolbox.
tool withinIn the Point layer parameter, select Sampled points
Set
5.0
as the Weighting powerIn the Advanced parameters set rvalue_1 for the Z value from field parameter
Finally click on Run and wait until the algorithm ends
Close the dialog
ここにあるのは元のデータセット(左)と私たちのサンプルポイントから構築されたもの(右)との比較です。サンプル点の位置にはランダム性があるため、実際に作成されたものは異なっている場合があります。
As you can see, 100 sample points aren't really enough to get a detailed impression of the terrain. It gives a very general idea, but it can be misleading as well.
7.4.8. Try Yourself Different interpolation methods¶
Use the processes shown above to create a new set of
10 000
random points.注釈
If the points amount is really big the processing time can take a long time.
オリジナルのDEMをサンプリングするためにこれらのポイントを使用してください。
Use the Grid (IDW with nearest neighbor searching) tool on this new dataset as above.
Set the Power and Smoothing to
5.0
and2.0
, respectively.
結果(ランダムな点の位置に応じて)多かれ少なかれ、このようになります。
This is a much better representation of the terrain, due to the much greater density of sample points. Remember, bigger samples give better results.
7.4.9. In Conclusion¶
QGISは、データセットの空間的な統計的性質を分析するための多くの可能性を可能にします。
7.4.10. What's Next?¶
これでベクター分析はカバーしましたが、ラスターで何ができるかは見ないのでしょうか。それは次のモジュールでやります!