Professional Documents
Culture Documents
Ujaval Gandhi
Follow @spatialthoughts
Want to learn QGIS in a structured way? Check out Spatial Thoughts (https://spatialthoughts.com/)
for more learning materials and instructor-led online programs with QGIS.org certi!cation.
These tutorials are also available in many other languages. Please see translations
(https://www.qgistutorials.com/en/docs/introduction.html#translations) page.
../../_images/zoning_map.png
1. Zoning layer: A polygon shape!le with zoning code and description for land parcels having a
single zoning - clipped to the Cape Town CBD area.
2. Split-zoning layer: A polygon shape!le with zoning code and description for land parcels
having multiple zoning - with each polygon split into single zones polygons.
3. Cape Town CDB Area: A polygon demarcating the Cape Town CBD area.
Let’s see the step wise to prepare the dataset for this tutorial.
../../_images/db1.png
2. Click on View Full Details to explore services available to get the data.
../../_images/db2.png
3. Scroll down to !nd View Data Source and click on the it.
../../_images/db3.png
4. On the ArcGIS REST Services Directory , Go to Home and copy the URL of that page. The
copied URL looks like - https://citymaps.capetown.gov.za/agsext1/rest/services
(https://citymaps.capetown.gov.za/agsext1/rest/services).
../../_images/db4.png
../../_images/db5.png
6. The list of data sources is seen in the left panel. Scroll down to !nd ArcGIS REST Server.
Click on new to create new server connection.
../../_images/db6.png
7. In the Connection Details, give the Name Cape Town Open Data Portal and paste the
copied url as an input for URL.
../../_images/db7.png
8. Click Ok and then Connect to see the data folders available in the server.
../../_images/db8.png
9. Now we will search for all three layers required for the tutorial from the database. Firstly,
we will open Cape Town CBD layer in the QGIS. Expand folders to browse to the layers. Full
path to the layer is Theme_Based ‣ Open_Data_Service ‣ Cape Town CBD. Select the layer
and click Add.
../../_images/db9.png
10. Close the Data Source Manager to see the layer added to the QGIS. Click on Zoom to Layer
to centre and display the layer on the canvas.
../../_images/db10.png
11. Now, will add the Zoning layer using Data Source Manager.Connect to Cape Town Open
Data Portal and browse to Zoning layer. The full path is Theme_Based ‣ Open_‐
Data_Service_Zoning ‣ Zoning. This is a very large layer, so make sure to check the box Only
request features overlapping the current view extent to avoid loading all the features avail-
able in the layer. If you forget this, loading of the layer may take a long time. Click Add to
open in the QGIS.
../../_images/db11.png
12. Similarly add Split_Zoning layer. The full path is - Theme_Based ‣ Land_Parcel_Zoning ‣
Split Zoning.
../../_images/db12.png
13. We can see all three source layers are open in QGIS. We want to clip the Zoning and Split
Zoning layers to the Cape Town CBD boundary layer. Firstly, let’s save all three layers lo-
cally as shape!les. Right click on the Cape Town CBD layer. Look for Export and click on
Save Features As.
../../_images/db13.png
14. Set the format ESRI Shapefile and browse to the local folder where you want to save the
shape!les. We will save all the layers related to this tutorial in a single data folder. Save the
layer as cbd . Keep all other options default and click OK. Similarly export other two layers
as Zoning.shp and Split Zoning to the same folder.
../../_images/db14.png
15. Remove the layers loaded from server. Select all three layers, and click on Remove Lay‐
er/Group icon. We want to extract features from Zoning and Split Zoning layers inter-
secting with cbd boundary.
:
../../_images/db15.png
16. Go to Processing ‣ Toolbox from the menubar.
../../_images/db16.png
17. In the toolbax, search for Intersection algorithm and double-click to open.
../../_images/db17.png
18. Select Zoning as Input layer and cbd as Overlay layer. Keep other options default and pro-
ceed to save output to !le.
../../_images/db18.png
19. Save the output layer as zoning_cbd in the data folder and click Run.
../../_images/db19.png
20. Depending on your Processing settings, you will see some errors or warnings displayed in
Log tab. The input layer has some invalid geometries and it is being skipped while running
intersection. We will !x geometries of Zoning and Split Zoning layers before taking
the intersection to extract all geometries.
../../_images/db20.png
21. Remove the intersection output from QGIS and data folder. Search for Fix geometries tool in
the processing toolbox. Double-click to open.
../../_images/db21.png
22. Select Zoning as Input layer. Keep all the other inputs as default and save the output layer
as zoning_fixed.shp in the data folder by clicking Save to File. Click Run. Repeat the
process for !xing geometries on Split Zoning layer and save the layer with !xed geome-
tries as split_zoning_fixed.shp .
../../_images/db22.png
23. Remove Zoning and Split Zoning layers. We will move ahead with extracting features
from zoning_fixed and split_zoning_fixed layers which intersect cbd . Search for
Intersection from the processing toolbox and double-click to open.
../../_images/db23.png
24.Select Zoning_fixed as Input layer and cbd as Overlay layer to perform intersection as de-
scribed in steps 18 and 19. Save the output as zoning_cbd and repeat the same for
split_zoning_fixed layer and save the output layer as split_zoning_cbd .
../../_images/db24.png
For convenience, you may directly download a copy of all three pre-processed layers from the links
below:
cbd.shp (https://www.qgistutorials.com/downloads/cbd.zip)
zoning_cbd.shp (https://www.qgistutorials.com/downloads/zoning_cbd.zip)
split_zoning_cbd.shp (https://www.qgistutorials.com/downloads/split_zoning_cbd.zip)
:
Procedure
1. Open QGIS. Click Open Data Source Manager icon to add layers to work on for the tutorial.
../../_images/160.png
2. Switch to the Vector tab and use the browsing button to navigate to the folder where you
have kept the processed shape!les.
../../_images/230.png
../../_images/325.png
4. You will see all three !le paths in the text box beside Vector Dataset. Click Add followed by
Close.
../../_images/410.png
../../_images/510.png
6. Save the project to the data directory as landuse_map.qgz !le. The QGIS Project !le con-
tains references to the data layers and saves styles, map templates etc.
../../_images/610.png
7. Select the zoning_cbd layer and click the Open Attribute Table button in the Attributes
Toolbar. Note that the attribute INT_ZONE_C has the zoning codes and INT_ZONE_D has
the zoning description. Close the attribute table.
../../_images/710.png
8. Now let’s style the layer based on these attributes, so the parcels with the same zoning
codes are styles in the same color. Click the Open the Layer Styling panel button in the Lay-
ers panel. Click the dropdown button next to Single Symbol.
:
../../_images/810.png
9. Select Categorized as the renderer. Select INT_ZONE_C as the Value. Click Classify.
../../_images/910.png
10. You will see a series of symbols appear. There is a di"erent color symbol assigned for every
unique code in the layer.
../../_images/1014.png
11. Notice that each zoning category has sub-categories. The General Business (GB) cate-
gory has further sub-divisions like GB1 , GB2 , and so on. For the purpose of this map, we
can merge all the sub-categories to a single top-level category. Hold the Shift key and select
all sub-categories. Right-click and select Merge Categories.
../../_images/1117.png
12. Repeat the process for MU and TR categories. Once merged, we can now change the Leg-
end label to be more descriptive. Click on the Legend label to rename a class.
../../_images/1215.png
13. Enter descriptions of each zoning category based on the values given in the INR_ZONE_D
column. As you enter those description, you will see the legend of the layer in the Layers
panel also updates.
../../_images/1313.png
14. Now we can update the colors and symbology of each category. Click on the Symbol for a
category.
../../_images/1412.png
15. Change the Fill color and Stroke color of the symbol to a color of your choice.
../../_images/1512.png
16. Repeat the process for each category. The last category is all other values. This category
contains all parcels which have NULL values. This is because those parcels have multiple zon-
ing categories attached to them and are represented in the split_zoning_cbd.shp layer. We
do not need them in this layer. Select it and click the - icon to remove that category.
../../_images/1611.png
17. Next, select the cbd layer. Change the symbol to Simple Line and increase the Stroke width.
../../_images/1712.png
18. The split_zoning_cbd.shp layer contains all parcels that were missing zoning codes in
the zoning_cbd layer. The attribute table and values for the zones in the
split_zoning_cbd are the same as the zoning_cbd layer. Instead of con!guring the
symbology for this layer manually, we can copy/paste the styles. Select the zoning_cbd lay-
er, right-click and select Styles ‣ Copy Style ‣ Symbology.
:
../../_images/1810.png
19. Now select the newly added split_zoning_cbd layer, right-click and select Styles ‣ Paste
Style ‣ Symbology.
../../_images/199.png
20. You will see the same symbology being applied to the polygons in the split_zoning_cbd
layer. The styling and legend are complete now.
../../_images/209.png
21. We have our layers styled and legend labels created. Now let’s create a map using these
styled layers along with map elements like, scale bar, north arrow, labels etc. QGIS comes
with a Print Layout that allows composing maps. Go to Project ‣ New Print Layout. When
prompted for a name, you can leave it blank and click OK.
../../_images/2114.png
22. In the Print Layout window, you will see a canvas. Right-click and select Page Properties.
../../_images/2211.png
23. Set the Orientation to Portrait . Next, go to Add Item ‣ Add Map.
../../_images/238.png
24. Hold the left mouse button and draw a rectangle on the canvas. This is the map frame which
will contain the map from the main QGIS window. In the Item Properties tab, use the Interac‐
tively Edit Map Extent icon to pan/zoom the content of the map frame.
../../_images/249.png
25. Scroll down in the Item Properties tab and check the Frame option. Expand it and select a
Color for the frame border. You can also increase the Thickness.
../../_images/258.png
26. The map frame is now ready. Let’s add other elements. Go to Add Item ‣ Add Legend.
../../_images/267.png
27. Drag a rectangle where you want to place the legend. Once added, scroll down in the Item
Properties tab and un-check the Auto update button so we can manually edit the legend
items.
../../_images/278.png
28. We have 2 layers with identical legends, so we can remove one of them. Select the
split_zoning_cbd layer and click the Remove selected item(s) from legend icon. Similarly
remove cbd layer from the legend.
../../_images/288.png
29. Right-click the zoning_cbd layer and check the Hidden option.
../../_images/297.png
30. Scroll down and expand the Columns section. Check the Split layers option and increase the
Count to 2.
../../_images/307.png
:
31. Scroll down further to the Spacing section. Adjust the spacing between di"erent elements
till the legend is clearly legible.
../../_images/3111.png
32. You can change style and size of the fonts in legend from Fonts and Text Formatting proper-
ties. When done, go to Add Item ‣ Add North Arrow. Drag a rectangle where you want to
place the element on the map.
../../_images/326.png
33. Pick a symbol of your choice. Scroll down and expand the SVG Parameters. Change the Fill
color and Stroke color as per your choice.
../../_images/333.png
34. Now we will add a Scale Bar. Go to Add Item ‣ Add Scale Bar. Drag a rectangle where you
want to place the element on the map. Adjust the Style and Segments parameters for the
scale bar.
../../_images/343.png
35. Our map needs a title and other information labels. Go to Add Item ‣ Add Label.
../../_images/353.png
36. Enter a map title in the Main Properties section. Click the Font button under Appearance
section to adjust the font size and style.
../../_images/362.png
37. Add other labels indicating the data source and your name. Lastly we will !nish our map by
adding a frame around the label block. Go to Add Item ‣ Add Shape ‣ Add Rectangle.
../../_images/372.png
38. Draw a rectangle. Click the symbol for Style and set the Fill Color to transparent and Stroke
color to match other frames.
../../_images/372.png
39. Once you are satis!ed with your composition, you can export the result. Go to Layout ‣ Ex‐
port as PDF. Save the PDF in your data folder as capetown_zoning_map.pdf .
../../_images/392.png
If you want to give feedback or share your experience with this tutorial, please comment below.
(requires GitHub account)
step 3: View Data Source open and click on the it --> View Data Source and click on it
:
step 3: View Data Source open and click on the it --> View Data Source and click on it
step 7: for for URL --> for URL
Write Preview
Sign in to comment
This work is licensed under a Creative Commons Attribution 4.0 International License
(http://creativecommons.org/licenses/by/4.0/deed.en_US)
: