Gis Practicals
Gis Practicals
Gis Practicals
Theory:
1) Create a folder on your D:/ drive on your computer called QGISlab by right clicking on
the D: drive and navigate down to the New / Folder.
2) Go to the QGIS download page and download the latest 64bit version of QGIS for
windows which is QGIS 3.4 'Madeira’ by clicking once.
3) If you have a 32 bit machine or using another operating system search the bottom of the
page for your operating system and download the correct operating system version of QGIS.
http://www.qgis.org/en/site/forusers/download.html
4) You browser will download the file to the browsers default download directory. By
pressing the control key and the letter J at the same time a popup window will show you the
folder where the QGIS file has been downloaded. The QGIS file will be called: QGIS-
OSGeo4W-3.4.2-1-Setup-x86.exe
5) Move or copy the above file to your C:/QGISlab folder and double click on the file. You
will get a popup window with a security warning.
6) Hit the run button to start the installation process and follow the prompts. There is no need
to install the data sets suggested by QGIS.
7) From the above window, click the Next button and continue with the installation.
8) Please go through the license agreement and click on the button> I agree and proceed with
the installation as shown in the screen.
9) As the software is very heavy it is advisable to install it in a different drive other than the
windows drive. As per our example, we will be installing in the QGIS folder on D:\ drive.
10) After browsing the folder click the Next button and proceed with the installation as
shown in above figure.
11) By default QGIS component is selected. Do not install any other data set at this point.
Click Install to proceed with installation.
12) You will see the progress of the installation on the screen.
13) Reboot your machine once the installation is completed. Click finish to complete the
installation.
14) After the machine is restarted, type QGIS on Run and open QGIS Desktop 3.4.2.
Understanding QGIS Desktop Environment. Quantum GIS interfaces change from one
project to another depending on the required interface of the project. Below are the basic
menus that you will encounter in Quantum GIS during the practicals.
1. Title of the Project - Shows the title of the project that you are going to view.
2. Menu Bar – This provides access to various Quantum GIS features using a standard
hierarchical menu.
3. Toolbars – These provide access to most of the same functions as the menus, plus
additional tools for interacting with the map. It shows the command for zoom in, zoom out,
pan, back to original view, go back to previous extent, go to next extent, object-information,
coordinate readout, measure, print and help.
4. Table of Contents/Map Legend (TOC) - Shows the layers that can be turned on or off and
the legend, attributes symbols and query symbols available for the corresponding project.
5. Display Window - Shows the feature/s that you have turned on from the TOC.
6. Status Bar - Shows you your current position in map coordinates (e.g. metres or decimal
degrees) as the mouse pointer is moved across the map view. To the left of the coordinate
display in the status bar is a small button that will toggle between showing coordinate
position or the view extents of the map view as you pan and zoom in and out.
7. Data sources browser – In previous versions, QGIS browser was only provided as an
external application which enables us to explore our spatial data sets. In QGIS 2.0.1-Dufour
this application is also integrated in the QGIS framework as an additional panel just below
the Table of Contents.
OUTPUT:
RESULT: Hence we studied how to install QGIS.
PRACTICAL NO.2
Aim: Creating and Managing Vector Data: Adding vector layer .(Point , Line , Polygon)
Theory:
A) Creating Polygon vector layer. Polygon features are enclosed areas like dams, islands,
country boundaries and so on. Like line features, polygons are created from a series of
vertices that are connected with a continuous line. However because a polygon always
describes an enclosed area, the first and last vertices should always be at the same place!
Polygons often have shared geometry –– boundaries that are in common with a neighbouring
polygon. Many GIS applications have the capability to ensure that the boundaries of
neighbouring polygons exactly coincide.
Select Project -> New Select Layer -> Create Layer ->New Shapefile Layer Following dialog
box will appear on the screen. Select Polygon option from Geometry type. Fill the
appropriate information in each text box.
File name :
Field Panel : Add the Attribute you want to show. (Column Name for Table)
B) Creating Line vector layer: Where a point feature is a single vertex, a line has two or
more vertices. The line is a continuous path drawn through each vertex. When two vertices
are joined, a line is created. When more than two are joined, they form a ‘line of lines’, or
line. A line is used to show the geometry of linear features such as roads, rivers, contours,
footpaths, flight paths and so on. Sometimes we have special rules for lines in addition to
their basic geometry. For example contour lines may touch (e.g. at a cliff face) but should
never cross over each other. Similarly, lines used to store a road network should be connected
at intersections. In some GIS applications you can set these special rules for a feature type
(e.g. roads) and the GIS will ensure that these lines always comply to these rules. If a curved
line has very large distances between vertices, it may appear angular or jagged, depending on
the scale at which it is viewed
C. Create Point vector layer: The first thing we need to realise when talking about point
features is that what we describe as a point in GIS is a matter of opinion, and often dependent
on scale. let’s look at cities for example. If you have a small scale map (which covers a large
area), it may make sense to represent a city using a point feature. However as you zoom in to
the map, moving towards a larger scale, it makes more sense to show the city limits as a
polygon. When you choose to use points to represent a feature is mostly a matter of scale
(how far away are you from the feature), convenience (it takes less time and effort to create
point features than polygon features), and the type of feature .
OUTPUT:
RESULT: Hence we studied Creating and Managing Vector Data: Adding vector layer
.(Point , Line , Polygon)
PRACTICAL NO.3
Theory:
Labels can be added to a map to show any information about an object. Any vector layer can
have labels associated with it. Labels rely on the attribute data of a layer for their
content.Labels are for providing more information about the object. This layer property
depends on the attributes of the layer. So, lets start
By right click the layer >> Properties>> label (icon shown below) Or Go to layer menu,
select labeling. Above map is not looking so attractive and informative.
OUTPUT:
Result: Hence we studied how to Labeling Layers in QGIS.
PRACTICAL NO.4
Aim: To calculate Line length and statistics.
Theory:
1. Go to Layer--->ADD Layer --->Add Vector Layer
2. Add the following file to Project.
3. “GIS_Workshop\Practicals\Practical_01\D\Data\IND_rrd\IND_rails.shp”
4. Press “ADD”.
5. Also add India Administrative Map
6. “GIS_Workshop\Practicals\Practical_01\D\Data\IND_adm\IND_adm0.shp”
7. Double click on IND_adm0
8. Select Symbology--->select any style from below options.
9. Press_ok
10. The display window will appear..
11. In Layer Pane Right click inIND_rails --->open Attribute Table.
12. Press TOggle Editing Button on Attribute table window toolbar
13. Press Open field Calculator
14. Set the output field as :”Track_Len”, field type to “Decimal Number” .
15. From Function List search $length or go to Geometry ---->select $Length
16. Set Expression as Press ok..
17. A new column is added to the attribute table with value representing the length
of track of track in KM.
18. Press CTRL+S or click on Save Edits option on tool bar
19. Close the Attribute table window .
20. Foe calculating the Total Length of Railways tracks in INDIA.
21. Select Vector ---->Analysis Tools --->Basic Statics for fields
22. Press RUN
OUTPUT:
RESULT: hence we studied how to calculate Line length and statistics.
PRACTICAL NO.5
Theory:
1) From menu bar select Layer → Add Layer → Add Raster Layer
2) Select Gridded Population of the World (GPW) v3 dataset from Columbia
University, Population Density Grid for the entire globe in ASCII format and for the
year 1990 and 2000. 3) “\GIS_Workshop\gl_gpwv3_pdens_90_ascii_one\gld s90
ag60.asc” “\GIS_Workshop\gl_gpwv3_pdens_90_ascii_one\glds00ag60.asc
4) Go to Project → Properties OR Press the Set CRS option on bottom right corner
i.e. 5) Select WGS 84 EPSG: 4326 and Press OK.
OUTPUT:
RESULT: Hence we studied Raster Mosaicking and Clipping.
PRACTICAL NO.7
Aim: Working with attributes to find the maximum population.
Theory:
The attribute table displays information on features of a selected layer. Each row in the table
represents a feature (with or without geometry), and each column contains a particular piece
of information about the feature. Features in the table can be searched, selected, moved or
even edited.
Aim: To find out the nearest populated place for each location where the earthquake
happened.
Theory:
2. You will see a new layer ne_10m_populated_places_simple loaded in the Layers panel.
This layer contains the points representing populated places. Now we will load the
earthquakes layer. This layer comes as a Tab Serepated Values (TSV) text file. To load this
file, click the Open Data Source Manager button on the Data Source Toolbar. You can also
use Ctrl + L keyboard shortcut.
3. Click the ... button next to File name and browse to the downloaded signif.txt file. Once
loaded, the File Format and Geometry Definition fields should be autopopulated with correct
values. Click Add followed by Close.
4. Zoom around and explore both the datasets. Each yellow point represents the location of a
significant earthquake and each red point represents the location of a populated place. Our
goal is to find out the nearest point from the populated places layer for each of the points in
the earthquake layer.
5. Before we do the analysis, we need to clean up our inputs. The signif layer contains many
records without a valid geometry. These records were imported with a NULL geometry. So
let’s remove these records first. Go to Processing ‣ Toolbox.
6. Search for and locate the Vector geometry ‣ Remove null geometries tool. Double-click to
launch it.
7. Select signif as the Input layer and click Run. Once the processing finishes, click Close.
8. You will see a new layer caled Non null geometries loaded into the Layers panel. We will
use this layer instead of the original signif layer in further analysis. Un-check the signif layer
in the Layers panel to hide it. Now it is time to perform the nearest neighbor analysis. Search
and locate the Vector analysis ‣ Distance to nearest hub (line to hub) tool. Double-click to
launch it.
9. In the Distance to Nearest Hub (Line to Hub) dialog, select Non null geometries as the
Source points layer. Select ne_10m_populated_places_simple as the Distination hubs layer.
Select name as the Hub layer name attribute. The tool will also compute straightline distance
between the populated place and the nearest earthquake. Set Kilometers as the Measurement
unit. Click Run. Once the processing finishes, click Close.
10. Back in the main QGIS window, you will see a new line layer called Hub distance loaded
in the Layers panel. This layer has line features connecting each earthquake point to the
nearest populated place. Right-click the Hub distance layer and select Open Attribute Table.
11. Scroll right to the last columns and you will see 2 new attributes called HubName and
HubDist added to the original earthquake features. This is the name the distance to the nearest
neighbor from the populated places layer.
12. Our analysis is complete. We can now explore another tool that can also do a similar
analysis. Distance Matrix is a powerful tool that allows you to not only compute distance to
the nearest point, but to all the points from another layer. We can use this method as an
alternative to the Distance to nearest hub tool. Un-check the Hub distance layer to hide it.
Search and locate the Vector analysis ‣ Distance matrix tool.
13. In the Distance matrix dialog, set Non null geometries as the Input point laeyer and I_D
as the Input unique ID field. Set ne_10m_populated_places_simple as the Target point layer
and name as the Target unique ID field. Select Linear (N*k x 3) distance matrix as the Output
matrix type. The key here is to set the Use only the nearest (k) target points parameter to 1 -
which will give you only the nearest neighbor in the output. Click Run to start the matrix
calculation. Once the processing finishes, click Close.
14. Once the processing finishes, a new layer called Distance matrix will be loaded. Note that
the output of this tool is a layer containin MultiPoint geometries. Each feature contains 2
points - source and target. Open the Attribute Table for the layer. You will see that each
feature has attributes mapping the earthquake to its nearest populated place. Note that the
distance here is in the layer’s CRS units (degrees).
15. At this point, you can save your results in the format of your choice by right-clicking the
layer and selecting Export ‣ Save Features As. If you want to visualize the results better, we
can easily create a hub-spoke rendering from the feature’s geometry. Right-click the Distance
matrix layer and select Properties.
16. In the Properties dialog, switch to the Symbology tab. Click on the Simple marker
subrenderer and select Geometry generator as the Symbol layer type. Set LineString /
MultiLineString as the Geometry type. Click the Expression button.
17. Here we can enter an expression to create a line geometry from the 2 points within each
multi-point source geometry. Enter the following expression. make_line(point_n( $geometry,
1), point_n( $geometry, 2))
18. Back in the Symbology tab, set the style of the line as per your liking and click OK.
19. You will see the Distance matrix layer now rendered with lines instead of points. Note
that we did not have to create a new layer for this visualization. The layer still contains
MultiPoint geometries, but it is dynamically rendered as lines based on the expression.
OUTPUT:
Result: Hence we studied how to find out the nearest populated place for each location where
the earthquake happened.
PRACTICAL NO .9
Aim: To visualize the connectivity and build a network to find shortest path between any
2 points in the city.
Theory:
1. Locate the downloaded Street_Centerlines.zip file in the Browser panel. Expand it and
drag the Street_Centerlines.shp file to the canvas.
2. You will see a new line layer called Street_Centerlines added to the Layers panel. This
layer represents each road in Washington DC. Select the Identify tool in the Attributes
Toolbar. Click on any road segment to see what attributes are attached to it. There are
standard attributes like road name, type etc. there is an attribute called DIRECTIONA.
This is an import attribute for routing as it specifies whether the segment is two-way or
one-way. It contains 4 different values. Two Way for two-way streets. One Way
(Digitizing direction) for one-way streets where the traffic is allowed in the direction of
the line (start-point to end-point) and One way (Against digitizing direction) for one-way
streets where the traffic flows in the opposite direction of the line. There is also Unknown
value where we will assume two-way traffic. We will now use the information in that
attribute to display an arrow on streets that are one-way.
3. Click the Open the layer Styling Panel button in the Layers panel. Select the Rule-
based renderer from the drop-down menu.
4. We will create a new style with a filter for only the one-way roads. Click the Add rule
+ button.
6. In the Expression string builder dialog, expand the Fields and Values section in the
middle-panel. Select DIRECTIONA attribute and click All Unique in the right-hand
panel. The 4 values that we discussed earlier will appear. Having these values here as a
reference helps when building the expression. Also, you can double-click on any value to
add them to the expression.
7. The goal is to create an expression that selects all one-way streets. Enter the following
expression and click OK.
"DIRECTIONA" = 'One way (Against digitizing direction)' OR "DIRECTIONA" ='One
Way (Digitizing direction)'
10. Click on the Simple marker symbol. Scroll down and pick the filled_arrowhead
marker. You will see that the arrow-like symbol now appears on the one-way streets. But
all of them are pointing in a single direction, whereas we know that our filter contains
roads in multiple directions. We can further refine the symbols with a data-defined
override for the Rotation value.
12. We can put a conditional expression that returns different rotation value depending on
the one-way direction. A simple 0 or 180 degree rotation works to account for the
direction, but it works only for horizontal lines. To align the arrow-head perpendicular to
all the lines - we need to account for the angle of the line in the expression as well. The
angle_at_vertex function helps us find the angle and use it in the expression. Enter the
following expression and click OK.
CASE
WHEN "DIRECTIONA" = 'One Way (Digitizing direction)'
THEN angle_at_vertex($geometry, 1) - 90
WHEN "DIRECTIONA" = 'One way (Against digitizing direction)'
THEN angle_at_vertex($geometry, 1) - 90 + 180
END
13. Now you will see the arrow-heads aligned to the correct road direction and angle. To
keep the style uncluttered, we are choosing to display arrows only on one-way streets.
Unlabeled streets are assumed to be two-way. Now that we have the network styled
correctly, we can do some analysis. Go to Processing ‣ Toolbox.
14. Search for and locate the Network analysis ‣ Shortest path (point to point) algorithm.
Double-click to launch it.
15. In the Shortest Path (Point to Point) dialog, select Street_Centerlines as the Vector
layer representing network. Keep the Path type to calculate as Shortest. Next we need to
pick a start and end point. You can click the ... button and click on any point on the
network in the canvas. If you want to replicate the results in this tutorial, you can enter -
76.99730092166396,38.887624846748984 as the Start point and -
76.99154831062152,38.89151000569929 as the End point. Expand the Advanced
parameter section. Choose DIRECTIONA as the Direction field. You must be familiar
with the one-way direction values for forward and backward traffic flow. Enter One Way
(Digitizing direction) as the Value for forward direction and One way (Against digitizing
direction) as the Value for backward direction. Keep other options to their default values
and click Run.
16. The algorithm will use the geometry of the layer and provided parameters to build a
network graph. This graph is then used to find the shortest path between the start and end
points. Once the algorithm finishes, you will see a new layer Shortest path added to the
Layers panel that shows the shortest path between start and end points.
OUTPUT:
RESULT: Hence we studied how to visualize the connectivity and build a network to find
the shortest path between any 2 points in the city.
PRACTICAL NO.10
Aim: To load a vector point layer representing all major airports and use python scripting to
create a text file with the airport name, airport code, latitude and longitude for each of the
airports in the layer
Theory:
1. Locate the ne_10m_airports.zip file in the QGIS Browser and expand it. Select the
ne_10m_airports.shp file and drag it to the canvas.
3. Select the Identify tool and click on any of the points to examine the available attributes.
You will see that the name of the airport and it’s 3 digit code are contained in the attributes
name and iata_code respectively. You can close the Identify window.
4. QGIS provides a built-in console where you can type python commands and get the result.
This console is a great way to learn scripting and also to do quick data processing. Open the
Python Console by going to Plugins ‣ Python Console.
5. You will see a new panel open at the bottom of QGIS canvas. You will see a prompt like
>>> at the bottom where you can type commands. For interacting with the QGIS
environment, we must use the iface variable. To access the currently active layer in QGIS,
you can type the following and press Enter. This command fetches the reference to the
currently loaded layer and stores it in the layer variable.
6. There is a handy function called dir() in python that shows you all available methods for
any object. This is useful when you are not sure what functions are available for the object.
Run the following command to see what operations we can do on the layer variable.
dir(layer)
7. You will see a long list of available functions. For now, we will use a function called
getFeatures() which will gets you the reference to all features of a layer. In our case, each
feature will be a point representing an airport. You can type the following command to iterate
through each of the features in the current layer.
for f in layer.getFeatures():
print(f)
8. As you will see in the output, each line contains a reference to a feature within the layer.
The reference to the feature is stored in the f variable. We can use the f variable to access the
attributes of each feature. Type the following to print the name and iata_code for each airport
feature. for f in layer.getFeatures(): print(f['name'], f['iata_code'])
9. So now you know how to programatically access the attribute of each feature in a layer.
Let’s see how we can access the coordinates of the feature. The coordinates of a vector
feature can be accessed by calling the geometry() function. This function returns a geometry
object that we can store in the variable geom. You can run asPoint() function on the geometry
object to get the x and y coordinates of the point. If your feature is a line or a polygon, you
can use asPolyline() or asPolygon() functions. Type the following code at the prompt and
press Enter to see the x and y coordinates of each feature.
for f in layer.getFeatures():
geom = f.geometry()
print(geom.asPoint())
10. What if we wanted to get only the x coordinate of the feature? You can call the x()
function on the point object and get its x coordinate.
for f in layer.getFeatures():
geom = f.geometry()
print(geom.asPoint().x())
11. Now we have all the pieces that we can stitch together to generate our desired output.
Type the following code to print the name, iata_code, latitude and longitude of each of the
airport features. Here we are using the .format() method which gives more control on printing
multiple variables. The .2f notation is to limit the coordinates to 2 decimals.
for f in layer.getFeatures():
geom = f.geometry()
print('{},{},{:.2f},{:.2f}'.format(f['name'],
f['iata_code'],geom.asPoint().y(),geom.asPoint().x( )))
12. You can see the output printed on the console. A more useful way to store the output
would be in a file. You can type the following code to create a file and write the output there.
Replace the file path with a path on your own system. Note that we add \n at the end of our
line formatting. This is to add a newline after we add the data for each feature. with
open('E:\airports.txt', 'w') as file:
for f in layer.getFeatures():
13. You can go to the output file location you specified and open the text file. You will see
the data from the airports shapefile that we extracted using python scripting.
OUTPUT:
Result: Hence we studied how to load a vector point layer representing all major airports and
use python scripting to create a text file with the airport name, airport code, latitude and
longitude for each of the airports in the layer