2

I am trying to build a QGIS modeler tool to do the following;

I have a parcel table with fields "OWNER" and "OWNERNO" where each owner has their own row in the table and the "OWNERNO" numbers them. (All other fields are the same in the rows.) I would like to collapse this table so that:

  • Owner=Bill, OwnerNo=1
  • Owner=Mike, OwnerNo=2

Becomes:

  • Owner1=Bill, Owner2=Mike

I have searched this forum but could not find an answer.

3
  • So you would want new columns like Owner1, Owner2 etc with only 1 row having a valid value? That doesn't make sense. Oct 2, 2019 at 17:26
  • You need a field with a shared ID. Do you have something like a "PARCELNO" field with a parcel number in it? What is that field called?
    – csk
    Oct 2, 2019 at 17:27
  • Is this a change you want to make to your data permanently, or is this something that you're using as an input to another process in your model? Oct 2, 2019 at 18:17

1 Answer 1

4
  1. Use the Field Calculator to create a new field, "OWNER1", with data type string(text), and the same field length as the "OWNER" field.

    Use this expression:

    If( "OWNERNO" = 1, "OWNER", NULL)
    

    Repeat the operation to create a field for each value in the "OWNERNO" field, changing the "OWNERNO" value in the expression each time.

    • Create the field "OWNER1" with this expression: If( "OWNERNO" = 1, "OWNER", NULL)
    • Create the field "OWNER2" with this expression: If( "OWNERNO" = 2, "OWNER", NULL)
    • Create the field "OWNER3" with this expression: If( "OWNERNO" = 3, "OWNER", NULL)
    • Create the field "OWNER4" with this expression: If( "OWNERNO" = 4, "OWNER", NULL)

    enter image description here

  2. Now use the Field Calculator to copy the "OWNER1" value from the one feature that has it to the other copies of that parcel. Use this expression to update the existing field, "OWNER1".

    maximum( "OWNER1","PARCELNO")
    

    enter image description here

    Repeat for every field.

    • Update the field "OWNER1" with this expression: maximum( "OWNER1","PARCELNO")
    • Update the field "OWNER2" with this expression: maximum( "OWNER2","PARCELNO")
    • Update the field "OWNER3" with this expression: maximum( "OWNER3","PARCELNO")
    • Update the field "OWNER4" with this expression: maximum( "OWNER4","PARCELNO")

    enter image description here

  3. Now consolidate the duplicate parcels, using either the Dissolve tool (choose "PARCELNO" as the dissolve field) or the Delete duplicate geometries tool.

    enter image description here

    This will create a new layer called Dissolved. Delete the fields "OWNER" and "OWNERNO" from the new layer. Be sure to export the new layer as a permanent data type (by default QGIS creates a temporary layer, which will be deleted when you close the project).

    enter image description here

If you have many layers, you might want to automate the process with a Processing Modeler. Just use the same processing algorithms and steps in the model as I described above. I didn't demonstrate that because setting up and troubleshooting a Processing Model is a giant pain in the [pick your favorite body part]. There are tutorials out there if you really want to do it this way. If you only have a few layers, setting up a model wouldn't be any faster than doing it manually for each layer.

Note: I assumed you have a field called "PARCELNO" which contains a Parcel ID Number that's unique for each parcel, but that identical for duplicates of parcels with multiple owners. Substitute the actual name of your Parcel ID Number field wherever I use "PARCELNO" here.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.