I see that it is possible to access Google Fusion Tables in QGIS using OGRs Virtual Format layer. Shown here and details about the Google Fusion Table driver here.

I was wondering whether something similar was possible with cartodb using the Postgres/PostGIS driver? I had tried a few different combinations with out any luck what so ever, I just keep getting an empty layer in QGIS.

Anyone have an idea on how to make this work? or if it is at all possible?

Using dev QGIS 1.9.



  • Does this involve a private table, performing writes, or otherwise require an API key?
    – Scro
    Commented Sep 4, 2013 at 2:41

1 Answer 1


I have not studied the API in detail, but I am unaware of any direct connection to the database that would allow you to use postgres/postGIS drivers. The API will, however return data from a query in GeoJSON format. This can be used in QGIS. The following steps will provide read only access on a public table:

First, browse to the table view from your CartoDB dashboard and grab your account name and an SQL query. Your account name is in the URL -- it's the bit between https:// and .cartodb.com. Choose or create a query from the menu on the right.

Launch Quantum and open the python console. Enter the following lines, using the info from above. Make sure you keep the quotes.

cartoName = 'your account name'
cartoQuery = 'the selected query'

Then paste the following code. You may have to press [Return] to execute the last line of code.

import urllib
cartoUrl = 'http://' + cartoName + '.cartodb.com/api/v2/sql?format=GeoJSON&q=' + cartoQuery
response = urllib.urlopen(cartoUrl)
content = response.read()
layer = QgsVectorLayer(content, cartoName, 'ogr')

Or get the Gist if that's easier: https://gist.github.com/geotom/6468534

  • Very cool - I was hoping to create a virtual layer so users could go to a directory and see all available layers that they could use. But this is still an effective method, thanks alot.
    – Ando
    Commented Sep 11, 2013 at 2:31
  • It looks like it should be possible with OGR GeoJSON driver in a virtual layer... I hacked at it with great fury. No joy. And GDAL/OGR documentation is not helpful either.
    – Scro
    Commented Sep 11, 2013 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.