This repository focusses on the development of an OpenDRIVE driver for the OGR Simple Features Library. By extending GDAL/OGR with the ability to read OpenDRIVE XML files, a broad and well-established toolset of GIS functions will be made available for OpenDRIVE processing. This OGR extension is based on the work by Orozco Idrobo (2015) and Scholz et al. (2017). Currently, the still prototypical OpenDRIVE driver is not yet integrated into the official GDAL distribution. Steps to built the driver as a shared library against GDAL to provide a pluggable extension are described below.
With OpenDRIVE version 1.4 the specified coordinate reference system - given as PROJ.4 string - is correctly interpreted during geometry creation. Different MultiLineString
, Point
and Polygon
layers are created for the desired element output. Details on driver capabilities can be found in the driver documentation.
Geometry:
- Specify point sampling distance for geometries as layer creation option
- Create 3D geometries from polynomial OpenDRIVE elevation profile
- Add
Point
layer for road objects (e.g. signals, signs) - Add
Polygon
layer for parking spaces - Add
Polygon
layer for driving lanes - Add additional
LineString
layer(s) to contain- driving lane boundaries
- road marks
- linear objects (e.g. guardrails, barriers)
- Implement sampling of
spiral
geometries, with bothcurvStart
andcurvEnd
!= 0
Misc:
- Catch invalid XODR file path ("terminate called after throwing an instance of 'xsd::cxx::tree::parsing'")
- Ensure proper resource deallocation
We tested on Ubuntu Linux 20.04 x64 (gcc 9.3.0) and Windows 10 x64 (Visual Studio 15 2017). Get started by cloning our ogr/xodr branch:
git clone https://github.com/DLR-TS/gdal.git -b ogr/xodr --single-branch <gdal>
If needed, substitute <gdal>
with the desired path name to clone into.
The XODR driver is tested to work for GDAL 3.x. It depends on the following libraries:
- odrSpiral
- xodr
- GEOS; on Windows we recommend simply using the development package distributed with OSGeo4W
- PROJ >= 6; on Windows we recommend simply using the development package distributed with OSGeo4W
- SQLite3; on Windows we recommend simply using the development package distributed with OSGeo4W
- Xerces-C; on Windows we recommend simply using the development package distributed with OSGeo4W
Building it is divided into
- building the original GDAL base library which we link our shared extension against, followed by
- building the actual OpenDRIVE driver as shared library extension of GDAL/OGR.
Install dependencies:
sudo apt install libgeos-dev
sudo apt install libgeos++-dev
sudo apt install libproj-dev
sudo apt install libsqlite3-dev
In the following steps we basically follow the official GDAL building instructions for Unix. Configure GDAL to support creation of shared libraries. At least for our Ubuntu 20.04 test environment we also had to disable libtool because it caused problems during later linking of the driver shared library. With --prefix
you specify the target directory for the resulting binaries and library:
cd <gdal>/
./configure --prefix ~/dev/gdal/build -enable-shared --without-libtool --with-geos=yes
Check the output for successful recognition of geos and xerces. For Debug configuration append --enable-debug
. Build with
make -f GNUmakefile
followed by a
make -f GNUmakefile install
which copies the resulting GDAL binaries and library into the specified --prefix
directory.
Navigate into the OpenDRIVE OGR driver directory
cd <gdal>/ogr/ogrsf_frmts/xodr/
Configure the paths for all required Unix dependencies in XODRmake.opt
. Then
make -f GNUmakefile plugin-install
This will build a shared library of the plugin and automatically copy it into GDAL's plugin directory relative to the CMake --prefix
directory specified in the previous section.
We basically follow the official GDAL building instructions for Windows. Things have gotten easier starting from GDAL 2.3.x. where GDAL provides a comfortable script generate_vcxproj.bat
to generate project definitions for recent Microsoft's Visual Studio editions. An exemplary project for Visual Studio 2017 x64 can be generated from the "VS2017 x64 Native Tools Command Prompt" as follows:
generate_vcxproj.bat 15.0 64 gdal_vs2017
Now configure your GEOS and Xerces dependencies by adding the corresponding include directory and library paths into a new lokal NMake configuration file nmake.local
. It should contain something like the following (consider nmake.opt
as a reference):
GDAL_HOME = D:\dev\gdal\build
OSGEO4W_DIR = C:\OSGeo4W
# GEOS
GEOS_DIR = $(OSGEO4W_DIR)
#GEOS_DIR = C:\tmp\dev\geos\distro
GEOS_INCLUDE = -I$(GEOS_DIR)\include
GEOS_CFLAGS = $(GEOS_INCLUDE) -DHAVE_GEOS
GEOS_LIB = $(GEOS_DIR)\lib\geos_c.lib
GEOS_CPPLIB = $(GEOS_DIR)\lib\geos.lib
GEOS_BIN_DIR = $(GEOS_DIR)\bin
# Xerces
XERCES_DIR = $(OSGEO4W_DIR)
#XERCES_DIR = D:\dev\xerces-c-3.2.3\distro
XERCES_INCLUDE = -I$(XERCES_DIR)\include -I$(XERCES_DIR)\include\xercesc
!IFNDEF DEBUG
XERCES_LIB = $(XERCES_DIR)\lib\xerces-c_3.lib
XERCES_DLL = $(XERCES_DIR)\bin\xerces-c_3_2.dll
!ELSE
XERCES_LIB = $(XERCES_DIR)\lib\xerces-c_3D.lib
XERCES_DLL = $(XERCES_DIR)\bin\xerces-c_3_2D.dll
!ENDIF
# PROJ >= 6
PROJ_INCLUDE = -I$(OSGEO4W_DIR)\include
#PROJ_INCLUDE = -IC:\tmp\dev\proj-6.3.2\distro\include
!IFNDEF DEBUG
PROJ_LIBRARY = $(OSGEO4W_DIR)\lib\proj.lib
#PROJ_LIBRARY = C:\tmp\dev\proj-6.3.2\distro\lib\proj.lib
!ELSE
PROJ_LIBRARY = $(OSGEO4W_DIR)\lib\proj_d.lib
#PROJ_LIBRARY = C:\tmp\dev\proj-6.3.2\distro\lib\proj_d.lib
!ENDIF
# SQLite3
SQLITE_INC = -I$(OSGEO4W_DIR)\include
SQLITE_LIB = $(OSGEO4W_DIR)\lib\sqlite3_i.lib
Build the base GDAL library with nmake
from the Visual Studio Command Prompt for the desired configuration. Attach DEBUG=1
for a Debug build:
nmake -f makefile.vc MSVC_VER=1910 WIN64=1
Lean back, enjoy a freshly brewed Lapsang Souchong and after a few minutes your raw GDAL library is built. To pack all executables and the library conveniently together, make sure to specify the desired output directory GDAL_HOME
in your lokal configuration file nmake.local
GDAL_HOME="D:\dev\gdal\build"
and run nmake install
afterwards
nmake -f makefile.vc MSVC_VER=1910 WIN64=1 install
Navigate into the OpenDRIVE OGR driver directory
cd <gdal>/ogr/ogrsf_frmts/xodr/
Configure the paths for all required Windows dependencies in the provided XODRnmake.opt
. Then
nmake -f makefile.vc MSVC_VER=1910 WIN64=1 plugin-install
This also copies the required Xerces DLL into GDAL's binary install directory.
GDAL/OGR is now extended by our OpenDRIVE driver which can be tested by running one of the utility programs, for example ogrinfo
:
Linux | Windows |
---|---|
cd <gdal>/build/bin/ |
cd <gdal>/build/bin/ |
./ogrinfo --formats |
ogrinfo.exe --formats |
This will print a list of supported OGR formats with the new format XODR -vector- (ro): OpenDRIVE
in the first row.
If you are on Linux, depending on your environment you might experience linker errors like:
error while loading shared libraries: libgdal.so: cannot open shared object file: No such file or directory
In such a case set the following environment variables:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<gdal>/build/lib
export GDAL_DRIVER_PATH=<gdal>/build/lib/gdalplugins
To convert reference lines of an OpenDRIVE file into, e.g., an ESRI Shapefile, use the provided utility ogr2ogr
:
ogr2ogr -f "ESRI Shapefile" CulDeSac.shp CulDeSac.xodr referenceLine
To convert the wohle OpenDRIVE file with all its different layers into a Geopackage:
ogr2ogr -f "GPKG" CulDeSac.gpkg CulDeSac.xodr
Details on driver capabilities can be found in the driver documentation. For advanced debug console output of those utility programs and the implemented drivers add CPL_DEBUG=ON
to your running environment.
To easily add new drivers to GDAL as shared libraries GDAL provides the GDALDriverManager with its AutoLoadDrivers()
function. The FileGDB driver serves as good orientation for shared library development in GDAL/OGR, see RegisterOGRFileGDB()
in FGdbDriver.cpp
. Also consider the GDAL building notes.