3

I am using ogrinfo to find out information about a shapefile

ogrinfo -so -al 'C:/test/test_shapefile.shp'

This obviously gives me a large summary, but I'm wondering is there any way to specify that I only want information regarding the extents or epsg for example?

1

1 Answer 1

4

The ogr2ogr utility is a general purpose tool and all that it can do is documented in https://gdal.org/programs/ogrinfo.html. There are some options for limiting the amount of output (-nocount -noextent nogeomtype) but their main purpose is to make ogrinfo faster because with some formats getting such information may require reading every single feature from the source data.

Information that fits on one line and has a unique keyword can be filtered from the output with sed of find

ogrinfo -so -al test.shp|find "Extent"
Extent: (7156409.373471, 207.123904) - (7156409.373471, 207.123904)

Python scripting is probably the best option for getting just the desired information. There is a Python version of ogrinfo in the section of Python demos in GitHub https://github.com/OSGeo/gdal/blob/master/swig/python/gdal-utils/osgeo_utils/samples/ogrinfo.py. It might be a good starting point for an own custom script.

8
  • ogrinfo -so -al test.shp|find "Extent" doesn't appear to work for me in the command-line. It doesn't return an error, just nothing Commented Apr 26, 2022 at 13:55
  • I've also had a look at the python version, but I can't make out where to specify my path to the shapefile Commented Apr 26, 2022 at 14:12
  • It is the first argument, just like with the ogrinfo executable python ogrinfo.py c:\data\test.shp
    – user30184
    Commented Apr 26, 2022 at 14:26
  • I'm sorry, I must be being silly, but I can't get it to work Commented Apr 26, 2022 at 18:56
  • 1
    If you're getting a NameError, you tried to run ogrinfo.py from a python prompt instead of a command line.
    – user2856
    Commented Apr 26, 2022 at 21:52

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.