A lot of questions have been asked how attribute data can be viewed but without displaying a coordinates column. If one is to export the default data into another format (i.e. CSV format) without generating coordinate column and without having an address which is recognized in the Geocoding system it will result in a lot of challenges when plotting such data.

Adding coordinates to the shapefile attribute data

So, we have our data sets which comprises of Points, Lines and Polygons, but they all lack coordinates (Latitude & Longitude data). We can add latitude and longitude data in simple steps outlined below:

  1. Import the data sets into Q-GIS
  2. Right click on the data set you want to work on and select Toggle Edit mode on the pop-up that comes after clicking.
  3. Right click again but this time select Open Attribute Table, QGIS will open another window which contains the attributes of your data.
  4. Click on Open Field Calculator icon which is on the top navigation bar of your window depending on your OS. Or you can simply use Ctrl + I.
Field calculator window in QGIS

The Create a new field option is already selected by default so there is no need to select that. Enter the name of the field you want to add. In this case we want coordinates so we use Latitude & Longitude for the name. For highest accuracy if you are using Decimal Degree coordinate system on the Output Field Type select Decimal number (real) and set the precision to 8 for increased accuracy.

We need to place an expression that will allow the computation of our field in this case latitude so type $x or select the $x from Geometry category. A preview of the coordinates will be displayed at the bottom of the window.

Click OK and Save. Repeat the same steps but this time for Longitude data therefore we need to change from $x to $y .

Your new field columns filled with Latitude and Longitude data should be appearing now.

What if you have Polygon Data?

For Polygon data maybe you have already realized that nothing will be displayed in the new field values if you follow the steps above.

First of all we need to determine the Center coordinates of each polygon and these are called Polygon Centroids. To do this, on your QGIS navigation bar:

Click on: Vector –> Geometry Tools –> Polygon Centroids

creating polygon centroids to determine center coordinates of polygon data.

Always be sure to select an Input Layer which corresponds to the centroids that you require. In our case we select the Polygon data. A new data layer of the centroids will be created and they will appear as Point data.

Carry out the steps above and you have your coordinates.

After getting your centroid coordinates, you can Join Attribute tables and get the coordinate sets to be attached to the Polygon data.
This will only provide coordinates for the center of the polygons.

What If I have Line data?

For line data its almost similar to the way we treated the polygon data. The only difference is that with line data we Extract Nodes. To do this:

Click on: Vector –> Geometry Tools –> Extract Nodes.

Repeat the steps and you are good to go.

Basically that’s how you can add coordinates to your data sets. If you have any questions kindly refer them to the community ask section

Leave a Reply