3

I have 2 vector layers:

1) Polygons with parcel-boundaries

2) Polygon with project-boundaries

I want to query all the parcels that are within the project-area, using spatial query 'select parcels that intersect project-area'. Works fine, so far no problem.

The parcel-layer however is a layer that is often subject to changes. Instead of always renewing the spatial query, I want to embed the query in a layer or project. So that every time when I open the layer/project, I automatticaly get the current parcels within the project-area.

Can this be done in QGIS? In Mapinfo it was very easy but I'm walking over to Qgis, so it would be great not to lose this ability!

  • I assume you're using Shapefiles? – DPSSpatial Dec 9 '16 at 15:48
3

Using shapefiles, you can create a layer that is a 'memory spatial view' with the QGIS DB Manager.

If I have schools and neighborhoods, they show up as Virtual Layers in the QGIS DB Manager. I can create a query that only shows me the points within a particular neighborhood with this query:

enter image description here

Here's the SQL:

select 
sch.name
, n."NBHD_ID"
, sch.geometry
from 'schools' as sch
join 'neighborhoods'as n on ST_Intersects(sch.geometry, n.geometry)
where  n."NBHD_ID" = '41'

Now at the bottom of the DB Manager is the 'load as new layer' option. To get your query to save as a virtual layer, enable these settings:

enter image description here

Now in my map, the virtual layer shows up with the points defined in the query:

enter image description here

Now save this QGIS document.

Note: you might need the Memory Layer Saver plugin enabled.

So I did a test where in a new QGIS document I created a new school point in the same NHood my spatial 'view' queries. Sure enough when I opened up the QGIS document with the spatial view layer, the new point showed up!

I think this would work just fine for what you're describing.

  • Thanks! This helped me a lot to find a solution to my problem. – Jonas Dec 13 '16 at 11:52
  • @Jonas Great! If you could mark that as your answer, I'd appreciate it! – DPSSpatial Dec 13 '16 at 15:36

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.