3

I want to calculate the union/merge two overlapping polygons using ogr2ogr (as I have 300+ to do). I want the output to be the same as you would get if you used the 'Merge shapefiles to one' command in QGIS (Vector > Data Management Tools > Merge shapefiles to one). Does anyone know whether or how this is possible?

My input files are two vector grids populated with statistics - I want to merge two files but keep the attributes of both. The files are exactly the same dimensions and the column names within the two files are different.

I've tried ogr2ogr -update -append etc... but this only allows me to keep one set of attributes.

  • There is a new option -addfields in ogr2ogr gdal.org/ogr2ogr.html. I would try it. If it does not work with shapefiles use spatialite in between. – user30184 Jul 2 '14 at 8:34
  • Do you know if there's a way to use -addfields without producing NULL values? Because I'm planning to do calculations with the output, the NULL values would be better set to 0... – AMK Jul 2 '14 at 9:43
  • I do not believe that you can do it but you can simply update the null values afterwards into whatever you want. It is surprising but the tool to use is ogrinfo and it goes like ogrinfo testdata.shp -dialect SQLite -sql "update testdata set nulltestcolumn=0 where nulltestcolumn is NULL" – user30184 Jul 2 '14 at 15:47

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.