Unable to read from "/vsimem/" using vtkGDALVectorReader

453 views Asked by At

I am trying to visualize a GDAL dataset in VTK using vtkGDALVectorReader... Everything works fine if I use a disk file. but when I use a memory dataset (ex."/vsimem/input.dat"), vtkGDALVectorReader reports the following error.

ERROR: In /opt/app/VTK-7.1.0/IO/GDAL/vtkGDALVectorReader.cxx, line 643 vtkGDALVectorReader (0xb881b0):

I debugged the program and found out that GDALOpenEx (in vtkGDALVectorReader) returns NULL... How do I fix it?

I am using VTK-7.1 and GDAL-2.1.2 on "RHEL Server 7.2"

the code is as follows....

#include <iostream>
#include <iomanip>
#include <ogrsf_frmts.h>

#include <vtkSmartPointer.h>
#include <vtkGDALVectorReader.h>
#include <vtkCompositeDataGeometryFilter.h>
#include <vtkCompositePolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkCamera.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>

#define MEMORY_FILENAME "/vsimem/example.dat"

int main(int argc, char *argv[])
{
    GDALAllRegister();
    VSIInstallMemFileHandler();

    GDALDataset *shpDS = (GDALDataset*) GDALOpenEx(argv[1], GDAL_OF_VECTOR, NULL, NULL, NULL);
    if(shpDS == NULL)
    {
        std::cerr << "Input ESRI Shapefile Open Failed..." << std::endl;
        return -1;
    }
    GDALDriver *memDriver = GetGDALDriverManager()->GetDriverByName("Memory");
    if(memDriver == NULL)
    {
        std::cerr << "GDAL Memory driver not available...." << std::endl;
        return -1;
    }
    GDALDataset *memDS = memDriver->CreateCopy(MEMORY_FILENAME, shpDS, FALSE, NULL, NULL, NULL);
    GDALClose(shpDS);

    vtkSmartPointer<vtkGDALVectorReader> reader = vtkSmartPointer<vtkGDALVectorReader>::New();
    reader->SetFileName(MEMORY_FILENAME);
//    reader->SetFileName(argv[1]);

    vtkSmartPointer<vtkCompositeDataGeometryFilter> filter = vtkSmartPointer<vtkCompositeDataGeometryFilter>::New();
    filter->SetInputConnection(reader->GetOutputPort());

    vtkSmartPointer<vtkCompositePolyDataMapper> mapper = vtkSmartPointer<vtkCompositePolyDataMapper>::New();
    mapper->SetInputConnection(filter->GetOutputPort());

    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);

    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);
    renderer->SetBackground(0.1, 0.2, 0.4);
    renderer->ResetCamera();
    renderer->GetActiveCamera()->Zoom(1.5);

    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->SetSize(500, 500);
    renderWindow->AddRenderer(renderer);

    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);
    renderWindowInteractor->Start();

    GDALClose(memDS);
    return 0;
}
0

There are 0 answers