Difference between revisions of "Editing Vector Data in GRASS GIS"
| Line 1: | Line 1: | ||
== Introduction == |
== Introduction == |
||
This tutorial will introduce basic GRASS GIS tools for working with vector data and editing aswell. This will include the use of three open datasets from the open source site of the City of Ottawa: Traffic Collisions, Red Light Camera Violations and Road Centrelines. The tutorial on this page will cover the creation of a GRASS project, importing the vector data, selecting specific features using attribute conditions, changing vector symbology and the use of basic vector editing tools. |
|||
This tutorial will demonstrate how to do a vector analysis using GRASS GIS. By the end, you should be a little more comfortable using the program. Please note that for this tutorial we are using GRASS 8.2, older versions of GRASS may not reconcile with this tutorial. Our goal is to use the 2020 Red Light Camera Violations data from open.ottawa.ca to make a map that displays the safest areas in Ottawa to drive based on the number of traffic violations. If you do not already have GRASS installed on your computer, you can go to this [https://dges.carleton.ca/CUOSGwiki/index.php/Intro_to_GRASS_workshop Intro to GRASS workshop page] with detailed instructions on how to download it. |
|||
If you currently DO NOT have GRASS GIS installed, this is the link to download it, including installation instructions. [https://dges.carleton.ca/CUOSGwiki/index.php/Intro_to_GRASS_workshop] |
|||
== Data == |
== Data == |
||
There will be three main Vector datasets used in this tutorial, all from the City of Ottawa: |
|||
First we will need to download our data. You can download the Ottawa Traffic Collision data [https://open.ottawa.ca/datasets/ottawa::traffic-collision-by-location-2019/explore?location=45.250250%2C-75.806856%2C1.62 here.] After you proceed to the link, click the download button, and select "shapefile." Once you have downloaded the Traffic Collision data, click [https://open.ottawa.ca/datasets/ottawa::red-light-camera-violations-2019/explore?location=45.376580%2C-75.686783%2C2.96 here] to download the Red Light violations data. Finally, download the Road Centrelines data [https://open.ottawa.ca/datasets/ottawa::road-centrelines/explore?location=45.245509%2C-75.794650%2C1.87 here.] |
|||
* '''Traffic Collision by Location (2019):''' [https://open.ottawa.ca/datasets/ottawa::traffic-collision-by-location-2019/explore?location=45.250250%2C-75.806856%2C1] |
|||
* '''Red Light Camera Violations (2019):''' [https://open.ottawa.ca/datasets/ottawa::red-light-camera-violations-2019/explore?location=45.376580%2C-75.686783%2C2] |
|||
* '''Road Centrelines:''' [https://open.ottawa.ca/datasets/ottawa::road-centrelines/explore?location=45.245509%2C-75.794650%2C1] |
|||
Download each of the linked datasets as SHAPEFILES and extract the files to start. The 2019 datasets are retained, this is for the purpose of this tutorial, in order to demonstrate vector data operations rather than analyze present traffic conditions |
|||
== Creating a GRASS Project == |
|||
GRASS GIS specializes in organizing spatial data by using projects and mapsets. For this tutorial, we will create a new Project for the Ottawa vector datasets. |
|||
From the GRASS startup interface, select "Create a new GRASS project". Enter a descriptive project name like '''Ottawa_Vector_Editing'''. |
|||
On the following screen, you will be prompted to enter and select a Coordinate Reference system (CRS), choose '''Read CRS from a georeferenced data file'''. Click on the downloaded SHP file '''Road_Centrelines.shp''' and continue through creating the project. Using the supplied georeferenced dataset will allow GRASS to establish the Project CRS directly from the data and helps avoid a CRS mismatch during import. |
|||
[[File:GRASS Project CRS From Data.png|500px|thumb|center|Selecting the option to read the project CRS from a georeferenced data file.]] |
|||
Once the Project has been created, ensure that its '''PERMANENT''' Mapset is active before importing the remaining vector datasets. |
|||
=== Importing the Vector Data === |
|||
From the GRASS menu, select '''File → Import vector data → Import of common vector formats [v.in.ogr]'''. |
|||
Find the downloaded '''Red Light Camera Violations''' SHP file and select it as the input . Before running the import, open the '''Output''' tab and enter a simple output vector map name such as: |
|||
'''Red_Light_Camera_Violations_2019''' |
|||
This step is important because some downloaded shapefiles may have filenames that do not meet GRASS vector map naming requirements. |
|||
[[File:GRASS Red Light Output Name.png|500px|thumb|left|Setting a valid output vector map name before importing the Red Light Camera Violations dataset.]] |
|||
Run it. Repeat this import process for '''Traffic_Collision_by_Location_2019''' if it is not already present in the Project. |
|||
After you've imported the datasets, the data and layers panel should contain the following three vector layers: |
|||
* '''Road_Centrelines''' |
|||
* '''Red_Light_Camera_Violations_2019''' |
|||
* '''Traffic_Collision_by_Location_2019''' |
|||
[[File:GRASS Three Vector Layers.png|500px|thumb|left|The three Ottawa vector datasets loaded into the GRASS GIS Project.]] |
|||
== Filtering and Displaying the Vector Data == |
|||
After you've imported, place the '''Road_Centrelines''' layer beneath the points layers (two) in the layers panel. This will keep traffic collision and red light camera locations visibile above the road network. |
|||
In the following steps, we will use attribute conditions in order to display the locations with higher numbers of violations or collisions. |
|||
=== Filtering Red Light Camera Violations === |
|||
Right-click the '''Red_Light_Camera_Violations_2019''' in the layers panel on the left and select '''properties'''. You will then open the '''Selection''' tab. |
|||
Open the SQL builder, beside the SQL WHERE condition. Click '''TOTAL_VIOL''', then select the '''>=''' operator, and enter '''500'''. |
|||
[[File:GRASS Red Light Selection Tab.png|500px|thumb|left|The Selection tab provides access to the SQL Builder for filtering vector features.]] |
|||
It should look like this " "TOTAL_VIOL" >= 500 " |
|||
[[File:GRASS Red Light 500 Filter.png|500px|thumb|left|SQL query used to display Red Light Camera locations with 500 or more violations.]] |
|||
Apply the changes in SQL then apply it in the layer properties. The Red Light Camera will now only display locations with 500 or more violations in 2019. |
|||
=== Filtering Traffic Collisions === |
|||
This exact process will be repeated for the '''Traffic_Collision_by_Location_2019''' layer. In the SQL Builder, you will select '''Total_Coll''' and >= 10 . |
|||
[[File:GRASS Traffic Collision 10 Filter.png|500px|thumb|left|SQL query used to display locations with 10 or more traffic collisions.]] |
|||
Apply it and the layer will now display only locations with 10 or more collisions. |
|||
=== Improving Layer Symbology === |
|||
The two point layers can be very hard to distinguish when they are the same similar symbols. we will now change the colors, shapes and sizes to make them easier to interpret. |
|||
[[File:GRASS Traffic Collision Symbol.png|500px|thumb|left|Changing the Traffic Collision point symbol to a circle with a size of 6.]] |
|||
==== Traffic Collision Symbology ==== |
|||
Right-click '''Traffic_Collision_by_Location_2019''' and select '''Properties'''. |
|||
Open the '''Colors''' tab and change the '''Feature color''' to a green preset. Next, open the '''Symbols''' tab, change the point symbol to '''basic/circle''', and set the '''Symbol size''' to '''6'''. |
|||
Go to the '''Colors''' tab and change the '''Area fill color''' to yellow. Click '''Apply''' to update the map display. |
|||
[[File:GRASS Traffic Collision Colors.png|500px|thumb|left|Changing the Traffic Collision feature color to green and the area fill color to yellow.]] |
|||
==== Red Light Camera Symbology ==== |
|||
Right-click '''Red_Light_Camera_Violations_2019''' and select the '''Properties'''. |
|||
Open the '''Colors''' tab and change the '''Feature color''' to red. You will then open the '''Symbols''' tab and increase the symbol size so that the filtered red light camera locations are clearly visible on the map. |
|||
You can use the Zoom In tool to focus on somewhere in Ottawa, where many of the displayed locations are concentrated. |
|||
[[File:GRASS Red Light Camera Color.png|700px|thumb|left|Changing the Red Light Camera Violations feature color to red.]] |
|||
== Editing Vector Features == |
|||
On top of changing how the vector data is displayed, GRASS GIS can be used to edit the vector features themselves. The Vector Digitizer provides tools for modifying vector geometry and attributes. |
|||
=== Starting the Vector Digitizer === |
|||
In the Layers panel, right-click the '''Road_Centrelines''' layer and select '''Start editing'''. GRASS will then activate the Vector Digitizer toolbar and display the editable vertices of the selected vector layer. |
|||
[[File:GRASS Vector Digitizer Roads.png|700px|thumb|left|The Road Centrelines layer opened in the GRASS GIS Vector Digitizer.]] |
|||
=== Moving a Vertex === |
|||
Select the '''Move vertex''' tool from the Vector Digitizer toolbar. Click a vertex on a road feature, move it to a new position, and click again to place it. |
|||
[[File:GRASS Move Vertex Tool.png|700px|thumb|left|Road Centrelines displayed in the Vector Digitizer while using the Move vertex tool.]] |
|||
If you are only trying the tools out, use '''Undo''' after moving the vertex to return the road feature to its original geometry. |
|||
== Getting Started with Grass == |
|||
=== Viewing and Updating Attributes === |
|||
Start by launching the GRASS software. You should see three windows, one is a terminal, one is the Map Display, and one is the main interface that includes tabs along the bottom of the window such as "data" and "layer," which we will refer to as the Layer Manager for convenience. You need to add a new "database," which is essentially a folder that you will keep "locations" in. Within the "locations," you will store your mapsets. |
|||
The Vector Digitizer can also be used to view and modify attribute information linked with a feature. Select the '''Display/update attributes''' tool and click a road feature on the map. |
|||
By default, you have a database named something similar to "C:\Users\YourUserName\Documents\grassdata." |
|||
An attribute window will open and display the fields associated with the selected feature. |
|||
Once done, go back to the Layer's Interface window in GRASS, and select the "add new location" icon. |
|||
[[File:GRASS Update Vector Attributes.png|600px|thumb|left|Viewing the attributes of a selected road feature using the Vector Digitizer.]] |
|||
[[File:GRASS_newlocation1.png|400px]] |
|||
<br /> |
|||
<br />Name your location "ottawa_road_safety" and click Next.<br /> |
|||
<br /> |
|||
[[File:ottawa_road_safety.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
Select "Select CRS from a list by EPSG or description" and press Next. |
|||
<br /> |
|||
<br /> |
|||
[[File:Selectingcoordinatesystem.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
Chose NAD27(CGQ77)/UTM zone 19N. This is the ideal projection for the Ottawa area. Select Next, and then Finish. |
|||
<br /> |
|||
<br /> |
|||
[[File:UTMzone19.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
You should now see a new location in your Layer Manager titled ottawa_road_safety. |
|||
<br /> |
|||
<br /> |
|||
[[File:allsetup.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
Before we upload our data in GRASS, open your filefolder on your computer and make sure that the data you downloaded from open.ottawa.ca is in the correct folder location (i.e. C:\Users\YourUserName\Documents\grassdata\ottawa_road_safety\PERMANENT.) |
|||
<br /> |
|||
<br /> |
|||
Next, navigate back to the Layers Manager window in GRASS. Ensure that you are working in the correct location by right-clicking ottawa_roads_safety and selecting "switch mapsets." Next Select the icon shaped like a "V" to import vector data. |
|||
<br /> |
|||
<br /> |
|||
[[File:importV.png|300px]] |
|||
<br /> |
|||
<br /> |
|||
Select browse, and navigate to where you stored your downloaded data. Select the "Traffic_Collision_by_Location_2019.shp" file and select "Import." |
|||
<br /> |
|||
<br /> |
|||
[[File:importingshape1.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
Select "Import and reproject" when prompted. |
|||
<br /> |
|||
<br /> |
|||
[[File:reproject1.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
You should now see a display similar to the one below on your Map Display window. |
|||
<br /> |
|||
<br /> |
|||
[[File:mapdisplay1.png|600px]] |
|||
<br /> |
|||
<br /> |
|||
Repeat these same steps to import the Red Light Violations data; select the icon shaped like a "V." This time, after you select browse, and navigate to where you stored your downloaded data, select the "Red_Light_Camera_Violations_2019.shp" file and select "Import." Next, repeat this for the Road Centrelines data. At the end you should have two layers in your Layers tab. |
|||
<br /> |
|||
<br /> |
|||
[[File:layerstab1.png|600px]] |
|||
<br /> |
|||
<br /> |
|||
== Editing the Map Display == |
|||
Attribute values should only be changed when there's a valid reason to modify the data. For this tutorial, viewing the attributes is sufficient to demonstrate the tool. |
|||
First, make sure the layers are in the correct order. Roads_Centrelines.shp should be the bottom layer. If this is not the case, simply click and drag that layer to the beneath the other two. We are then going to edit our Map Display so that it displays the intersections and areas in Ottawa with a significant number of red light traffic violations and traffic violations in one year. |
|||
When finished, exit the Vector Digitizer to stop editing the Road Centrelines layer. |
|||
===Displaying Layers Based on Attribute Data=== |
|||
== Conclusion == |
|||
The first thing we will edit in our Map display is the Red_Light_Camera_Violations_2019.shp data. We are going to display only the intersections that have 500 or more traffic violations in the year of 2019. |
|||
Right-click on Red_Light_Camera_Violations_2019.shp and select "Properties." |
|||
This tutorial has introduced multiple tools that help learning and working with vector data in GRASS GIS. The work that was displayed for the GRASS project included using coordinate reference system for an existing georeferenced dataset, importing vector SHP, filtering the features by using attribute conditions tool and improving the layer symbology. |
|||
<br /> |
|||
<br /> |
|||
[[File:redlight1.png|600px]] |
|||
<br /> |
|||
<br /> |
|||
Select the "Selection" tab. Then, underneath where it says (where=sql_query), select the blue and white rectangle/square icon. |
|||
<br /> |
|||
<br /> |
|||
[[File:sql_redlight.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
Next, double click the TOTAL_VIOL column. Then select the >= sign, and type 500. Your final query should look like the one below. Press "Apply." |
|||
<br /> |
|||
<br /> |
|||
[[File:grassslqred.png|300px]] |
|||
<br /> |
|||
<br /> |
|||
Press "Apply" again. Then close the d.vect window. |
|||
<br /> |
|||
<br /> |
|||
[[File:montgomery.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
If you uncheck the boxes for each layer except for the Red_Light_Camera_Violations_2019 layer, your map display should look like the one below. We have successfully displayed only the intersections with 500 or more violations in the year 2019. |
|||
<br /> |
|||
<br /> |
|||
[[File:stage1.png|700px]] |
|||
<br /> |
|||
<br /> |
|||
Now we will repeat these steps with the Traffic_Collision_by_Location_2019 layer. Right-click on this layer, and select "Properties." Next, select the "Selection" tab. Select the same square icon again underneath (where=sql_query). This time, double-click the Total_Coll column. Then select the >= button, and type 10. Select "Apply." Select "Apply" again then close the d.vect window. We have now set the Map Display to only display areas with 10 collisions or more in the year 2019. |
|||
<br /> |
|||
<br /> |
|||
[[File:collisions10.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
===Editing Symbols=== |
|||
This tutorial also introduces the Vector Digitizer for editing vector geometry and also viewing feature attributes. A foundation for working with vector data sets in GRASS GIS using the tools and application of spatial data and GIS projections. |
|||
We will start by editing the Traffic_Collision_by_Location_2019 symbols on our Map Display. By default, they are the same color as the other layers, making the information very difficult to discern. We will start by changing the color of the symbol. Right-click on the Traffic_Collision_by_Location_2019 layer, and select “Properties.” Then select the “Colors” tab. It should look like the photo below. |
|||
<br /> |
|||
<br /> |
|||
[[File:colorz.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
Click on the “Feature color.” Then select a new color, in the example below a bright green was selected. Click “OK” and then “Apply.” There is an example of what your Map Display should look like below. |
|||
<br /> |
|||
<br /> |
|||
[[File:colorzz.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
[[File:mapz.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
Now we will repeat these steps with the Red_Light_Camera_Violations_2019 layer. Right-click on this layer, and select “Properties.” Navigate to the “Colors” tab, and select a red color. Click “OK” and then “Apply.” Now your Map Display should look like the one below. |
|||
<br /> |
|||
<br /> |
|||
[[File:displayz.png|500px]] |
|||
<br /> |
|||
<br /> |
|||
Our data is concentrated in the downtown area of Ottawa, so we are going to zoom in this area to make our Display more readable. Select the magnifying glass at the top of your screen that has the plus sign. Then click the center of the most concentrated area of your map. The result on your map display should be similar to the one below. |
|||
<br /> |
|||
<br /> |
|||
[[File:yeehawz.png|500px]] |
|||
<br /> |
|||
<br /> |
|||
Next we are going to edit the symbol size and shape. Right-click on the Traffic_Collision_by_Location_2019 layer. Select “Properties,” then select the “Symbols” tab. Click on the “X” to change the shape of the symbol. Select the circle as the new symbol. Next change the symbol size to 6. Your “Symbols" tab should look like the photo below. |
|||
<br /> |
|||
<br /> |
|||
[[File:coloredit.png|400px]] |
|||
<br /> |
|||
<br /> |
|||
Before you press “Apply” and close this window, navigate back to the “Colors” tab and change the “Area fill color” to yellow. Then press apply. The Map Display should now look like the one below. |
|||
<br /> |
|||
<br /> |
|||
[[File:symbolstuff.png|500px]] |
|||
<br /> |
|||
<br /> |
|||
Now we will do the same thing for the Red_Light_Camera_Violations_2019 layer. Right-click on this layer, and select “Properties.” Then, go to the “Symbols” tab and change the symbol from “X” to a circle, and the size from 5 to 6. Before you press “Apply,” navigate to the “Colors” tab and select the color red for the “Area fill color.” You Map Display should now look like the one below. |
|||
<br /> |
|||
<br /> |
|||
[[File:peachtea.png|500px]] |
|||
<br /> |
|||
<br /> |
|||
==Conclusion== |
|||
In this tutorial, you have begun to explore ways of editing your map display in GRASS GIS. By the end of it, you should be more comfortable uploading data into GRASS, and editing symbols in vector layers. There is much more you can do in this program, and hopefully this tutorial gives you the confidence and the basics to continue to explore the features of GRASS. |
|||
Revision as of 18:25, 6 October 2026
Contents
Introduction
This tutorial will introduce basic GRASS GIS tools for working with vector data and editing aswell. This will include the use of three open datasets from the open source site of the City of Ottawa: Traffic Collisions, Red Light Camera Violations and Road Centrelines. The tutorial on this page will cover the creation of a GRASS project, importing the vector data, selecting specific features using attribute conditions, changing vector symbology and the use of basic vector editing tools.
If you currently DO NOT have GRASS GIS installed, this is the link to download it, including installation instructions. [1]
Data
There will be three main Vector datasets used in this tutorial, all from the City of Ottawa:
- Traffic Collision by Location (2019): [2]
- Red Light Camera Violations (2019): [3]
- Road Centrelines: [4]
Download each of the linked datasets as SHAPEFILES and extract the files to start. The 2019 datasets are retained, this is for the purpose of this tutorial, in order to demonstrate vector data operations rather than analyze present traffic conditions
Creating a GRASS Project
GRASS GIS specializes in organizing spatial data by using projects and mapsets. For this tutorial, we will create a new Project for the Ottawa vector datasets.
From the GRASS startup interface, select "Create a new GRASS project". Enter a descriptive project name like Ottawa_Vector_Editing.
On the following screen, you will be prompted to enter and select a Coordinate Reference system (CRS), choose Read CRS from a georeferenced data file. Click on the downloaded SHP file Road_Centrelines.shp and continue through creating the project. Using the supplied georeferenced dataset will allow GRASS to establish the Project CRS directly from the data and helps avoid a CRS mismatch during import.
Once the Project has been created, ensure that its PERMANENT Mapset is active before importing the remaining vector datasets.
Importing the Vector Data
From the GRASS menu, select File → Import vector data → Import of common vector formats [v.in.ogr].
Find the downloaded Red Light Camera Violations SHP file and select it as the input . Before running the import, open the Output tab and enter a simple output vector map name such as:
Red_Light_Camera_Violations_2019
This step is important because some downloaded shapefiles may have filenames that do not meet GRASS vector map naming requirements.
Run it. Repeat this import process for Traffic_Collision_by_Location_2019 if it is not already present in the Project.
After you've imported the datasets, the data and layers panel should contain the following three vector layers:
- Road_Centrelines
- Red_Light_Camera_Violations_2019
- Traffic_Collision_by_Location_2019
Filtering and Displaying the Vector Data
After you've imported, place the Road_Centrelines layer beneath the points layers (two) in the layers panel. This will keep traffic collision and red light camera locations visibile above the road network.
In the following steps, we will use attribute conditions in order to display the locations with higher numbers of violations or collisions.
Filtering Red Light Camera Violations
Right-click the Red_Light_Camera_Violations_2019 in the layers panel on the left and select properties. You will then open the Selection tab.
Open the SQL builder, beside the SQL WHERE condition. Click TOTAL_VIOL, then select the >= operator, and enter 500.
It should look like this " "TOTAL_VIOL" >= 500 "
Apply the changes in SQL then apply it in the layer properties. The Red Light Camera will now only display locations with 500 or more violations in 2019.
Filtering Traffic Collisions
This exact process will be repeated for the Traffic_Collision_by_Location_2019 layer. In the SQL Builder, you will select Total_Coll and >= 10 .
Apply it and the layer will now display only locations with 10 or more collisions.
Improving Layer Symbology
The two point layers can be very hard to distinguish when they are the same similar symbols. we will now change the colors, shapes and sizes to make them easier to interpret.
Traffic Collision Symbology
Right-click Traffic_Collision_by_Location_2019 and select Properties.
Open the Colors tab and change the Feature color to a green preset. Next, open the Symbols tab, change the point symbol to basic/circle, and set the Symbol size to 6.
Go to the Colors tab and change the Area fill color to yellow. Click Apply to update the map display.
Red Light Camera Symbology
Right-click Red_Light_Camera_Violations_2019 and select the Properties.
Open the Colors tab and change the Feature color to red. You will then open the Symbols tab and increase the symbol size so that the filtered red light camera locations are clearly visible on the map.
You can use the Zoom In tool to focus on somewhere in Ottawa, where many of the displayed locations are concentrated.
Editing Vector Features
On top of changing how the vector data is displayed, GRASS GIS can be used to edit the vector features themselves. The Vector Digitizer provides tools for modifying vector geometry and attributes.
Starting the Vector Digitizer
In the Layers panel, right-click the Road_Centrelines layer and select Start editing. GRASS will then activate the Vector Digitizer toolbar and display the editable vertices of the selected vector layer.
Moving a Vertex
Select the Move vertex tool from the Vector Digitizer toolbar. Click a vertex on a road feature, move it to a new position, and click again to place it.
If you are only trying the tools out, use Undo after moving the vertex to return the road feature to its original geometry.
Viewing and Updating Attributes
The Vector Digitizer can also be used to view and modify attribute information linked with a feature. Select the Display/update attributes tool and click a road feature on the map.
An attribute window will open and display the fields associated with the selected feature.
Attribute values should only be changed when there's a valid reason to modify the data. For this tutorial, viewing the attributes is sufficient to demonstrate the tool.
When finished, exit the Vector Digitizer to stop editing the Road Centrelines layer.
Conclusion
This tutorial has introduced multiple tools that help learning and working with vector data in GRASS GIS. The work that was displayed for the GRASS project included using coordinate reference system for an existing georeferenced dataset, importing vector SHP, filtering the features by using attribute conditions tool and improving the layer symbology.
This tutorial also introduces the Vector Digitizer for editing vector geometry and also viewing feature attributes. A foundation for working with vector data sets in GRASS GIS using the tools and application of spatial data and GIS projections.