Search code examples
pythonpython-3.xgdalgeorasterio

Read OpenAir File using Python GDAL


I need to read OpenAir files in Python.

According to the following vector driver description, GDAL has built-in OpenAir functionality: https://gdal.org/drivers/vector/openair.html

However there is no example code for reading such OpenAir files. So far I have tried to read a sample file using the following lines:

from osgeo import gdal
airspace = gdal.Open('export.txt')

However it returns me the following error:

ERROR 4: `export.txt' not recognized as a supported file format.

I already looked at vectorio however no OpenAir functionality has been implemented.

Why do I get the error above?

In case anyone wants to reproduce the problem: sample OpenAir files can easily be generated using XContest: https://airspace.xcontest.org/


Solution

  • Since you're dealing with vector data, you need to use ogr instead of gdal (it's normally packaged along with gdal)

    So you can do:

    from osgeo import ogr
    
    ds = ogr.Open('export.txt')
    layer = ds.GetLayer(0)
    featureCount = layer.GetFeatureCount()
    
    print(featureCount)
    

    There's plenty of info out there on using ogr, but this cookbook might be helpful.