I have to merge a lot of shapefiles into one great shapefile.
So I want to compare the properties of the attribute tables to see if there are differences between the tableproperties of each shape (type, length, precision, name, etc). With the intention to standardize all the shapefiles


enter image description here

Is there a way to print out a list of the table properties as shown in the tab 'fields' or to export the properties into an .xls or .dbf?

Or is there an automated way to do the standardisation? (Perhaps this is a subject for a new thread...)

I am using QGIS 1.8 (QGIS 2.2 is also possible).


  • Indeed, I meant print it on paper. But if you can suggest me how to do it in an easier way. Please tell me.
    – PieterB
    Feb 26, 2014 at 12:30
  • I could only find answers about Arc but it should work similar for QGIS: gis.stackexchange.com/questions/54034/… Feb 26, 2014 at 15:20
  • Can you elaborate a bit more what you mean by "properties of the attribute table"? Preferable a list of properties which you would like to compare - and how you would like to compare them. What will be the end result of your analysis? Feb 27, 2014 at 11:54
  • @ Matthias: I added some more information in my answer
    – PieterB
    Feb 27, 2014 at 13:12
  • @Spießbürger I've refined further my answer providing also a Processing script solution. Hope this helps. Mar 7, 2014 at 8:51

5 Answers 5


OSGeo4W shell solution

IMHO the simplest way to extract the attribute table properties (schema) consists into opening the OSGeo4W shell ('cause you're on win os), change directory to your data folder and simply type something like:

ogrinfo -so inputLayerName.shp inputLayerName

It will show you the summary information like projection, schema, feature count and extents. Then, because you have a bunch of shapefiles, you can do a FOR cycle like the following:

FOR %f IN (*.shp) DO ogrinfo -so %f %~nf >> properties.txt

This returns one txt-file with the properties of all the shapefiles in a directory (because the output redirection with >> appends each single output to the properties.txt file).

Alternatively, if you're interested in one properties file for each shapefile:

FOR %f IN (*.shp) DO ogrinfo -so %f %~nf > %~nf_properties.txt

About the standardization, there are several techniques. I suggest you to use the RESIZE layer creation option after the merge in order to resize fields to their optimal size (e.g. text fields with excessive length will be shortened). For instance:

ogr2ogr -lco RESIZE=yes merge_resized.shp merge.shp 

Processing script solution

Open the Processing toolbox in QGIS, create a new script (clicking on Scripts --> Tools --> Create new script) and type:

##ogrinfo (summary only)=name
##output=output file

import os, subprocess

head, tail = os.path.split(input)
inputname = os.path.splitext(tail)[0]
cmd = 'ogrinfo -so ' + input + ' ' + inputname + ' > ' + output
subprocess.check_call(cmd, shell=True)

Save it as you like, e.g. ogrinfo_so.py. Then, a new script ogrinfo (summary only) will appear in the Processing toolbox --> Scripts --> User script group. It can be executed as it is or in batch mode.

The same operation is possible in order to resize the field length, as described before:

##Resize fields=name
##output=output vector

import subprocess

cmd = 'ogr2ogr -lco RESIZE=YES ' + output + ' ' + input 
subprocess.check_call(cmd, shell=True)

A new script called Resize fields will be available in the Processing toolbox --> Scripts --> User scripts group. Enjoy it!

  • Interesting! And how can i get the info out of the OSGeo4W shell into a text- or excelldocument? ps: is there beginnersdocumentation on how to use that OSGeo4W shell?
    – PieterB
    Mar 5, 2014 at 13:37
  • The OSGeo4W Shell is a batch / DOS Shell, so you can select the text, copy it and paste into a text file Mar 5, 2014 at 13:47
  • 1
    edit was made by @PieterB (thanks to him). I just corrected a typo.
    – simo
    Mar 6, 2014 at 14:37
  • 1
    @afalciano: Thanks for introducing me into the world of OSGeo4W. There is still a lot to learn...
    – PieterB
    Mar 6, 2014 at 14:45

Shapefiles hold their attributes in .dbf files, can you not just open the .dbf file directly in a program like libreoffice calc and then print from there? If you don't have too many files this should work.

Another option would be to write a python script that prints out (to the console) the attributes of features directly, or even compares them for you. You can access the attributes of a feature like this:

it = vectorLayer.getFeatures()
for eachFeature in it:
    attributes = eachFeature.attributes()

You would need to do this for each shapefile your comparing and see if

eachFeature.attributes() == eachOtherFeature.attributes()

more info here: http://www.qgis.org/en/docs/pyqgis_developer_cookbook/

  • If more people would be interested in a tool like this perhaps we could crowd-fund the development. Feb 27, 2014 at 15:29
  • That sounds like an interesting idea
    – user24956
    Feb 27, 2014 at 15:36
  • They should have a form for that on the QGIS website :) Feb 27, 2014 at 16:25

Following on the .dbf theme have you looked for .dbf comparers directly? I haven't found a free solution immediately, but something like: dbfCompare


Try some of the DBF metadata extractors available. Most of them support command line mode, so multiple metadata extraction can be run in batch.

http://geology.usgs.gov/tools/metadata/tools/doc/dbfmeta.html http://sco.wisc.edu/wisclinc/metatool/dbfmeta.htm


Just open the .dbf file in Libreoffice Calc or Excel just save it as a new file. I saved over it once and the shapefile was no good.

Your Answer

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

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