0

I have two tables one with zip codes together with addresses (tableA) and another layer with zip codes and values (tableB), this layer for example has zip code = 1234567 and a value of 50, zip code 2345678 has a value of 22 etc. I need to find a way to randomly select 50 and 22 etc within those zip codes for the addresses to be able to add a new field or use an existing field to update with value of 1, or even better do add the value during the process. When aggregate for the zip codes of addresses (tableA) the sum of the field used should match with the layer of zip codes (tableB) and its values. Result for zip code 1234567 should be 50 randomly picked addresses (of hundreds that exist) added with value of 1 and for zip code 2345678 should have 22 randomly picked addresses with added value of 1. Its a lot of data for each zip code doing this manually, need to find a better way to execute this. Have not find any of the random features in QGIS being able to do this, you can only choose a number or percentage but not based on matching fields etc. Below is an "dummy" example of the two tables used. Address tableA:

zipCode address city
1234567 StreetA CityX
1234567 StreetB CityX
1234567 StreetH CityX
1234567 StreetB CityX
1234567 StreetC CityX
2345678 StreetD CityX
2345678 StreetF CityX
2345678 StreetK CityX
2345678 StreetA CityX
8901234 StreetA CityY
8901234 StreetB CityY

Zip code tableB:

zipCode amount
1234567 2
2345678 1
8901234 0

The result I'm looking for is this:

zipCode address city picked
1234567 StreetA CityX
1234567 StreetB CityX 1
1234567 StreetH CityX
1234567 StreetB CityX 1
1234567 StreetC CityX
2345678 StreetD CityX
2345678 StreetF CityX
2345678 StreetK CityX
2345678 StreetA CityX 1
8901234 StreetA CityY
8901234 StreetB CityY

Something like... select all addresses (tableA) with zipCode = 1234567 and randomly pick 2 (the value from the amount field "tableB") add a new field and for those picked set value = 1. End result when filter on picked = 1 you should have same amount of addresses for each zip code as the the amount (from zip code "tableB").

6
  • 4
    Sorry, I don't get it. Maybe restructuring your question can help to clarify.
    – MrXsquared
    Commented Sep 29, 2021 at 0:52
  • 1
    As it stands I think your question would benefit from being heavily revised to try and make what you are asking clearer. I recommend reviewing meta.gis.stackexchange.com/a/3353/115 for tips on how to structure a good question.
    – PolyGeo
    Commented Sep 29, 2021 at 4:44
  • Still quite confusing...
    – Babel
    Commented Sep 29, 2021 at 21:32
  • Can you please tell what format/ file type are your tables. Csv? Database tables or... ??
    – Ben W
    Commented Sep 30, 2021 at 10:20
  • uhh sorry for my bad explanation... they are two csv files in original format, imported to QGIS . The structure of each file looks as the example above but has much more data. The address file has 100 000 rows and 10 000 different zip codes (postal code) for the process to run thru. This process is not manageable by doing it manually.
    – QGIS-user
    Commented Sep 30, 2021 at 12:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.