Fundamental Seminar
Analyzing Spatial Data with QGIS
Azarel Chamorro Obra
Salsabila Panji Arum
福田研究室
基礎ゼミナール
27 of April, 20181

Outline● Processing GIS data
● Importing layers● Attributes operation● Setting CRS up● Filtering data

● Using plugins● Generating plots● Aggregating data

● Exporting data2

What is QGIS?
QGIS is a free geographic information system (GIS) software to view andanalyze geospatial data.
The type of data QGIS processes is geospatial/spatial data.
Spatial data is the data equipped with particular coordinate location.

東京工業大学 緑が丘１号館〒152-8552 Tōkyō-to, Meguro-ku, Ookayama, 2 Chome−12−1 M1 東京工業大学緑が丘１号館
35.608755, 139.678955(X,Y)

Source: www.arch.titech.ac.jp

coordinate location

Benefits:●See the context of location of our data in detail●Analyze the relationship between our data and the surrounding
environment3

Types of Data(1)

Vector Data

Point

Object is represented
by a point

(2)

Line

ex: railways, roads,river, etc.

Polygonex: buildings,
prefecture, country

Raster Data
Represents the world as surface divided byseveral grids of cells (rows and columns)
The smaller size of the cells we have, the higher
accuracy of the data
4

User interface
Toolbar

LayersToolbarWorkspace5

CoordinateCRSImporting Layers
Data from MLIT

Importing vector file in shapefile (.shp)
(1)
(2)
(3)
(4)

Layer → Add layer → Add Vector
Layer
Browse the .shp file (Railway.shp)
Set encoding to Shift_JIS for datawith Japanese characters
Click Open

Importing vector data from text file(.csv)
(1)
(2)
(3)
(4)
(5)

(6)
(7)

Layer → Add layer → Add
Delimited Text LayerBrowse the .csv file
(Stations.csv)
Set File Format to CSV
Choose the encoding (UTF-8)
Set Geometry Definition as
Point Coordinates
X field: x
Y field: yClick Open
Set CRS (CoordinateReference System) to WGS 84 6

Coordinate Reference System (CRS)●We can specify the coordinate for each layer to best represent their locationin the real world.

●Generally, data source will specify which CRS shall be used for each data(but we always have to double check). However, when there are nospecification in the CRS, it is best to choose WGS 84 since it is compatible
with most cases.

We can also change CRS
after loading it to theworksheet by:
Right click on theLayer -> Properties ->General -> Coordinate
Reference System7

Installing Plugin●

Plugin is a tool for conducting data analysis that is not available on the QGISinterface●

Plugin is similar to ‘package’ in R and Python●

Since QGIS is mostly based on graphical user interface (GUI), most of thetime, we do not have to use code.

Let’s install MMQGIS and OpenLayers
Plugins → Manage and Install Plugins → Type on the keyword → Select →Install Plugin
12Type keyword here

8OpenStreetMap
Web → OpenLayers plugin → OpenStreetMap → OpenStreetMap●OpenStreetMap may be added as a base layer in the working space.

●With OSM, we can visualize the location of our data better, since the map
represents real world with roads, buildings, green space, water area (similarto Google Maps)●

It is possible to download data from OSM such as the road network

NOTE:
It is better to put OSM layer inthe bottom of all layers
9MMQGIS - Creating a Mesh
Type of mesh

MMQGIS → Create → Create Grid Layer
Unit and Grid Size●(1)(2)(3)(4)(5)

MMQGIS is a useful tool to do
make mesh for aggregation. Thistime, we are going to make a meshgrid from aggregated ‘Stations’data.

Range of meshcreatedOutput file directory

Shape type: rectangle for meshSpecify unit: 0.01 and 0.01 in layer
unit
Extent: layer extent
Layer: Stations
Browse the directory of output file10

Data Aggregation
Now that we have the mesh and pointsof station, we can do a data aggregation
analysis. For this exercise, we are goingto aggregate the number of stations inevery mesh.
(1)
(2)

(3)
(4)
(5)

Vector → Analysis tools → countpoints in polygon
Set the polygon layer as the meshlayer we have,point layer to be counted as‘Stations’Name the count field as‘StatNum’
Browse the directory for output file
Click Run

