void Writer::writeEnd(boost::uint64_t /*actualNumPointsWritten*/) { calculateGridSizes(); log()->get(logDEBUG) << "X grid size: " << m_GRID_SIZE_X << std::endl; log()->get(logDEBUG) << "Y grid size: " << m_GRID_SIZE_Y << std::endl; log()->floatPrecision(6); log()->get(logDEBUG) << "X grid distance: " << m_GRID_DIST_X << std::endl; log()->get(logDEBUG) << "Y grid distance: " << m_GRID_DIST_Y << std::endl; log()->clearFloat(); boost::scoped_ptr<OutCoreInterp> p(new OutCoreInterp(m_GRID_DIST_X, m_GRID_DIST_Y, m_GRID_SIZE_X, m_GRID_SIZE_Y, m_RADIUS_SQ, m_bounds.getMinimum(0), m_bounds.getMaximum(0), m_bounds.getMinimum(1), m_bounds.getMaximum(1), m_fill_window_size)); m_interpolator.swap(p); if (m_interpolator->init() < 0) { throw p2g_error("unable to initialize interpolator"); } int rc(0); std::vector<boost::tuple<double, double, double> >::const_iterator i; for (i = m_coordinates.begin(); i!= m_coordinates.end(); ++i) { double x = i->get<0>(); double y = i->get<1>(); x = x - m_bounds.getMinimum(0); y = y - m_bounds.getMinimum(1); rc = m_interpolator->update(x, y, i->get<2>()); if (rc < 0) { throw p2g_error("interp->update() error while processing "); } } if ((rc = m_interpolator->finish(const_cast<char*>(m_filename.c_str()), m_outputFormat, m_outputTypes)) < 0) { throw p2g_error("interp->finish() error"); } return; }
void P2gWriter::processOptions(const Options& options) { m_GRID_DIST_X = options.getValueOrDefault<double>("grid_dist_x", 6.0); m_GRID_DIST_Y = options.getValueOrDefault<double>("grid_dist_y", 6.0); m_RADIUS_SQ = options.getValueOrDefault<double>("radius", 8.4852813742385713); m_fill_window_size = options.getValueOrDefault<boost::uint32_t>( "fill_window_size", 3); m_filename = options.getValueOrThrow<std::string>("filename"); std::vector<Option> types = options.getOptions("output_type"); if (!types.size()) m_outputTypes = OUTPUT_TYPE_ALL; else { for (auto i = types.begin(); i != types.end(); ++i) { if (boost::iequals(i->getValue<std::string>(), "min")) m_outputTypes |= OUTPUT_TYPE_MIN; if (boost::iequals(i->getValue<std::string>(), "max")) m_outputTypes |= OUTPUT_TYPE_MAX; if (boost::iequals(i->getValue<std::string>(), "mean")) m_outputTypes |= OUTPUT_TYPE_MEAN; if (boost::iequals(i->getValue<std::string>(), "idw")) m_outputTypes |= OUTPUT_TYPE_IDW; if (boost::iequals(i->getValue<std::string>(), "den")) m_outputTypes |= OUTPUT_TYPE_DEN; if (boost::iequals(i->getValue<std::string>(), "std")) m_outputTypes |= OUTPUT_TYPE_STD; if (boost::iequals(i->getValue<std::string>(), "all")) m_outputTypes = OUTPUT_TYPE_ALL; } } std::string output_format = options.getValueOrDefault<std::string>("output_format", "grid"); if (boost::iequals(output_format, "grid")) m_outputFormat = OUTPUT_FORMAT_GRID_ASCII; else if (boost::iequals(output_format, "asc")) m_outputFormat = OUTPUT_FORMAT_ARC_ASCII; else if (boost::iequals(output_format, "tif")) m_outputFormat = OUTPUT_FORMAT_GDAL_GTIFF; else if (boost::iequals(output_format, "all")) m_outputFormat = OUTPUT_FORMAT_ALL; else { std::ostringstream oss; oss << "Unrecognized output format " << output_format; throw p2g_error("Unrecognized output format"); } }
void P2gWriter::done(PointTableRef table) { // If we never got any points, we're done. if (! m_coordinates.size()) return; m_GRID_SIZE_X = (int)(ceil((m_bounds.maxx - m_bounds.minx)/m_GRID_DIST_X)) + 1; m_GRID_SIZE_Y = (int)(ceil((m_bounds.maxy - m_bounds.miny)/m_GRID_DIST_Y)) + 1; log()->get(LogLevel::Debug) << "X grid size: " << m_GRID_SIZE_X << std::endl; log()->get(LogLevel::Debug) << "Y grid size: " << m_GRID_SIZE_Y << std::endl; log()->floatPrecision(6); log()->get(LogLevel::Debug) << "X grid distance: " << m_GRID_DIST_X << std::endl; log()->get(LogLevel::Debug) << "Y grid distance: " << m_GRID_DIST_Y << std::endl; log()->clearFloat(); std::unique_ptr<OutCoreInterp> p(new OutCoreInterp(m_GRID_DIST_X, m_GRID_DIST_Y, m_GRID_SIZE_X, m_GRID_SIZE_Y, m_RADIUS * m_RADIUS, m_bounds.minx, m_bounds.maxx, m_bounds.miny, m_bounds.maxy, m_fill_window_size)); m_interpolator.swap(p); if (m_interpolator->init() < 0) { throw p2g_error("unable to initialize interpolator"); } int rc(0); std::vector<boost::tuple<double, double, double> >::const_iterator i; for (i = m_coordinates.begin(); i!= m_coordinates.end(); ++i) { double x = i->get<0>(); double y = i->get<1>(); x = x - m_bounds.minx; y = y - m_bounds.miny; rc = m_interpolator->update(x, y, i->get<2>()); if (rc < 0) { throw p2g_error("interp->update() error while processing "); } } double adfGeoTransform[6]; adfGeoTransform[0] = m_bounds.minx - 0.5*m_GRID_DIST_X; adfGeoTransform[1] = m_GRID_DIST_X; adfGeoTransform[2] = 0.0; adfGeoTransform[3] = m_bounds.maxy + 0.5*m_GRID_DIST_Y; adfGeoTransform[4] = 0.0; adfGeoTransform[5] = -1 * m_GRID_DIST_Y; SpatialReference const& srs = table.spatialRef(); log()->get(LogLevel::Debug) << "Output SRS :'" << srs.getWKT() << "'" << std::endl; if ((rc = m_interpolator->finish(const_cast<char*>(m_filename.c_str()), m_outputFormat, m_outputTypes, adfGeoTransform, srs.getWKT().c_str())) < 0) { throw p2g_error("interp->finish() error"); } return; }
void P2gWriter::write(const PointBuffer& buf) { std::string z_name = getOptions().getValueOrDefault<std::string>("Z", "Z"); for (point_count_t idx = 0; idx < buf.size(); idx++) { double x = buf.getFieldAs<double>(Dimension::Id::X, idx); double y = buf.getFieldAs<double>(Dimension::Id::Y, idx); double z = buf.getFieldAs<double>(Dimension::Id::Z, idx); m_coordinates.push_back(boost::tuple<double, double, double>(x, y, z)); } m_bounds = buf.calculateBounds(); m_GRID_SIZE_X = (int)(ceil((m_bounds.maxx - m_bounds.minx)/m_GRID_DIST_X)) + 1; m_GRID_SIZE_Y = (int)(ceil((m_bounds.maxy - m_bounds.miny)/m_GRID_DIST_Y)) + 1; log()->get(LogLevel::Debug) << "X grid size: " << m_GRID_SIZE_X << std::endl; log()->get(LogLevel::Debug) << "Y grid size: " << m_GRID_SIZE_Y << std::endl; log()->floatPrecision(6); log()->get(LogLevel::Debug) << "X grid distance: " << m_GRID_DIST_X << std::endl; log()->get(LogLevel::Debug) << "Y grid distance: " << m_GRID_DIST_Y << std::endl; log()->clearFloat(); boost::scoped_ptr<OutCoreInterp> p(new OutCoreInterp(m_GRID_DIST_X, m_GRID_DIST_Y, m_GRID_SIZE_X, m_GRID_SIZE_Y, m_RADIUS_SQ, m_bounds.minx, m_bounds.maxx, m_bounds.miny, m_bounds.maxy, m_fill_window_size)); m_interpolator.swap(p); if (m_interpolator->init() < 0) { throw p2g_error("unable to initialize interpolator"); } int rc(0); std::vector<boost::tuple<double, double, double> >::const_iterator i; for (i = m_coordinates.begin(); i!= m_coordinates.end(); ++i) { double x = i->get<0>(); double y = i->get<1>(); x = x - m_bounds.minx; y = y - m_bounds.miny; rc = m_interpolator->update(x, y, i->get<2>()); if (rc < 0) { throw p2g_error("interp->update() error while processing "); } } double adfGeoTransform[6]; adfGeoTransform[0] = m_bounds.minx; adfGeoTransform[1] = m_GRID_DIST_X; adfGeoTransform[2] = 0.0; adfGeoTransform[3] = m_bounds.maxy; adfGeoTransform[4] = 0.0; adfGeoTransform[5] = -1 * m_GRID_DIST_Y; SpatialReference const& srs = getSpatialReference(); if ((rc = m_interpolator->finish(const_cast<char*>(m_filename.c_str()), m_outputFormat, m_outputTypes, adfGeoTransform, srs.getWKT().c_str())) < 0) { throw p2g_error("interp->finish() error"); } return; }
void Writer::initialize() { pdal::Writer::initialize(); m_GRID_DIST_X = getOptions().getValueOrDefault<double>("grid_dist_x", 6.0); m_GRID_DIST_Y = getOptions().getValueOrDefault<double>("grid_dist_y", 6.0); m_RADIUS_SQ = getOptions().getValueOrDefault<double>("radius", 8.4852813742385713); m_fill_window_size = getOptions().getValueOrDefault<boost::uint32_t>("fill_window_size", 3); m_filename = getOptions().getValueOrThrow<std::string>("filename"); std::string output_format = getOptions().getValueOrDefault<std::string>("output_format", "grid"); double min_x = (std::numeric_limits<double>::max)(); double max_x = (std::numeric_limits<double>::min)(); double min_y = (std::numeric_limits<double>::max)(); double max_y = (std::numeric_limits<double>::min)(); setBounds(pdal::Bounds<double>(min_x, min_y, max_x, max_y)); std::vector<Option> types = getOptions().getOptions("output_type"); if (!types.size()) m_outputTypes = OUTPUT_TYPE_ALL; else { for (std::vector<Option>::const_iterator i = types.begin(); i != types.end(); ++i) { if (boost::iequals(i->getValue<std::string>(), "min")) { m_outputTypes |= OUTPUT_TYPE_MIN; } if (boost::iequals(i->getValue<std::string>(), "max")) { m_outputTypes |= OUTPUT_TYPE_MAX; } if (boost::iequals(i->getValue<std::string>(), "mean")) { m_outputTypes |= OUTPUT_TYPE_MEAN; } if (boost::iequals(i->getValue<std::string>(), "idw")) { m_outputTypes |= OUTPUT_TYPE_IDW; } if (boost::iequals(i->getValue<std::string>(), "den")) { m_outputTypes |= OUTPUT_TYPE_DEN; } if (boost::iequals(i->getValue<std::string>(), "all")) { m_outputTypes = OUTPUT_TYPE_ALL; } } } if (boost::iequals(output_format, "grid")) m_outputFormat = OUTPUT_FORMAT_GRID_ASCII; else if (boost::iequals(output_format, "asc")) m_outputFormat = OUTPUT_FORMAT_ARC_ASCII; else { std::ostringstream oss; oss << "Unrecognized output format " << output_format; throw p2g_error("Unrecognized output format"); } return; }