DEV Community

Cover image for QGIS mapping
ondugba
ondugba

Posted on

QGIS mapping

Introduction

For our second group project in my Data Science course - we were tasked with designing a linear regression model that would predict housing prices.

For this analysis, we were provided with the dataset "King County Housing Price from May 2014- May 2015" created by the Center for Spatial Data Science (https://spatial.uchicago.edu). It contained 21,597 entries with 21 different columns about home sales in the Seattle metropolitan area. One of the columns I found pretty interesting was the waterfront property feature.

Upon examining the data - it seemed like the waterfront feature wasn't capturing all the homes it should have caught. There were a lot of null values. So rather than dropping the feature entirely - I thought there had to be a better way of bringing that information out.

So I came upon QGIS. QGIS is a "Free and Open Source Geographic Information System [that enables users to] Create, edit, visualise, analyse and publish geospatial information on Windows, Mac, Linux, BSD and mobile devices"

Here's a brief overview of the steps:

  1. Download and install QGIS.
  2. Load map
  3. Input latitude and longitude for each home sale point
  4. Overlay shape file
  5. Calculate distance from homes to body of water
  6. Export results.

Step 1 - Install QGIS

Download and install QGIS. QGIS can be installed from .

Step 2 - Load map

When you first open up QGIS - it's just a white screen. You have to actually load a map. On the left side of the screen you'll see a few different options - I chose the "Street Map" option under the XYZ tiles header.

Image description

Image description

Since the data we'll be importing is from the Seattle metropilitan area make sure you navigate and zoom to the pacific northwest.

Image description

Step 3 - Input Latitude and Longitude

At the top of the screen there are more options. Navigate to Layer > Add Layer > Add delimited Text Layer. In the box that comes up you'll need to import your data file and label your lat and long as x and y.

Image description

Image description

Your map should now look like this.

Image description

Step 4 - Overlay shape file

Our next step is to map the bodies of water in the area. For this project the shape file gives the 'shape' of the bodies of water in a given area. I used the Seattle dataset downloaded from (.
Now we just add the shapefile as a layer onto our map. You can just drag it from your download folder onto the map itself.

Image description

now our map look likes this - the bodies of water are dark blue - note you can change the colors of the map by playing around with the color settings on the right side of the screen.

Image description

Step 5 - Calculate distance

Now this step has a few parts - first we need to find the shoreline, then calculate the distance from homes to the closest body of water.

In the lower right hand corner - there is a search bar - we need to find and run the "Convert polygon/line vertices to points”.

Image description

Since we are interested in finding the shorelines make sure its running on the waterbody shape file you downloaded.

Image description

Now we've added the shorelines onto our map (yellow)

Image description

Next we need to calculate the distance in miles (denoted by the orange line) from each home point (purple) to the closest shoreline (yellow).
In that same lower right hand corner we need to find and run the "Distance to nearest hub (line to hub)”. The source layer - is our housing location. The destination layer is the points layer. For distance I used miles but feel free to use another measurement

Image description

Image description

After running the distance tool this is what we now have

Image description

Image description

Step 6 - Exporting data

Our final step is to add our distance data to our original data and export it out of QGIS.

In the right hand corner double-click our housing data layer, select joins from the pop-up, add a join (the green plus sign).

Image description

Use distance for join layer, and id for join field and target field. Make sure the joined fields box is checked and select the distance feature and hit ok.

Image description

Finally export.
Right click on the data layer again, and export.

Image description

And just like that. We're done.

Top comments (0)