I have a vector file "map.shp" with a field ID. I have an attribute table (data.txt) with the following fields: ID, value1, value2. The field ID is the same in both files.

I want to update map.shp by adding a new column and get the values from an attribute table ("data.txt").

How I could that with ogr in command line?

Since I don't have 2 shapefiles (vector layers).

  • Are you open to use Python for this or does it necessarily need to be using the command line? – Marcelo Villa Feb 23 at 22:01
  • @MarceloVilla I'd prefer command line, but yes I am open to use python , too. So, please give any information you have. Thank you – Nat Feb 24 at 16:49
  • 1
    You should be able to do it with ogrinfo and the -sql parameter by using OGR SQL. Read about ALTER TABLE and JOIN gdal.org/ogr_sql.html, – user30184 Feb 24 at 20:37
  • Thank you @user30184 this worked using : ogr2ogr -sql "SELECT map.ID,data.CO from map LEFT JOIN 'data.dbf'.data ON map.ID=data.ID" "output.shp" "map.shp". However, could I define the names of the columns in the output file? For example column CO got the name "data1". I tried to put "CO" or 'CO' in the select option but it didn't work. – Nat Feb 24 at 23:21
  • 1
    Read about field name alias gdal.org/ogr_sql.html and try with select data.CO AS CO... – user30184 Feb 25 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.