|
#include <limits> |
|
#include <pdal/PipelineManager.hpp> |
|
#include <pdal/Stage.hpp> |
|
#include <json/json.h> |
|
|
|
// Native (EPSG:26913) -> EPSG:3857 |
|
// (-11711830, 4816845.6), (-11710915, 4817998.9) |
|
// |
|
// EPSG:26912 -> EPSG:3857 |
|
// (-12379747, 4816845.6), (-12378831, 4817998.9) |
|
|
|
void analyze(const Json::Value& pipeline) |
|
{ |
|
pdal::PipelineManager pm; |
|
std::cout << pipeline << std::endl; |
|
|
|
std::istringstream iss(pipeline.toStyledString()); |
|
pm.readPipeline(iss); |
|
|
|
pdal::Stage* stage(pm.getStage()); |
|
if (!stage) throw std::runtime_error("No stage"); |
|
|
|
pdal::PointTable table; |
|
stage->prepare(table); |
|
const auto views(stage->execute(table)); |
|
|
|
double x, y, xmin, ymin, xmax, ymax; |
|
xmin = ymin = std::numeric_limits<double>::max(); |
|
xmax = ymax = std::numeric_limits<double>::lowest(); |
|
|
|
for (auto view : views) |
|
{ |
|
for (uint64_t i(0); i < view->size(); ++i) |
|
{ |
|
x = view->getFieldAs<double>(pdal::Dimension::Id::X, i); |
|
y = view->getFieldAs<double>(pdal::Dimension::Id::Y, i); |
|
|
|
xmin = std::min(xmin, x); |
|
ymin = std::min(ymin, y); |
|
|
|
xmax = std::max(xmax, x); |
|
ymax = std::max(ymax, y); |
|
} |
|
} |
|
|
|
std::cout << std::fixed << std::setprecision(2) << "Bounds: " << |
|
"(" << xmin << ", " << ymin << "), " << |
|
"(" << xmax << ", " << ymax << ")\n\n" << std::endl; |
|
} |
|
|
|
int main() |
|
{ |
|
Json::Value wrapper; |
|
Json::Value& pipeline(wrapper["pipeline"]); |
|
Json::Value& reader(pipeline.append(Json::objectValue)); |
|
Json::Value& filter(pipeline.append(Json::objectValue)); |
|
|
|
filter["type"] = "filters.reprojection"; |
|
filter["out_srs"] = "EPSG:3857"; |
|
|
|
// First we'll run both readers using the default spatial reference from |
|
// the input files themselves. We expect the same output bounds from both |
|
// of these since the LAZ and BPF files contain the same data and same SRS. |
|
|
|
reader["filename"] = "https://entwine.io/data/red-rocks.bpf"; |
|
analyze(wrapper); |
|
|
|
reader["filename"] = "https://entwine.io/data/red-rocks.laz"; |
|
analyze(wrapper); |
|
|
|
// Now we'll set the "spatialreference" option on the reader and run both |
|
// pipelines again. While the LAS reader respects the setting, the BPF |
|
// reader does not. |
|
reader["spatialreference"] = "EPSG:26912"; |
|
|
|
reader["filename"] = "https://entwine.io/data/red-rocks.bpf"; |
|
analyze(wrapper); |
|
|
|
reader["filename"] = "https://entwine.io/data/red-rocks.laz"; |
|
analyze(wrapper); |
|
} |