Last active
March 21, 2016 19:53
-
-
Save connormanning/2f666606cabd51be5e74 to your computer and use it in GitHub Desktop.
PDAL reader behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdexcept> | |
#include <string> | |
#include <pdal/BufferReader.hpp> | |
#include <pdal/Filter.hpp> | |
#include <pdal/GlobalEnvironment.hpp> | |
#include <pdal/Options.hpp> | |
#include <pdal/PointTable.hpp> | |
#include <pdal/QuickInfo.hpp> | |
#include <pdal/Reader.hpp> | |
#include <pdal/StageFactory.hpp> | |
namespace | |
{ | |
pdal::StageFactory stageFactory; | |
bool preview(const std::string path) | |
{ | |
const std::string driver(stageFactory.inferReaderDriver(path)); | |
if (driver.empty()) throw std::runtime_error("No driver for " + path); | |
if (pdal::Reader* reader = static_cast<pdal::Reader*>( | |
stageFactory.createStage(driver))) | |
{ | |
pdal::Options options; | |
options.add(pdal::Option("filename", path)); | |
reader->setOptions(options); | |
std::cout << "\nDoing preview..." << std::endl; | |
const pdal::QuickInfo quickInfo(reader->preview()); | |
return quickInfo.valid(); | |
} | |
else throw std::runtime_error("No reader for " + driver); | |
} | |
void prepareDummyFilter() | |
{ | |
if (pdal::Filter* filter = static_cast<pdal::Filter*>( | |
stageFactory.createStage("filters.reprojection"))) | |
{ | |
pdal::Options options; | |
options.add(pdal::Option("in_srs", "EPSG:26915")); | |
options.add(pdal::Option("out_srs", "EPSG:3857")); | |
filter->setOptions(options); | |
pdal::PointTable pointTable; | |
/* | |
// Fill the view with some actual data, if you'd like. | |
auto layout(pointTable.layout()); | |
layout->registerDim(pdal::Dimension::Id::X); | |
layout->registerDim(pdal::Dimension::Id::Y); | |
layout->registerDim(pdal::Dimension::Id::Z); | |
layout->finalize(); | |
pdal::PointViewPtr pointViewPtr(new pdal::PointView(pointTable)); | |
pointViewPtr->setField(pdal::Dimension::Id::X, 0, 0); | |
pointViewPtr->setField(pdal::Dimension::Id::Y, 0, 0); | |
pointViewPtr->setField(pdal::Dimension::Id::Z, 0, 0); | |
pdal::BufferReader bufferReader; | |
bufferReader.addView(pointViewPtr); | |
filter->setInput(bufferReader); | |
*/ | |
filter->prepare(pointTable); | |
} | |
else throw std::runtime_error("No reprojection filter created"); | |
} | |
} | |
int main() | |
{ | |
const std::string path("02004736.laz"); | |
if (preview(path)) std::cout << "First preview looks good" << std::endl; | |
else throw std::runtime_error("Bad first preview"); | |
prepareDummyFilter(); | |
if (preview(path)) std::cout << "Second preview looks good" << std::endl; | |
else throw std::runtime_error("Bad second preview"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ g++ -std=c++11 bomb.cpp -lpdalcpp && ./a.out | |
Doing preview... | |
ERROR 6: EPSG PCS/GCS code 5103 not found in EPSG support files. Is this a valid | |
EPSG coordinate system? | |
ERROR 6: EPSG PCS/GCS code 5103 not found in EPSG support files. Is this a valid | |
EPSG coordinate system? | |
First preview looks good | |
Doing preview... | |
libc++abi.dylib: terminating with uncaught exception of type pdal::pdal_error: readers.lasGDAL Failure number = 6: EPSG PCS/GCS code 5103 not found in EPSG support files. Is this a valid | |
EPSG coordinate system? | |
Abort trap: 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g++ -std=c++11 inconsistency.cpp -lpdalcpp && ./a.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment