In order to be able to connect OGR to the bcgw you need to make sure that the version of gdal/ogr you are using supports OCI (Oracle call interface). Most binary installs do not. This means in many cases you are stuck with the requirement to compile gdal yourself.
Compiling gdal on windows used to be a HUGE pain in the arse. Windows 10 introduced the Windows subsystem for linux (WSL) which makes compiling opensource code way easier. The remainder of this document assumes you have WSL installed. Most of it however will probably just work on osx.
When it comes time to installing a distribution I recommend ubuntu
Ubuntu is actually now creating special distribution that are designed to work with WSL. article
- zip
- unzip
- swig
- gcc
- make
- build-essential
- python-dev
Installing:
sudo apt-get install zip unzip swig gcc make sqlite3 build-essential python-dev
Not required but do a great job of masking the stench that is windows:
- Windows Terminal or
- Cmder. I'd also recommend installing using
- chocolatey
All the oracle stuff can be found at the oracle download page
Proceed with downloading the following files:
I used version 19.5 but I believe any version should work
- create /opt/oracle, and extract the oracle zips into that directory
cd /opt
sudo mkdir oracle
sudo unzip /location/to/your/download/instantclient-basic-linux.x64-19.5.0.0.0dbru.zip
sudo unzip /location/to/your/download/instantclient-sqlplus-linux.x64-19.5.0.0.0dbru.zip
sudo unzip /location/to/your/download/instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip
This repo contains a install_deps.sh script that was stolen from the pyrosal github repo: https://github.com/johntruckenbrodt/pyroSAR/blob/master/pyroSAR/install/install_deps.sh
It has been modified slightly in the following ways:
- bash shell path to work with ubuntu
- modified gdal configure so it can incorporates the oracle stuff to add OCI interface
- deleted cleanup so that if it fails we don't have to start from scratch.
sudo ./install_deps.sh
Once complete you should have a local directory in your ~ (home) folder with gdal utilities and a bunch of other stuff that you may find useful at a later date.
Use the following command to verify that you can dump data from oracle to some other format. example below is for a pgdump file, you can test for any output format.
To get a list of supported formats:
cd ~/local
./ogrinfo --formats
If the install worked you should see a line that says OCI
... OCI -vector- (rw+): Oracle Spatial ...
Test dump of BCGW table to PGDUMP format.
ogr2ogr -nln <output object name> -lco GEOMETRY_NAME=geom -f "PGDUMP" <path to pgdump file> OCI:"<username>/<password>@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=<db host>)(PORT=<db port>)))(CONNECT_DATA=(SERVICE_NAME=<db service name>))):<oracle schema>.<oracle table to dump>"
Specific Options that needed to be set to get a valid PGDUMP file:
- -nln: specifies the name of the object to be created in the postgres db. without this option will generate an invalid object name for the destination
- -lco: specifies the output geometry name. without this option generates a dump file with "" for the geometry column which makes the file invalid.
sudo mkdir /opt/gdal
sudo cp -R ~/local/* /opt/gdal/.
Add the following lines to .bashrc
export GDAL_HOME=/opt/gdal
export ORACLE_HOME=/opt/oracle/instantclient_19_5
export LD_LIBRARY_PATH=$ORACLE_HOME:$GDAL_HOME/lib:$GDAL_HOME/include:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME:$GDAL_HOME/bin:$PATH
and lastly open a new shell and verify that you have ogr installed:
ogrinfo --version
should be 3.0.1
- build bash script
- extensive docs on compiling o/s geospatial tools / lib
- bunch more references to build scripts:
- specifics to oracle
- configure oracle client
- the great oracle's ideas on gdal/ogr
Proj requires some data files that are not currently being downloaded as part of the install, could modify the install to add those files or possibly figure out how to add stuff in later. In a typical build process the datums get added after 'configure' and before 'make'.
- now get the datums from here
- direct link to [proj-datumgrid-1.8.zip](https://download.osgeo.org/proj/proj-datumgrid-1.8.zip