TransWikia.com

Filtering attributes in a shapefile using a common ID from an Excel file

Geographic Information Systems Asked by Pescariz on April 3, 2021

I am using QGIS 2.18.11 and I have a shape layer with lines and polylines I need to review; but not all of them, only certain ones. The ones I need to review are marked in a specific field (rev = 0 or rev = 1) in an Excel file (.xlxs). Both data files share the same ID, so I could connect them.

How I would normally do this is performing a join in my shapefile with the Excel file using the ID; then I would add a new field in the shapefile and update it with the “rev” field data; I would then close the excel file so I can keep on working on it in parallel; finally I would filter my shapefile with “rev”=1, and there I have the lines and polylines I need to review.

Is there a faster way? Also a way that does not make me edit the shapefile (by creating that “rev” field)?

3 Answers

If you can connect the shapefile with Excel file using join by attribute, then you can simply save the joined file as a new shapefile and the link will exist permanently.

In this case, Rev field which exist in Excel file will be written / transferred to shapefile and you can filter the new shapefile by Rev field.

Answered by ahmadhanb on April 3, 2021

You can temporary join table to your shapefile via Joins tab in layer properties.

  1. save your table as .csv
  2. load the CSV using Add Delimited Text Layer...
  3. go to Joins tab in shapefile layer properites, and hit the + button
  4. make a join by setting your id

enter image description here

Done, the CSV values append to your shapefile remaining in CSV (not writing to shapefile). You can also edit the CSV values in external spreadsheet editor (Calc, Excel, etc.). When you remove the CSV from your QGIS project, the connection (attributes from shapefile) is also removed.

Answered by Oto Kaláb on April 3, 2021

The only faster way of doing this beyond the other answers is to automate it using python/pyqgis (creating the join, iterating through the join layer and looking for successfully joined features, and commuting the attribute edit). Here's a tutorial on the joining part.

https://www.qgistutorials.com/en/docs/performing_table_joins_pyqgis.html

The other parts you should be able to find more code examples by using various keyword searches like "pyqgis commit edit" or "pyqgis get layer features".

Answered by artwork21 on April 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP