Fiona: Enabling GRASS support in Fiona

Created on 5 Jun 2019  路  4Comments  路  Source: Toblerity/Fiona

Expected behavior and actual behavior.

I expected to be able to read GRASS vector datasets, as my GDAL version supports it.

Steps to reproduce the problem.

  • I'm using GDAL installed from ubuntuGIS PPA which has prebuilt GRASS plugins.
    From a python3 environment I can successfully read GRASS vector datasets using the python GDAL bindings:
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import ogr 
   ...: cnt = ogr.GetDriverCount() 
   ...: formatsList = []  # Empty List 
   ...:  
   ...: for i in range(cnt): 
   ...:     driver = ogr.GetDriver(i) 
   ...:     driverName = driver.GetName() 
   ...:     if not driverName in formatsList: 
   ...:         formatsList.append(driverName) 
   ...:  
   ...: formatsList.sort() # Sorting the messy list of ogr drivers 
   ...:  
   ...: for i in formatsList: 
   ...:     print(i) 
   ...:                                                                                                                                                                         
ARCGEN
AVCBin
AVCE00
AeronavFAA
AmigoCloud
BNA
CAD
CSV
CSW
Carto
Cloudant
CouchDB
DGN
DXF
EDIGEO
EEDA
ESRI Shapefile
ESRIJSON
ElasticSearch
GFT
GML
GMLAS
GPKG
GPSBabel
GPSTrackMaker
GPX
GeoJSON
GeoJSONSeq
GeoRSS
Geoconcept
Geomedia
HTF
HTTP
Idrisi
Interlis 1
Interlis 2
JML
JP2OpenJPEG
KML
LIBKML
MBTiles
MSSQLSpatial
MVT
MapInfo File
Memory
MySQL
NAS
NGW
ODBC
ODS
OGR_DODS
OGR_GMT
OGR_GRASS
OGR_OGDI
OGR_PDS
OGR_SDTS
OGR_VRT
OSM
OpenAir
OpenFileGDB
PCIDSK
PDF
PGDUMP
PGeo
PLSCENES
PostgreSQL
REC
S57
SEGUKOOA
SEGY
SOSI
SQLite
SUA
SVG
SXF
Selafin
TIGER
TopoJSON
UK .NTF
VDV
VFK
WAsP
WFS
WFS3
Walk
XLS
XLSX
XPlane
netCDF
  • I tried to build FIONA from source, and manually add GRASS in the list of supported drivers
In [2]: !cat /usr/local/lib/python3.7/dist-packages/fiona/drvsupport.py | grep GRASS                                                                                            
    # GRASS     GRASS   No  Yes     No, needs libgrass
    ("GRASS", "r"),
  • To build Fiona I used the following command from inside the src tree of a clone of the Fiona GitHub master branch:
sudo GDAL_CONFIG=/usr/bin/gdal-config pip3 install --no-binary fiona .
  • I checked that Fiona was built agains the right version of GDAL:
In [3]: !fio --gdal-version                                                                                                                                                     
GDAL, version 2.4.0

In [4]: !gdal-config --version                                                                                                                                                  
2.4.0
  • No luck .. the GRASS drivers are not available from Fiona:

In [5]: import fiona
...: from fiona._drivers import GDALEnv
...: env = GDALEnv()

In [6]:

In [6]: env.start().drivers().keys()
Out[6]: dict_keys(['OGR_GRASS', 'PCIDSK', 'netCDF', 'JP2OpenJPEG', 'PDF', 'MBTiles', 'EEDA', 'ESRI Shapefile', 'MapInfo File', 'UK .NTF', 'OGR_SDTS', 'S57', 'DGN', 'OGR_VRT', 'REC', 'Memory', 'BNA', 'CSV', 'NAS', 'GML', 'GPX', 'LIBKML', 'KML', 'GeoJSON', 'GeoJSONSeq', 'ESRIJSON', 'TopoJSON', 'Interlis 1', 'Interlis 2', 'OGR_GMT', 'GPKG', 'SQLite', 'OGR_DODS', 'ODBC', 'WAsP', 'PGeo', 'MSSQLSpatial', 'OGR_OGDI', 'PostgreSQL', 'MySQL', 'OpenFileGDB', 'XPlane', 'DXF', 'CAD', 'Geoconcept', 'GeoRSS', 'GPSTrackMaker', 'VFK', 'PGDUMP', 'OSM', 'GPSBabel', 'SUA', 'OpenAir', 'OGR_PDS', 'WFS', 'WFS3', 'SOSI', 'HTF', 'AeronavFAA', 'Geomedia', 'EDIGEO', 'GFT', 'SVG', 'CouchDB', 'Cloudant', 'Idrisi', 'ARCGEN', 'SEGUKOOA', 'SEGY', 'XLS', 'ODS', 'XLSX', 'ElasticSearch', 'Walk', 'Carto', 'AmigoCloud', 'SXF', 'Selafin', 'JML', 'PLSCENES', 'CSW', 'VDV', 'GMLAS', 'MVT', 'TIGER', 'AVCBin', 'AVCE00', 'NGW', 'HTTP'])

Operating system

Distributor ID: Ubuntu
Description:    Ubuntu 19.04
Release:    19.04
Codename:   disco

Fiona and GDAL version and provenance

  • Fiona version 1.8.6 built from source (GitHub master branch - commit # 417b94c21deb4745a39313891f51f67ebe98b871)
  • GDAL 2.4.0 installed via apt-get from Ubuntu GIS PPA

Most helpful comment

@epifanio GRASS format support isn't enabled by default, but you can turn it on after you import fiona by executing fiona.supported_drivers["GRASS"] = "r".

All 4 comments

@epifanio GRASS format support isn't enabled by default, but you can turn it on after you import fiona by executing fiona.supported_drivers["GRASS"] = "r".

super cool! I didn't know It was possible to enable it without touching the src code.
The line that worked for me is:

import fiona
fiona.supported_drivers["OGR_GRASS"] = "r" 

then the line below works as expected!

import geopandas as gpd
gpd.read_file('/GRASSDB/LOCATION_NAME/MAPSET/vector/layername/head')

Thanks!

@sgillies Is there a reason it is not enabled by default? Not all aspects of such files supported in fiona's data model?

@jorisvandenbossche incomplete driver implementations have been a support headache for GDAL/OGR (CAD formats especially) and I didn't want to enable all of the marginal and odd drivers in Fiona and invite the headache here. I kept GRASS out, mainly because I'm not very familiar with it and am unsure of how well it works. OGR can't write the GRASS format, so it's not fully functional.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kylebarron picture kylebarron  路  5Comments

sgillies picture sgillies  路  4Comments

SeanDS picture SeanDS  路  3Comments

keithamoss picture keithamoss  路  3Comments

nyotta picture nyotta  路  7Comments