Mesh layer

Points to be
countedField name to store
the result

Check this11

Data visualisation
(1)
(2)
(3)
(4)
(5)
(6)
(7)

Right click on our new mesh layer → Properties
Open Style
Change the single symbol to graduatedPick the column name as ‘StatNum’
In the Color Ramps,choose your favorite color!
Click on Classify
Click OK12Analysing Attributes
Right click on the layer → Select “Open Attribute Table”●

Most of spatial data are equipped with “attributes’’●

Spatial data sometimes comes with several other files. Attribute data is stored
in .csv or database files (access, SQL….)●

Each row of the attribute represents the information of ONE point/line/polygon(of vector data) or cell (of raster data) in the selected layer

Field name
Attribute file

Shapefile
Information of point #813

Attributes - Filtering
We can filter to select or remove attributes based on ourconditions.
Select the Railway layer.
●In this example, we want to remove the old railway data which operation
has been closed down.

●According to the data source, existing railway is denoted by ‘9999’.
Therefore, we only want the value of ‘9999’ in our data. This information iscontained in the ‘CLOSING’ field of ‘Railway’ data attribute.

14

Attributes - Filtering(1)

Open attribute table
See on top of the window about the information of unfiltered data

(2)

Click on the select/filter features using form

(3)

In the ‘CLOSING’, type 9999

(4)

Make sure the right option box is set to ‘Contains’(5)

On the bottom right, click ‘Filter feature’(6)

Again, on the bottom right, click ‘Apply’ on the filter expression(7)

Your data has been successfully filtered!

Switch to Table
Viewing
15

Attributes - Remove Unfiltered Data
(1)

Use select/filter features using form again in the attribute table(2)

In the ‘CLOSING’, type 9999

(3)

Make sure the right option box is set to ‘Contains’(4)

On the bottom right, click ‘SELECT feature’(5)

Switch to table view, and go back to QGIS Workspace(6)

Right click on the layer → save as…

(7)

Make sure the setting is right before clicking OK16

Attributes - Adding New Field
We can add more variable to the attributes, either with our own conditions orbased on another variable’s condition.
(1)

Open Attribute table of “Railway”(2)

Click on the Open field calculator(3)

Type the title of the new column on Output Field Name
We’ll write down if a line belongs to JR EAST

(4)

Specify the output field type as string and length as 10

(5)

Type:
if("COMPANY"='東日本旅客鉄道（旧国鉄）','JR East', '0')

(6)

Click OK

17

Attributes - Adding New Field

18

Automating QGIS●

Python scripts can be run
in QGIS●

Useful when working withlarge sets of data●

To open Python console:
Plugin→Python console●

For more information check
QGIS documentation

19

Printing out maps: print composer●

Plots are professional
visualisations of the maps●

Useful when printing out andshowing results●

Plots are generated through“print composer”:
Project → New Print Composer●You can add features such asmaps, legend, grid, etc●

ALWAYS draw the scale

20

Exporting maps to KML/KMZ●

Useful to send interactivelayers to third parties (eg.
client, reviewer)●GoogleEarth and Maps allows
people to see our GIS data●

Both software use .KML and.KMZ files●

To export a layer as .kml: “saveas” -> Format =”Keyhole
Markup Language”
21Summary●

Today we learnt○

Processing GIS data○

Importing layers○

Setting CRS up○

Using plugins○

Analysing and creating attributes○

Filtering data○Generating plots○Exporting data

For more information check:

22

FINAL EXERCISE●●Create a layer of the decommissioned Japanese rail network by
15 periods:• Before 1951 (Imaoka)• 1951-1955 (Hirabayashi)• 1956-1960 (Ihoroi)• 1961-1965 (Suzuki)• 1966-1970 (Shiroma)• 1971-1975 (Kaneko)• 1976-1980 (Ogawa)• 1981-1985 (Muro)• 1986-1990 (Kawai)• 1991-1995 (Kita)• 1996-1999 (Koizumi)• After 2000 (Koike)• Still in operation (Nagasaki)● Upload your layer to the GoogleMaps share folder:
https://drive.google.com/open?id=1vKSMpxqtDFE6vOWKzjQn-6QViSRohD6b&us
p=sharing23