TransWikia.com

Determining driver, spatial reference and other props from an open GDAL layer

Geographic Information Systems Asked by auslander on December 14, 2020

I have a very large network share full of data (raster, vector, sometimes mixed inside of geopackage and/or file geodatabase containers). I have a set of classes that crawl through it all and use arcpy.Describe() to extract from each dataset its datatype, extent and spatial reference system. That then goes into a single enterprise db layer that shows our spatial holdings and a bit of heritage data of each element.

I’d like to try making it open source for other users to run who do not have licenses. GDAL also offers me some more insight into what specific driver is being used, to further categorize the data, theoretically.

I’d like to avoid hardcoding around file extensions and ask GDAL (or fiona, or shapely, not picky here) instead – [update] because I don’t know what sort of files the indexer will encounter. Assuming a subset of the data, I can do something like this:

import gdal

filelist = [
    '/share/Data/Terrain/N43W072.hgt',
    '/share/Data/Terrain/N43W072_StrahlerOrder_8.tif',
    '/share/Data/Terrain/N43W072_Channels_Clipped.shp',
    '/share/Data/Terrain/N43W072_Channels.shp',
    '/share/Data/Network/NH/nh_road_network.gdb',
    '/share/Data/Network/MA/ma_road_network.gpkg'
]

for f in filelist:
    try:
        dataset = gdal.Open(f)
    except:
        # do stuff

but I am not clear how to then summon the properties of dataset (I’m presuming that the open dataset object holds the elements I’m looking for). I’ve looked at https://gdal.org/python/ but there is nothing I can find that says "here is how you get all the properties of an gdal.Open() object."

Ultimately the properties I want to see would be presented something like this:

{
    "driver": "GPKG",
    "driver_long_name": "GeoPackage raster"
    "type": "Raster",
    "extent": [(miny, minx), (maxy, minx), (maxy, maxx), (miny, maxx)]
    "CRS" : {'epsg:4326'}
}

One Answer

gdal.Info might be the simplest way:

ds = gdal.Open('/vsicurl/https://github.com/OSGeo/gdal/raw/master/autotest/gcore/data/3376.tif')
info = gdal.Info(ds, options='-json')
print(info.keys())

dict_keys(['description', 'driverShortName', 'driverLongName', 'files', 'size', 'coordinateSystem', 'geoTransform', 'metadata', 'cornerCoordinates', 'wgs84Extent', 'rat', 'bands'])

But if you want to figure out how to pull that information directly from the open Dataset object look at the methods that start with Get in the documentation for gdal.Dataset.

Answered by user2856 on December 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP