I have a PostGIS database with 30 million gazetteer points, each have an X Y coordinate. I want to query this and then zoom map to location. However, I don't want to add the data to the project because it takes forever to load 30 million points.

I started looking at creating my own QGIS plugin but all tutorials I have seen, seem to add vector data directly to the map canvas first.

Pseudo Code:

Click button
Dialogue Box 
Enter PostGIS database connection fields (host, dbname, user, password)
Enter gazetteer value
Finds match
Zooms and centers on point.

If anyone has a better idea or knows of a plugin that would be very useful

  • 1
    Tim, how are you getting on with this project? I'd be interested to hear more and i'm after writing a similar plugin myself. – geosmiles Mar 7 '12 at 8:12

Moderately easy :) The ZoomToPoint plugin can show you how to do half of this - you basically call mapCanvas.setExtent(rect) where rect is a QgsRectangle of the area to zoom to.

To get the area, just do a Postgis query and get back the result... Easier said than done... probably need to use psycopg2 for this bit unless there's a database-independent interface in Qgis somewhere...

Another thought is that you could create a VIEW on your query, and have that return the bounding box (beware if there's only one point in your query though) as one polygon with some PostGIS geometry conversions. Then load that as a layer (it will just be one polygon, not millions of points), then zoom to layer extent (from the Python API), and then delete the layer.

Hope that helps. Have a look at some of the SQL-related plugins.


When you click in the "add postgis layers" dialog, and after clicking "connect", you can select one o the table and enter a query (column "sql") and so filter what you need before adding it to the canvas.

  • Hi Giovanni I have seen that and used it in the past. However I dont want any actual data to be loaded onto the map, I would just like to orientate the map to the location. – Tim Martin Feb 21 '12 at 10:21

If anyone is still looking for this, I'd suggest taking a look at the gazetteer plugin developed by @Nathan W at https://github.com/AstunTechnology/QGIS-Gazetteer-Plugin. It might need some tweaking to connect to a database, but the rest of the desired functionality is there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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