How can I query polygon features that intersect other polygon features in QGIS? I have ZIP code areas and city areas, and I would like to list all the ZIP codes that intersect the city areas. Example: San Antonio= 78209,78258,78259,78250, etc.
I've been looking for a method for a while that can do this in QGIS, I tried "list unique values and union" commands in the vector tools and no luck. I know you can do a Union in ArcMap Pro but I don't have that software here. I was also able to do this in GeoMedia Pro years ago. I am unable to figure out in QGIS how to do some polygon vs polygon analysis.
I am still having problems with this, I was able to create an intersection layer but I can't figure out how to associate the results back to the city area feature. I would like to add a field to City_Area which would list the ZIP Code names separated by comma. (City_A=78205,78204,78203,78201)
Answer
One solution is to create a Virtual Layer and write some SQL.
Type the following query into the Query section of the dialog:
SELECT c.geometry, c.CITY_NAME, group_concat(z.code) AS ZIP_ids
FROM ZIPCODE z, CITY_AREA c
WHERE ST_Intersects(z.geometry, c.geometry)
GROUP BY c.CITY_NAME;
Adjust field names in the query. For example, I assumed ZIP codes are stored in the code
field of your ZIPCODE layer. Test the query.
Choose proper values for other options such as Geometry column, type, and CRS. Finally, click OK
.
You should get a new layer with concatenated ZIP ids for each CITY_AREA.
No comments:
Post a Comment