1

Is there any way in QGIS where we can auto populate new layer feature_attributes from parent layer? We have layer A as here. It has attributes including: f_id, class_name, class_type, r_total.

We now make a Polygon (B) over it using Toggle Editing --> Add Feature as here .

The new polygon B has null values in f_id, class_name, class_type, r_total attributes.

How do we auto fill these feature attributes values in Polygon B so that it matches with layer A values. (Auto fill needs to be done as this process has to be carried out for large number of tiles.)

  • This can be done if your data resides in a PostGIS database (or any spatial database) by means of triggers. If as you say you have a large number of tiles (large is relative), it might be a good thing to consider using a spatial database. – Techie_Gus Mar 5 at 9:09
  • @Techie_Gus Yes, data resides in a PostgreSQL database. So, each tile is opened through geometry column in table from database. Now, we need to make new polygon on each tile and when the user completes the polygon, the attributes from layer 1 should get reflected in Polygon B (instead of asking from user each time). – Sajjadmanal Mar 5 at 9:20
  • Yes, can be done, as long as your PostgreSQL database has the PostGIS extension. You need to look at triggers and the ST_Within function. – Techie_Gus Mar 5 at 9:31
  • @Techie_Gus Could you please explain more on how to use that here? – Sajjadmanal Mar 5 at 10:17
1

After multiple attempts, ended with the below PostgreSQL query to have suitable feature attributes:

 Update B set 
 f_id = old.f_id, class_name = old.class_name,
 class_type = old.class_type, r_total = old.r_total 
 from B new, A old 
 where st_within(new.geom, old.geom)

Here, the selective feature attribute values of table A are copied to that of table B. table A and table B are the tables of layer A and polygon B respectively in the database.

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.