8

I have two layers, one (A) has point features and the other (B) has polygons.

How do I produce a new table with some (the ID) or all the fields from the A table and some (the area code) or all from the B table where the B polygon contains the A point?

I am using QGIS.

12

It's possible to do a join on location ("where the B polygon contains the A point") using "Join attributes by location" from "Vector" menu. The resulting layer will contain all attributes from both layers.

A faster alternative is SAGA Add polygon attributes to points which is available through the Processing toolbox in QGIS.

0

Through SQL

You will need access to the data and access to a SQL db, you can derive the information via a simple SQL query. This example was written for SQL Server in TSQL.

The query will list the Hydrant (Layer A) and Fire District (Layer B) IDs along with common identifiers and the geometry definition of each. Because it has the geometry defined, if you were to insert these results into a table you can then review them in your map.

SELECT WHYDRANT.OBJECTID AS HYDID,
    WFIREDISTRICT.OBJECTID AS FDID, WHYDRANT.UNID AS UNID,
    WFIREDISTRICT.UNID AS FDUNID, WHYDRANT.SHAPE
FROM WFIREDISTRICT 
    INNER JOIN WHYDRANT ON 
        WFIREDISTRICT.SHAPE.STContains(WHYDRANT.SHAPE()) = 1

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.