[GIS] QGis import partial PostGIS layer using query builder

postgispostgresqlqgisquery

I'm sorry, but I'm terribly new to the GIS scene (and PostGIS & QGis). I have loaded a whole bunch of OpenStreetMap data into a PostGIS database and successfully drawn a map using Mapnik. Now I want to explore the data in my PostGIS database using QGis.

I have successfully connected QGis to my remote PostGis DB and QGis lists the OSM tables. The query builder also displays all sorts of OpenStreetMap attributes and values.

My issue comes when clicking the "Add" button: I assume that QGis is trying to load the complete DB table, this step takes very long (and could be eating a lot of expensive South African bandwidth). I am really just interested in my tiny university campus for testing purposes. I don't yet know how to use the query builder to limit QGis' DB query to a certain latitute/longitude bounding box.

The QGis user manual wasn't helpful to solve this nooby question, sorry.
Thanks!

Best Answer

You can limit the load with "Build Query" button on the "Add Postgis table dialog". On the bottom where it says "SQL where clause" write:

the_geom && ST_SetSRID(ST_MakeBox2D(ST_Point(14,43),ST_Point(16,46)),4326)

Replace points for the BBOX of your choice. This will work assuming that your geometry column is the_geom, otherwise, replace that with you geometry column name.

Related Question