Skip to content

Instantly share code, notes, and snippets.

@creg-ny-baa
Last active December 22, 2015 11:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save creg-ny-baa/6468534 to your computer and use it in GitHub Desktop.
Save creg-ny-baa/6468534 to your computer and use it in GitHub Desktop.
View CartoDB data (from a public table) in QGIS 1.8. Substitute your user name and SQL, and paste it in the python console.
# Run in QGIS python console for read-only view of CartoDB table
# Substitute your user name and query on first two lines
cartoName = "" # PUT YOUR USER NAME IN THE QUOTES
cartoQuery = "" # PUT YOUR QUERY IN THE QUOTES
import urllib
cartoUrl = 'http://{}.cartodb.com/api/v2/sql?format=GeoJSON&q={}'.format(cartoName, cartoQuery)
response = urllib.urlopen(cartoUrl)
content = response.read()
layer = QgsVectorLayer(content, cartoName, 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(layer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment