I expected to be able to read GRASS vector datasets, as my GDAL version supports it.
GDAL installed from ubuntuGIS PPA which has prebuilt GRASS plugins.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
FIONA from source, and manually add GRASS in the list of supported driversIn [2]: !cat /usr/local/lib/python3.7/dist-packages/fiona/drvsupport.py | grep GRASS
# GRASS GRASS No Yes No, needs libgrass
("GRASS", "r"),
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 .
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
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'])
Distributor ID: Ubuntu
Description: Ubuntu 19.04
Release: 19.04
Codename: disco
apt-get from Ubuntu GIS PPA@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.
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".