VTK source comes with self-contained PROJ source, in directory ThirdParty/libproj, and library libvtklibproj.so is built from that. Compiling application C++ code with this flag enables VTK PROJ headers and the aforementioned library:
-isystem /usr/local/include/vtk-9.2/vtklibproj/src
I’m currently using VTK-9.2.0, which incorporates PROJ-8.1.0, with ubuntu 20.04. My system also has PROJ-7.1.0 installed “standalone”.
The following simple program works if VTK PROJ is not enabled, but fails with “libproj_proj_create: Cannot find proj.db” if VTK PROJ is enabled:
#include <iostream>
// Using compile flag
// -isystem /usr/local/include/vtk-9.2/vtklibproj/src
// enables vtk's "built-in" proj version
#include <proj.h>
int main(int argc, char **argv) {
PJ_INFO projInfo = proj_info();
std::cerr << "proj release: " << projInfo.release << std::endl;
double xMin = 0.;
// Get UTM zone of grid's W edge
int utmZone = ((xMin + 180)/6 + 0.5);
std::cerr << "UTM zone: " << utmZone << std::endl;
PJ_CONTEXT *projContext = proj_context_create();
if (projContext) {
std::cerr << "Created projContext OK" << std::endl;
} else {
return -1;
}
const char *srcCRS = "EPSG:4326";
char targCRS[64];
sprintf(targCRS, "+proj=utm +zone=%d +datum=WGS84", utmZone);
std::cout << "targCRS: " << targCRS << std::endl;
PJ *proj = proj_create_crs_to_crs (projContext,
srcCRS,
targCRS,
nullptr);
if (!proj) {
std::cerr << "failed to create proj" << std::endl;
} else {
std::cerr << "created proj OK" << std::endl;
}
return 0;
}
With VTK PROJ not enabled, the program works, gives this output:
proj release: Rel. 7.1.0, August 1st, 2020
UTM zone: 30
Created projContext OK
targCRS: +proj=utm +zone=30 +datum=WGS84
created proj OK
When VTK PROJ is enabled, the proj_create_crs_to_crs() call fails:
proj release: Rel. 8.1.0, July 1st, 2021
UTM zone: 30
Created projContext OK
targCRS: +proj=utm +zone=30 +datum=WGS84
libproj_proj_create: Cannot find proj.db
failed to create proj
The VTK PROJ proj.db is at /usr/local/share/vtk-9.2/proj/proj.db, so I tried setting environment variable PROJ_LIB to /usr/local/share/vtk-9.2/proj/ - but get the same “Cannot find proj.db” error. Does anyone know why this is happening?
Thanks!