1

I’m a novice user of QGIS. I have searched this site and failed to find an ability to split a layer into new layers based on a secondary input.

I have a layer of buildings with no attributes. I want to devide them into new layers/files by zip code. I have a layer with zip codes. Both are in the same CRS. However when I use split or intersection operations it will cut the house in half if it crosses the zip code. Is there a way to retain the integrity of the house and have it duplicated into both zip code layers?

2

If you make a query using intersects operator your buildings objects will be duplicated as many times as they intersect zip code areas.

In the other hand if you use the centroid of the building in your query your building will be associated with only one zip code area.

In any case a query can return (among other things) the geometry of your objects (and eventually duplicate objects ...)

So an answer to your question is building the right query in the DB_manager of QGIS. Something like :

select building.geometry,zip_code.id from building, zip_code
where st_intersects (building.geometry, zip_code.geometry)

Adapt it according to your data structure.

To write your query go to : Database / Database Manager / Database Manager then Virtual Layers / Qgis Layers ...

1

Use the Join attributes by location tool to create a copy of the building layer with zip code values added.

  • Choose the option to "Create separate feature for each located feature (one-to-many)". This option will create a copy of each building that falls into multiple zip codes.

enter image description here

Use the Split Vector Layer tool to split the new layer based on the zip code field.

enter image description here

Notes:

  • The tools mentioned here are available through the Processing Toolbox.
  • The default output type of most processing tools is a temporary layer, which will be deleted when you close the QGIS project. Be sure to save any temporary layers that you want to keep before closing the project.

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.