16

I'm trying to use ogrinfo to get some details on a shapefile I downloaded. Currently, the only way I know how to do this is to load it into QGIS and manually click around to find any information on it, like opening the attribute table.

I just want to be able to see any metadata is tagged along with the features. If I do:

ogrinfo -al USA_adm0.shp

I can see at the beginning there is a lot of useful information, but then it flies past with all the feature data.

Can someone help me out?

EDIT

This is what I get on my mac using the -ro and -so flag, doesn't seem to be much help.

->ogrinfo -ro -so USA_adm0.shp
INFO: Open of `USA_adm0.shp'
      using driver `ESRI Shapefile' successful.
1: USA_adm0 (Polygon)
5
  • 1
    There are various ways in which you can see this info in an userfirendly manner, but this will depend upon your OS. You could for example pipe the output to a file, or use your bash/command line's pagination feature. We need more information about your OS, and where you are running the command. Commented Mar 2, 2014 at 14:38
  • 2
    In regards to your EDIT part, don't forget to look closely at the usage of ogrinfo --help where it needs you to specify ogrinfo datasource_name layer and you forgot to add a layer (so it listed the layers for you instead). Using -al, it will list info on All Layers without you specifying a layer.
    – SaultDon
    Commented Mar 3, 2014 at 3:40
  • Hi dvreed77, did you resolve this issue? there doesn't seem to be an answer on this thread that addresses the fact that -ro -so doesn't do much. I am experiencing the same problem.
    – Vlad
    Commented Jun 29, 2018 at 16:57
  • 1
    Hi @Vlad, the -geom=NO flag did the trick for me
    – dvreed77
    Commented Jun 30, 2018 at 3:03
  • ogrinfo -al -ro -so shapefile.shp worked for me to get all the information
    – m13r
    Commented Apr 20, 2022 at 12:24

2 Answers 2

25

ogrinfo can shorten the output considerably using the -so flag.

-so: Summary Only: supress listing of features, show only the summary information like projection, schema, feature count and extents.

So ogrinfo -ro -so file.shp should give a summary of the metadata.

And

-al: List all features of all layers (used instead of having to give layer names as arguments).

Would certainly give you a lot of info on the other hand if used by itself!

And if you want to see metadata for individual or a range of features, there is the -fid, -where, and -sql flags which do that.

Lastly, -geom will act as a master toggle for the geometry info.

-geom={YES/NO/SUMMARY}: (starting with GDAL 1.6.0) If set to NO, the feature dump will not display the geometry. If set to SUMMARY, only a summary of the geometry will be displayed. If set to YES, the geometry will be reported in full OGC WKT format. Default value is YES.

There is a FAQVector Wiki with examples for GDAL command line utilities that also gives some other tips =)

3
  • Thanks SaultDon. I edited my post to show you what happens when I try the -so flag
    – dvreed77
    Commented Mar 2, 2014 at 21:40
  • 1
    It seems the -geom=NO is something that I was expecting. Thanks!
    – dvreed77
    Commented Mar 2, 2014 at 21:49
  • This just prints the name of the first layer for me. Why is that? Versions prior to 3.4.1 behaved the way like you stated. Commented Jan 13, 2022 at 21:01
7

You may try:

ogrinfo -al USA_adm0.shp >> output.txt

All the information will be redirected into a text file called output.txt in the folder in which the command was invoked (but a richer relative or absolute path can also be used)

2
  • 1
    OR; > ogrinfo -al USA_adm0.shp | head -30 (top 30 lines)
    – Gagan
    Commented Apr 6, 2019 at 5:36
  • Thanks. Other command did not work for me with GDAL 3.4.1 Commented Jan 13, 2022 at 21:00

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