Spatial Analysis (Intersect and Nearestpoints) using QGIS CartoDB plugin

This post will demonstrate how we used CartoDB plugin in QGIS to perform spatial analysis operations namely:

– Intersect features

– Nearest Points


1. Launch QGIS on your desktop. Click on ‘Add CartoDB Layer’. We want to add a polygon layer

that comprises the administrative boundaries of countries in the West African region of Africa.



2. We select the layer-west_africa- from our layers in CartoDB. Click OK to load the

layer onto the map canvas.



3. The polygon layer is added on the map canvas as seen on the screenshot below.



4. We click on the ‘Add SQL CartoDB Layer’ icon button on the main menu bar.



5. We have a layer of point features that represent grazing spots located allover the region.

We will write a SQL statement for the grazing spots that intersect the polygon feature

named Nigeria.

select grazingspots.cartodb_id, grazingspots.the_geom, grazingspots.headcount,
from grazingspots, west_africa
where ST_Intersects(grazingspots.the_geom, west_africa.the_geom)
and “country” = ‘Nigeria’


Click on ‘Test Query’ button to see if the statement inputted is valid.



6. Click on ‘Add Layer’ to add the result of the query to the map canvas.



7. The result is added onto the layer previously on the map canvas as shown

on the screenshot below.



Nearest Points is a common term used to describe a spatial analysis that gives the user the

closest features to a specified point or spatial object. For this demo, we will still use the

grazingspots layer as the earlier analysis.


8. Click on the ‘Add SQL CartoDB Layer’ icon button. Write the SQL statement to find

the closest 30 features to our specified point- 3.94702588, 7.48137608.

Click ‘Test Query’ to validate for any error in the statement.



If the statement is valid, then click “Add Layer’ to load the result of the query on the map canvas.


9. The result is added to the layer already on the map canvas as shown on

the screenshot below.



10. In addition , the user can open the attribute table of the query layer and view the

attributes of the selected point features.



11. The attribute table opens and can be exported in report form.



Thank you for following the blog.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s