OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeoRaster< T, Z > Struct Template Reference

#include <GeoRasterTableFunctions.hpp>

+ Collaboration diagram for GeoRaster< T, Z >:

Public Member Functions

template<typename T2 , typename Z2 >
 GeoRaster (const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, const RasterAggType raster_agg_type, const double bin_dim_meters, const bool geographic_coords, const bool align_bins_to_zero_based_grid)
 
template<typename T2 , typename Z2 >
 GeoRaster (const Column< T2 > &input_x, const Column< T2 > &input_y, const ColumnList< Z2 > &input_z_cols, const std::vector< RasterAggType > &raster_agg_types, const double bin_dim_meters, const bool geographic_coords, const bool align_bins_to_zero_based_grid)
 
template<typename T2 , typename Z2 >
 GeoRaster (const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, const RasterAggType raster_agg_type, const double bin_dim_meters, const bool geographic_coords, const bool align_bins_to_zero_based_grid, const T x_min, const T x_max, const T y_min, const T y_max)
 
get_x_bin (const T input) const
 
get_y_bin (const T input) const
 
bool is_null (const Z value) const
 
bool is_bin_out_of_bounds (const int64_t x_bin, const int64_t y_bin) const
 
std::pair< int64_t, Z > get_bin_idx_and_z_val_for_xy_bin (const int64_t x_bin, const int64_t y_bin) const
 
int64_t get_bin_idx_for_xy_coords (const T x, const T y) const
 
std::pair< T, T > get_xy_coords_for_bin_idx (const int64_t bin_idx) const
 
offset_source_z_from_raster_z (const int64_t source_x_bin, const int64_t source_y_bin, const Z source_z_offset) const
 
offset_source_z_from_raster_z (const int64_t source_x_bin, const int64_t source_y_bin, const Z source_z_offset, const int64_t z_col_idx) const
 
void align_bins_max_inclusive ()
 
void align_bins_max_exclusive ()
 
void calculate_bins_and_scales ()
 
template<typename T2 , typename Z2 >
void compute (const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, std::vector< Z > &output_z, const RasterAggType raster_agg_type, const size_t max_inputs_per_thread)
 
void fill_bins_from_neighbors (const int64_t neighborhood_fill_radius, const bool fill_only_nulls, const RasterAggType raster_agg_type=RasterAggType::GAUSS_AVG)
 
void fill_bins_from_neighbors (const int64_t neighborhood_fill_radius, const bool fill_only_nulls, const RasterAggType raster_agg_type, std::vector< Z > &z)
 
bool get_nxn_neighbors_if_not_null (const int64_t x_bin, const int64_t y_bin, const int64_t num_bins_radius, std::vector< Z > &neighboring_bins) const
 
std::pair< Z, Z > calculate_slope_and_aspect_of_cell (const std::vector< Z > &neighboring_cells, const bool compute_slope_in_degrees) const
 
void calculate_slope_and_aspect (Column< Z > &slope, Column< Z > &aspect, const bool compute_slope_in_degrees) const
 
int64_t outputDenseColumns (TableFunctionManager &mgr, Column< T > &output_x, Column< T > &output_y, Column< Z > &output_z, const int64_t band_idx=0) const
 
int64_t outputDenseColumn (TableFunctionManager &mgr, Column< Z > &output_z, const int64_t band_idx) const
 
int64_t outputDenseColumns (TableFunctionManager &mgr, Column< T > &output_x, Column< T > &output_y, Column< Array< Z >> &output_z) const
 
int64_t outputDenseColumnsAndFill (TableFunctionManager &mgr, Column< T > &output_x, Column< T > &output_y, Column< Z > &output_z, const int64_t neighborhood_null_fill_radius) const
 
void setMetadata (TableFunctionManager &mgr) const
 

Public Attributes

const T bin_dim_meters_
 
const bool geographic_coords_
 
const Z null_sentinel_
 
const bool is_multi_z_
 
std::vector< Z > z_
 
std::vector< std::vector< Z > > z_cols_
 
std::vector< Z > counts_
 
x_min_
 
x_max_ {0}
 
y_min_ {0}
 
y_max_ {0}
 
x_range_ {0}
 
y_range_ {0}
 
x_meters_per_degree_ {0}
 
y_meters_per_degree_ {0}
 
int64_t num_x_bins_ {0}
 
int64_t num_y_bins_ {0}
 
int64_t num_bins_ {0}
 
x_scale_input_to_bin_ {0}
 
y_scale_input_to_bin_ {0}
 
x_scale_bin_to_input_ {0}
 
y_scale_bin_to_input_ {0}
 

Static Public Attributes

static constexpr int64_t BIN_OUT_OF_BOUNDS {-1}
 

Private Member Functions

template<RasterAggType AggType, typename T2 , typename Z2 >
void computeSerialImpl (const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, std::vector< Z > &output_z)
 
template<RasterAggType AggType>
void computeParallelReductionAggImpl (const std::vector< std::vector< Z >> &z_inputs, std::vector< Z > &output_z, const Z agg_sentinel)
 
template<RasterAggType AggType, typename T2 , typename Z2 >
void computeParallelImpl (const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, std::vector< Z > &output_z, const size_t max_inputs_per_thread)
 
fill_bin_from_avg_box_neighborhood (const int64_t x_centroid_bin, const int64_t y_centroid_bin, const int64_t bins_radius, std::vector< Z > &z) const
 
template<RasterAggType AggType>
fill_bin_from_box_neighborhood (const int64_t x_centroid_bin, const int64_t y_centroid_bin, const int64_t bins_radius, const ComputeAgg< AggType > &compute_agg, std::vector< Z > &z) const
 
template<RasterAggType AggType>
void fill_bins_from_box_neighborhood (const int64_t neighborhood_fill_radius, const bool fill_only_nulls, std::vector< Z > &z)
 
void fill_bins_from_gaussian_neighborhood (const int64_t neighborhood_fill_radius, const bool fill_only_nulls, std::vector< Z > &z)
 

Detailed Description

template<typename T, typename Z>
struct GeoRaster< T, Z >

Definition at line 90 of file GeoRasterTableFunctions.hpp.

Constructor & Destructor Documentation

template<typename T , typename Z >
template<typename T2 , typename Z2 >
GeoRaster< T, Z >::GeoRaster ( const Column< T2 > &  input_x,
const Column< T2 > &  input_y,
const Column< Z2 > &  input_z,
const RasterAggType  raster_agg_type,
const double  bin_dim_meters,
const bool  geographic_coords,
const bool  align_bins_to_zero_based_grid 
)

Definition at line 296 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::align_bins_max_inclusive(), GeoRaster< T, Z >::calculate_bins_and_scales(), GeoRaster< T, Z >::compute(), DEBUG_TIMER, GeoRaster< T, Z >::geographic_coords_, get_column_min_max(), max_inputs_per_thread, GeoRaster< T, Z >::num_bins_, GeoRaster< T, Z >::num_x_bins_, GeoRaster< T, Z >::num_y_bins_, Column< T >::size(), GeoRaster< T, Z >::x_max_, GeoRaster< T, Z >::x_min_, GeoRaster< T, Z >::y_max_, GeoRaster< T, Z >::y_min_, and GeoRaster< T, Z >::z_.

303  : bin_dim_meters_(bin_dim_meters)
304  , geographic_coords_(geographic_coords)
305  , null_sentinel_(inline_null_value<Z>())
306  , is_multi_z_(false) {
307  auto timer = DEBUG_TIMER(__func__);
308  const int64_t input_size{input_z.size()};
309  if (input_size <= 0) {
310  num_bins_ = 0;
311  num_x_bins_ = 0;
312  num_y_bins_ = 0;
313  return;
314  }
315  const auto min_max_x = get_column_min_max(input_x);
316  const auto min_max_y = get_column_min_max(input_y);
317  x_min_ = min_max_x.first;
318  x_max_ = min_max_x.second;
319  y_min_ = min_max_y.first;
320  y_max_ = min_max_y.second;
321 
322  if (align_bins_to_zero_based_grid && !geographic_coords_) {
323  // For implicit, data-defined bounds, we treat the max of the x and y ranges as
324  // inclusive (closed interval), since if the max of the data in either x/y dimensions
325  // is at the first value of the next bin, values at that max will be discarded if we
326  // don't include the final bin. For exmaple, if the input data (perhaps already binned
327  // with a group by query) goes from 0.0 to 40.0 in both x and y directions, we should
328  // have the last x/y bins cover the range [40.0, 50.0), not [30.0, 40.0)
330  }
331 
333  compute(input_x, input_y, input_z, z_, raster_agg_type, max_inputs_per_thread);
334 }
NEVER_INLINE HOST std::pair< T, T > get_column_min_max(const Column< T > &col)
DEVICE int64_t size() const
const size_t max_inputs_per_thread
const bool geographic_coords_
#define DEBUG_TIMER(name)
Definition: Logger.h:412
std::vector< Z > z_
void compute(const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, std::vector< Z > &output_z, const RasterAggType raster_agg_type, const size_t max_inputs_per_thread)

+ Here is the call graph for this function:

template<typename T , typename Z >
template<typename T2 , typename Z2 >
GeoRaster< T, Z >::GeoRaster ( const Column< T2 > &  input_x,
const Column< T2 > &  input_y,
const ColumnList< Z2 > &  input_z_cols,
const std::vector< RasterAggType > &  raster_agg_types,
const double  bin_dim_meters,
const bool  geographic_coords,
const bool  align_bins_to_zero_based_grid 
)

Definition at line 338 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::align_bins_max_inclusive(), GeoRaster< T, Z >::calculate_bins_and_scales(), GeoRaster< T, Z >::compute(), DEBUG_TIMER, GeoRaster< T, Z >::geographic_coords_, get_column_min_max(), max_inputs_per_thread, GeoRaster< T, Z >::num_bins_, GeoRaster< T, Z >::num_x_bins_, GeoRaster< T, Z >::num_y_bins_, ColumnList< T >::numCols(), Column< T >::size(), GeoRaster< T, Z >::x_max_, GeoRaster< T, Z >::x_min_, GeoRaster< T, Z >::y_max_, GeoRaster< T, Z >::y_min_, and GeoRaster< T, Z >::z_cols_.

345  : bin_dim_meters_(bin_dim_meters)
346  , geographic_coords_(geographic_coords)
347  , null_sentinel_(inline_null_value<Z>())
348  , is_multi_z_(true) {
349  auto timer = DEBUG_TIMER(__func__);
350  const int64_t input_size{input_x.size()};
351  const int64_t num_z_cols = input_z_cols.numCols();
352  if (num_z_cols != static_cast<int64_t>(raster_agg_types.size())) {
353  throw std::runtime_error("Number of z cols and raster_agg_types do not match.");
354  }
355  if (input_size <= 0) {
356  num_bins_ = 0;
357  num_x_bins_ = 0;
358  num_y_bins_ = 0;
359  return;
360  }
361  z_cols_.resize(num_z_cols);
362  const auto min_max_x = get_column_min_max(input_x);
363  const auto min_max_y = get_column_min_max(input_y);
364  x_min_ = min_max_x.first;
365  x_max_ = min_max_x.second;
366  y_min_ = min_max_y.first;
367  y_max_ = min_max_y.second;
368 
369  if (align_bins_to_zero_based_grid && !geographic_coords_) {
370  // For implicit, data-defined bounds, we treat the max of the x and y ranges as
371  // inclusive (closed interval), since if the max of the data in either x/y dimensions
372  // is at the first value of the next bin, values at that max will be discarded if we
373  // don't include the final bin. For exmaple, if the input data (perhaps already binned
374  // with a group by query) goes from 0.0 to 40.0 in both x and y directions, we should
375  // have the last x/y bins cover the range [40.0, 50.0), not [30.0, 40.0)
377  }
378 
380  for (int64_t z_col_idx = 0; z_col_idx < num_z_cols; ++z_col_idx) {
381  compute(input_x,
382  input_y,
383  input_z_cols[z_col_idx],
384  z_cols_[z_col_idx],
385  raster_agg_types[z_col_idx],
387  }
388 }
std::vector< std::vector< Z > > z_cols_
NEVER_INLINE HOST std::pair< T, T > get_column_min_max(const Column< T > &col)
DEVICE int64_t size() const
DEVICE int64_t numCols() const
const size_t max_inputs_per_thread
const bool geographic_coords_
#define DEBUG_TIMER(name)
Definition: Logger.h:412
void compute(const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, std::vector< Z > &output_z, const RasterAggType raster_agg_type, const size_t max_inputs_per_thread)

+ Here is the call graph for this function:

template<typename T , typename Z >
template<typename T2 , typename Z2 >
GeoRaster< T, Z >::GeoRaster ( const Column< T2 > &  input_x,
const Column< T2 > &  input_y,
const Column< Z2 > &  input_z,
const RasterAggType  raster_agg_type,
const double  bin_dim_meters,
const bool  geographic_coords,
const bool  align_bins_to_zero_based_grid,
const T  x_min,
const T  x_max,
const T  y_min,
const T  y_max 
)

Definition at line 395 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::align_bins_max_exclusive(), GeoRaster< T, Z >::calculate_bins_and_scales(), GeoRaster< T, Z >::compute(), DEBUG_TIMER, GeoRaster< T, Z >::geographic_coords_, max_inputs_per_thread, and GeoRaster< T, Z >::z_.

406  : bin_dim_meters_(bin_dim_meters)
407  , geographic_coords_(geographic_coords)
408  , null_sentinel_(inline_null_value<Z>())
409  , is_multi_z_(false)
410  , x_min_(x_min)
411  , x_max_(x_max)
412  , y_min_(y_min)
413  , y_max_(y_max) {
414  auto timer = DEBUG_TIMER(__func__);
415  if (align_bins_to_zero_based_grid && !geographic_coords_) {
416  // For explicit, user-defined bounds, we treat the max of the x and y ranges as
417  // exclusive (open interval), since if the user specifies the max x/y as the end of
418  // the bin, they do not intend to add the next full bin For example, if a user
419  // specifies a bin_dim_meters of 10.0 and an x and y range from 0 to 40.0, they almost
420  // assuredly intend for there to be 4 bins in each of the x and y dimensions, with the
421  // last bin of range [30.0, 40.0), not 5 with the final bin's range from [40.0, 50.0)
423  }
425  compute(input_x, input_y, input_z, z_, raster_agg_type, max_inputs_per_thread);
426 }
const size_t max_inputs_per_thread
const bool geographic_coords_
#define DEBUG_TIMER(name)
Definition: Logger.h:412
std::vector< Z > z_
void compute(const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, std::vector< Z > &output_z, const RasterAggType raster_agg_type, const size_t max_inputs_per_thread)

+ Here is the call graph for this function:

Member Function Documentation

template<typename T , typename Z >
void GeoRaster< T, Z >::align_bins_max_exclusive ( )

Definition at line 469 of file GeoRasterTableFunctions.hpp.

Referenced by GeoRaster< T, Z >::GeoRaster().

+ Here is the caller graph for this function:

template<typename T , typename Z >
void GeoRaster< T, Z >::align_bins_max_inclusive ( )

Definition at line 459 of file GeoRasterTableFunctions.hpp.

Referenced by GeoRaster< T, Z >::GeoRaster().

459  {
460  x_min_ = std::floor(x_min_ / bin_dim_meters_) * bin_dim_meters_;
461  x_max_ = std::floor(x_max_ / bin_dim_meters_) * bin_dim_meters_ +
462  bin_dim_meters_; // Snap to end of bin
463  y_min_ = std::floor(y_min_ / bin_dim_meters_) * bin_dim_meters_;
464  y_max_ = std::floor(y_max_ / bin_dim_meters_) * bin_dim_meters_ +
465  bin_dim_meters_; // Snap to end of bin
466 }

+ Here is the caller graph for this function:

template<typename T , typename Z >
void GeoRaster< T, Z >::calculate_bins_and_scales ( )

Definition at line 477 of file GeoRasterTableFunctions.hpp.

References CHECK_GT, distance_in_meters(), heavydb.dtypes::T, and to_string().

Referenced by GeoRaster< T, Z >::GeoRaster().

477  {
478  CHECK_GT(bin_dim_meters_, static_cast<T>(0));
479  x_range_ = x_max_ - x_min_;
480  y_range_ = y_max_ - y_min_;
481  if (geographic_coords_) {
482  const T x_centroid = (x_min_ + x_max_) * 0.5;
483  const T y_centroid = (y_min_ + y_max_) * 0.5;
485  distance_in_meters(x_min_, y_centroid, x_max_, y_centroid) / x_range_;
486 
488  distance_in_meters(x_centroid, y_min_, x_centroid, y_max_) / y_range_;
489 
492 
493  if (num_x_bins_ < 1 || num_y_bins_ < 1) {
494  throw std::runtime_error("Invalid GeoRaster (" + std::to_string(num_x_bins_) + "x" +
495  std::to_string(num_y_bins_) + " bins)");
496  }
497 
502 
503  } else {
506 
507  if (num_x_bins_ < 1 || num_y_bins_ < 1) {
508  throw std::runtime_error("Invalid GeoRaster (" + std::to_string(num_x_bins_) + "x" +
509  std::to_string(num_y_bins_) + " bins)");
510  }
511 
516  }
518 }
#define CHECK_GT(x, y)
Definition: Logger.h:305
std::string to_string(char const *&&v)
const bool geographic_coords_
EXTENSION_NOINLINE double distance_in_meters(const double fromlon, const double fromlat, const double tolon, const double tolat)
Computes the distance, in meters, between two WGS-84 positions.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T , typename Z >
void GeoRaster< T, Z >::calculate_slope_and_aspect ( Column< Z > &  slope,
Column< Z > &  aspect,
const bool  compute_slope_in_degrees 
) const

Definition at line 1020 of file GeoRasterTableFunctions.hpp.

References CHECK_EQ, DEBUG_TIMER, threading_serial::parallel_for(), Column< T >::setNull(), Column< T >::size(), and x_y_bin_to_bin_index().

Referenced by tf_geo_rasterize_slope__cpu_template().

1023  {
1024  auto timer = DEBUG_TIMER(__func__);
1025  CHECK_EQ(slope.size(), num_bins_);
1027  tbb::blocked_range<int64_t>(0, num_y_bins_),
1028  [&](const tbb::blocked_range<int64_t>& r) {
1029  std::vector<Z> neighboring_z_vals(9); // 3X3 calc
1030  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
1031  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
1032  const bool not_null =
1033  get_nxn_neighbors_if_not_null(x_bin, y_bin, 1, neighboring_z_vals);
1034  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
1035  if (!not_null) {
1036  slope.setNull(bin_idx);
1037  aspect.setNull(bin_idx);
1038  } else {
1039  const auto slope_and_aspect = calculate_slope_and_aspect_of_cell(
1040  neighboring_z_vals, compute_slope_in_degrees);
1041  slope[bin_idx] = slope_and_aspect.first;
1042  if (slope_and_aspect.second == null_sentinel_) {
1043  aspect.setNull(bin_idx);
1044  } else {
1045  aspect[bin_idx] = slope_and_aspect.second;
1046  }
1047  }
1048  }
1049  }
1050  });
1051 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
bool get_nxn_neighbors_if_not_null(const int64_t x_bin, const int64_t y_bin, const int64_t num_bins_radius, std::vector< Z > &neighboring_bins) const
std::pair< Z, Z > calculate_slope_and_aspect_of_cell(const std::vector< Z > &neighboring_cells, const bool compute_slope_in_degrees) const
DEVICE int64_t size() const
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
DEVICE void setNull(int64_t index)
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:412

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T , typename Z >
std::pair< Z, Z > GeoRaster< T, Z >::calculate_slope_and_aspect_of_cell ( const std::vector< Z > &  neighboring_cells,
const bool  compute_slope_in_degrees 
) const
inline

Definition at line 993 of file GeoRasterTableFunctions.hpp.

References math_consts::radians_to_degrees.

995  {
996  const Z dz_dx =
997  ((neighboring_cells[8] + 2 * neighboring_cells[5] + neighboring_cells[2]) -
998  (neighboring_cells[6] + 2 * neighboring_cells[3] + neighboring_cells[0])) /
999  (8 * bin_dim_meters_);
1000  const Z dz_dy =
1001  ((neighboring_cells[6] + 2 * neighboring_cells[7] + neighboring_cells[8]) -
1002  (neighboring_cells[0] + 2 * neighboring_cells[1] + neighboring_cells[2])) /
1003  (8 * bin_dim_meters_);
1004  const Z slope = sqrt(dz_dx * dz_dx + dz_dy * dz_dy);
1005  std::pair<Z, Z> slope_and_aspect;
1006  slope_and_aspect.first =
1007  compute_slope_in_degrees ? atan(slope) * math_consts::radians_to_degrees : slope;
1008  if (slope < 0.0001) {
1009  slope_and_aspect.second = null_sentinel_;
1010  } else {
1011  const Z aspect_degrees =
1012  math_consts::radians_to_degrees * atan2(dz_dx, dz_dy); // -180.0 to 180.0
1013  slope_and_aspect.second = aspect_degrees + 180.0;
1014  // aspect_degrees < 0.0 ? 180.0 + aspect_degrees : aspect_degrees;
1015  }
1016  return slope_and_aspect;
1017 }
constexpr double radians_to_degrees
Definition: math_consts.h:23
template<typename T , typename Z >
template<typename T2 , typename Z2 >
void GeoRaster< T, Z >::compute ( const Column< T2 > &  input_x,
const Column< T2 > &  input_y,
const Column< Z2 > &  input_z,
std::vector< Z > &  output_z,
const RasterAggType  raster_agg_type,
const size_t  max_inputs_per_thread 
)

Definition at line 663 of file GeoRasterTableFunctions.hpp.

References AVG, CHECK, COUNT, MAX, max_inputs_per_thread, MIN, threading_serial::parallel_for(), and SUM.

Referenced by GeoRaster< T, Z >::GeoRaster().

668  {
669  switch (raster_agg_type) {
670  case RasterAggType::COUNT: {
671  computeParallelImpl<RasterAggType::COUNT, T2, Z2>(
672  input_x, input_y, input_z, output_z, max_inputs_per_thread);
673  break;
674  }
675  case RasterAggType::MIN: {
676  computeParallelImpl<RasterAggType::MIN, T2, Z2>(
677  input_x, input_y, input_z, output_z, max_inputs_per_thread);
678  break;
679  }
680  case RasterAggType::MAX: {
681  computeParallelImpl<RasterAggType::MAX, T2, Z2>(
682  input_x, input_y, input_z, output_z, max_inputs_per_thread);
683  break;
684  }
685  case RasterAggType::SUM: {
686  computeParallelImpl<RasterAggType::SUM, T2, Z2>(
687  input_x, input_y, input_z, output_z, max_inputs_per_thread);
688  break;
689  }
690  case RasterAggType::AVG: {
691  computeParallelImpl<RasterAggType::SUM, T2, Z2>(
692  input_x, input_y, input_z, output_z, max_inputs_per_thread);
693  computeParallelImpl<RasterAggType::COUNT, T2, Z2>(
694  input_x, input_y, input_z, counts_, max_inputs_per_thread);
695  tbb::parallel_for(tbb::blocked_range<size_t>(0, num_bins_),
696  [&](const tbb::blocked_range<size_t>& r) {
697  const size_t start_idx = r.begin();
698  const size_t end_idx = r.end();
699  for (size_t bin_idx = start_idx; bin_idx != end_idx;
700  ++bin_idx) {
701  // counts[bin_idx] > 1 will avoid division for nulls and 1
702  // counts
703  if (counts_[bin_idx] > 1) {
704  output_z[bin_idx] /= counts_[bin_idx];
705  }
706  }
707  });
708  break;
709  }
710  default: {
711  CHECK(false);
712  }
713  }
714 }
const size_t max_inputs_per_thread
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
std::vector< Z > counts_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T , typename Z >
template<RasterAggType AggType, typename T2 , typename Z2 >
void GeoRaster< T, Z >::computeParallelImpl ( const Column< T2 > &  input_x,
const Column< T2 > &  input_y,
const Column< Z2 > &  input_z,
std::vector< Z > &  output_z,
const size_t  max_inputs_per_thread 
)
private

Definition at line 589 of file GeoRasterTableFunctions.hpp.

References COUNT, DEBUG_TIMER, max_temp_output_entries, MIN, threading_serial::parallel_for(), Column< T >::size(), and x_y_bin_to_bin_index().

593  {
594  const size_t input_size = input_z.size();
595  const size_t max_thread_count = std::thread::hardware_concurrency();
596  const size_t num_threads_by_input_elements =
597  std::min(max_thread_count,
598  ((input_size + max_inputs_per_thread - 1) / max_inputs_per_thread));
599  const size_t num_threads_by_output_size =
600  std::min(max_thread_count, ((max_temp_output_entries + num_bins_ - 1) / num_bins_));
601  const size_t num_threads =
602  std::min(num_threads_by_input_elements, num_threads_by_output_size);
603  if (num_threads <= 1) {
604  computeSerialImpl<AggType, T2, Z2>(input_x, input_y, input_z, output_z);
605  return;
606  }
607  auto timer = DEBUG_TIMER(__func__);
608 
609  std::vector<std::vector<Z>> per_thread_z_outputs(num_threads);
610  // Fix
611  const Z agg_sentinel = AggType == RasterAggType::MIN ? std::numeric_limits<Z>::max()
612  : std::numeric_limits<Z>::lowest();
613 
614  tbb::parallel_for(tbb::blocked_range<size_t>(0, num_threads),
615  [&](const tbb::blocked_range<size_t>& r) {
616  for (size_t t = r.begin(); t != r.end(); ++t) {
617  per_thread_z_outputs[t].resize(num_bins_, agg_sentinel);
618  }
619  });
620 
621  ComputeAgg<AggType> compute_agg;
622  tbb::task_arena limited_arena(num_threads);
623  limited_arena.execute([&] {
625  tbb::blocked_range<int64_t>(0, input_size),
626  [&](const tbb::blocked_range<int64_t>& r) {
627  const int64_t start_idx = r.begin();
628  const int64_t end_idx = r.end();
629  size_t thread_idx = tbb::this_task_arena::current_thread_index();
630  std::vector<Z>& this_thread_z_output = per_thread_z_outputs[thread_idx];
631 
632  for (int64_t sparse_idx = start_idx; sparse_idx != end_idx; ++sparse_idx) {
633  auto const z = input_z[sparse_idx];
634  if constexpr (std::is_same_v<Z2, float> || std::is_same_v<Z2, double>) {
635  if (std::isnan(z) || std::isinf(z)) {
636  continue;
637  }
638  }
639  const int64_t x_bin = get_x_bin(input_x[sparse_idx]);
640  const int64_t y_bin = get_y_bin(input_y[sparse_idx]);
641  if (x_bin < 0 || x_bin >= num_x_bins_ || y_bin < 0 || y_bin >= num_y_bins_) {
642  continue;
643  }
644  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
645  compute_agg(z, this_thread_z_output[bin_idx], inline_null_value<Z2>());
646  }
647  });
648  });
649 
650  // Reduce
651  if constexpr (AggType == RasterAggType::COUNT) {
652  // Counts can't be counted, they must be summed
653  computeParallelReductionAggImpl<RasterAggType::SUM>(
654  per_thread_z_outputs, output_z, agg_sentinel);
655  } else {
656  computeParallelReductionAggImpl<AggType>(
657  per_thread_z_outputs, output_z, agg_sentinel);
658  }
659 }
const size_t max_temp_output_entries
DEVICE int64_t size() const
T get_y_bin(const T input) const
T get_x_bin(const T input) const
const size_t max_inputs_per_thread
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:412

+ Here is the call graph for this function:

template<typename T , typename Z >
template<RasterAggType AggType>
void GeoRaster< T, Z >::computeParallelReductionAggImpl ( const std::vector< std::vector< Z >> &  z_inputs,
std::vector< Z > &  output_z,
const Z  agg_sentinel 
)
private

Definition at line 556 of file GeoRasterTableFunctions.hpp.

References threading_serial::parallel_for().

559  {
560  const size_t num_inputs = z_inputs.size();
561  output_z.resize(num_bins_, agg_sentinel);
562 
563  ComputeAgg<AggType> reduction_agg;
565  tbb::blocked_range<size_t>(0, num_bins_), [&](const tbb::blocked_range<size_t>& r) {
566  const size_t start_idx = r.begin();
567  const size_t end_idx = r.end();
568  for (size_t bin_idx = start_idx; bin_idx != end_idx; ++bin_idx) {
569  for (size_t input_idx = 0; input_idx < num_inputs; ++input_idx) {
570  reduction_agg(z_inputs[input_idx][bin_idx], output_z[bin_idx], agg_sentinel);
571  }
572  }
573  });
574 
575  tbb::parallel_for(tbb::blocked_range<size_t>(0, num_bins_),
576  [&](const tbb::blocked_range<size_t>& r) {
577  const size_t start_idx = r.begin();
578  const size_t end_idx = r.end();
579  for (size_t bin_idx = start_idx; bin_idx != end_idx; ++bin_idx) {
580  if (output_z[bin_idx] == agg_sentinel) {
581  output_z[bin_idx] = null_sentinel_;
582  }
583  }
584  });
585 }
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())

+ Here is the call graph for this function:

template<typename T , typename Z >
template<RasterAggType AggType, typename T2 , typename Z2 >
void GeoRaster< T, Z >::computeSerialImpl ( const Column< T2 > &  input_x,
const Column< T2 > &  input_y,
const Column< Z2 > &  input_z,
std::vector< Z > &  output_z 
)
private

Definition at line 522 of file GeoRasterTableFunctions.hpp.

References DEBUG_TIMER, MIN, Column< T >::size(), and x_y_bin_to_bin_index().

525  {
526  auto timer = DEBUG_TIMER(__func__);
527  const int64_t input_size{input_z.size()};
528  const Z agg_sentinel = AggType == RasterAggType::MIN ? std::numeric_limits<Z>::max()
529  : std::numeric_limits<Z>::lowest();
530  output_z.resize(num_bins_, agg_sentinel);
531  ComputeAgg<AggType> compute_agg;
532  for (int64_t sparse_idx = 0; sparse_idx != input_size; ++sparse_idx) {
533  auto const z = input_z[sparse_idx];
534  if constexpr (std::is_same_v<Z2, float> || std::is_same_v<Z2, double>) {
535  if (std::isnan(z) || std::isinf(z)) {
536  continue;
537  }
538  }
539  const int64_t x_bin = get_x_bin(input_x[sparse_idx]);
540  const int64_t y_bin = get_y_bin(input_y[sparse_idx]);
541  if (x_bin < 0 || x_bin >= num_x_bins_ || y_bin < 0 || y_bin >= num_y_bins_) {
542  continue;
543  }
544  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
545  compute_agg(z, output_z[bin_idx], inline_null_value<Z2>());
546  }
547  for (int64_t bin_idx = 0; bin_idx != num_bins_; ++bin_idx) {
548  if (output_z[bin_idx] == agg_sentinel) {
549  output_z[bin_idx] = null_sentinel_;
550  }
551  }
552 }
DEVICE int64_t size() const
T get_y_bin(const T input) const
T get_x_bin(const T input) const
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
#define DEBUG_TIMER(name)
Definition: Logger.h:412

+ Here is the call graph for this function:

template<typename T , typename Z >
Z GeoRaster< T, Z >::fill_bin_from_avg_box_neighborhood ( const int64_t  x_centroid_bin,
const int64_t  y_centroid_bin,
const int64_t  bins_radius,
std::vector< Z > &  z 
) const
inlineprivate

Definition at line 717 of file GeoRasterTableFunctions.hpp.

References x_y_bin_to_bin_index().

720  {
721  Z val = 0.0;
722  int32_t count = 0;
723  for (int64_t y_bin = y_centroid_bin - bins_radius;
724  y_bin <= y_centroid_bin + bins_radius;
725  y_bin++) {
726  for (int64_t x_bin = x_centroid_bin - bins_radius;
727  x_bin <= x_centroid_bin + bins_radius;
728  x_bin++) {
729  if (x_bin >= 0 && x_bin < num_x_bins_ && y_bin >= 0 && y_bin < num_y_bins_) {
730  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
731  const Z bin_val = z[bin_idx];
732  if (bin_val != null_sentinel_) {
733  count++;
734  val += bin_val;
735  }
736  }
737  }
738  }
739  return (count == 0) ? null_sentinel_ : val / count;
740 }
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)

+ Here is the call graph for this function:

template<typename T , typename Z >
template<RasterAggType AggType>
Z GeoRaster< T, Z >::fill_bin_from_box_neighborhood ( const int64_t  x_centroid_bin,
const int64_t  y_centroid_bin,
const int64_t  bins_radius,
const ComputeAgg< AggType > &  compute_agg,
std::vector< Z > &  z 
) const
inlineprivate

Definition at line 846 of file GeoRasterTableFunctions.hpp.

References MIN, and x_y_bin_to_bin_index().

851  {
852  const Z agg_sentinel = AggType == RasterAggType::MIN ? std::numeric_limits<Z>::max()
853  : std::numeric_limits<Z>::lowest();
854  Z val{agg_sentinel};
855  for (int64_t y_bin = y_centroid_bin - bins_radius;
856  y_bin <= y_centroid_bin + bins_radius;
857  y_bin++) {
858  for (int64_t x_bin = x_centroid_bin - bins_radius;
859  x_bin <= x_centroid_bin + bins_radius;
860  x_bin++) {
861  if (x_bin >= 0 && x_bin < num_x_bins_ && y_bin >= 0 && y_bin < num_y_bins_) {
862  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
863  compute_agg(z[bin_idx], val, null_sentinel_);
864  }
865  }
866  }
867  return val == agg_sentinel ? null_sentinel_ : val;
868 }
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)

+ Here is the call graph for this function:

template<typename T , typename Z >
template<RasterAggType AggType>
void GeoRaster< T, Z >::fill_bins_from_box_neighborhood ( const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
std::vector< Z > &  z 
)
private

Definition at line 872 of file GeoRasterTableFunctions.hpp.

References AVG, BOX_AVG, CHECK, GAUSS_AVG, INVALID, threading_serial::parallel_for(), and x_y_bin_to_bin_index().

875  {
876  CHECK(AggType != RasterAggType::GAUSS_AVG); // Should have gone down Gaussian path
877  CHECK(AggType != RasterAggType::AVG); // Should be BOX_AVG for fill pass
878  CHECK(AggType != RasterAggType::INVALID);
879  std::vector<Z> new_z(num_bins_);
880  ComputeAgg<AggType> compute_agg;
881  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_y_bins_),
882  [&](const tbb::blocked_range<int64_t>& r) {
883  const int64_t end_y_bin = r.end();
884  for (int64_t y_bin = r.begin(); y_bin != end_y_bin; ++y_bin) {
885  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
886  const int64_t bin_idx =
887  x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
888  const Z z_val = z[bin_idx];
889  if (!fill_only_nulls || z_val == null_sentinel_) {
890  if constexpr (AggType == RasterAggType::BOX_AVG) {
891  new_z[bin_idx] = fill_bin_from_avg_box_neighborhood(
892  x_bin, y_bin, neighborhood_fill_radius, z);
893  } else {
894  new_z[bin_idx] = fill_bin_from_box_neighborhood(
895  x_bin, y_bin, neighborhood_fill_radius, compute_agg, z);
896  }
897  } else {
898  new_z[bin_idx] = z_val;
899  }
900  }
901  }
902  });
903  z.swap(new_z);
904 }
Z fill_bin_from_avg_box_neighborhood(const int64_t x_centroid_bin, const int64_t y_centroid_bin, const int64_t bins_radius, std::vector< Z > &z) const
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
Z fill_bin_from_box_neighborhood(const int64_t x_centroid_bin, const int64_t y_centroid_bin, const int64_t bins_radius, const ComputeAgg< AggType > &compute_agg, std::vector< Z > &z) const
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

template<typename T , typename Z >
void GeoRaster< T, Z >::fill_bins_from_gaussian_neighborhood ( const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
std::vector< Z > &  z 
)
private

Definition at line 745 of file GeoRasterTableFunctions.hpp.

References generate_1d_gaussian_kernel(), threading_serial::parallel_for(), and x_y_bin_to_bin_index().

748  {
749  const double sigma = neighborhood_fill_radius * 2.0 / 6.0;
750  const auto gaussian_kernel =
751  generate_1d_gaussian_kernel(neighborhood_fill_radius, sigma);
752  std::vector<Z> only_nulls_source_z;
753  if (fill_only_nulls) {
754  // Copy z_
755  only_nulls_source_z.resize(z.size());
756  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_bins_),
757  [&](const tbb::blocked_range<int64_t>& r) {
758  const int64_t end_bin_idx = r.end();
759  for (int64_t bin_idx = r.begin(); bin_idx < end_bin_idx;
760  ++bin_idx) {
761  only_nulls_source_z[bin_idx] = z[bin_idx];
762  }
763  });
764  }
765  auto& source_z = fill_only_nulls ? only_nulls_source_z : z;
766 
767  std::vector<Z> new_z(num_bins_);
769  tbb::blocked_range<int64_t>(0, num_y_bins_),
770  [&](const tbb::blocked_range<int64_t>& r) {
771  const int64_t end_y_bin = r.end();
772  for (int64_t y_start_bin = r.begin(); y_start_bin != end_y_bin; ++y_start_bin) {
773  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
774  Z val = 0.0;
775  Z sum_weights = 0.0;
776  for (int64_t y_offset = -neighborhood_fill_radius;
777  y_offset <= neighborhood_fill_radius;
778  ++y_offset) {
779  const auto y_bin = y_start_bin + y_offset;
780  if (y_bin >= 0 && y_bin < num_y_bins_) {
781  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
782  const Z bin_val = source_z[bin_idx];
783  if (bin_val != null_sentinel_) {
784  const auto gaussian_weight =
785  gaussian_kernel[y_offset + neighborhood_fill_radius];
786  val += bin_val * gaussian_weight;
787  sum_weights += gaussian_weight;
788  }
789  }
790  }
791  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_start_bin, num_x_bins_);
792  new_z[bin_idx] = sum_weights > 0.0 ? (val / sum_weights) : null_sentinel_;
793  }
794  }
795  });
796  source_z.swap(new_z);
798  tbb::blocked_range<int64_t>(0, num_x_bins_),
799  [&](const tbb::blocked_range<int64_t>& r) {
800  const int64_t end_x_bin = r.end();
801  for (int64_t x_start_bin = r.begin(); x_start_bin != end_x_bin; ++x_start_bin) {
802  for (int64_t y_bin = 0; y_bin < num_y_bins_; ++y_bin) {
803  Z val = 0.0;
804  Z sum_weights = 0.0;
805  for (int64_t x_offset = -neighborhood_fill_radius;
806  x_offset <= neighborhood_fill_radius;
807  ++x_offset) {
808  const auto x_bin = x_start_bin + x_offset;
809  if (x_bin >= 0 && x_bin < num_x_bins_) {
810  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
811  const Z bin_val = source_z[bin_idx];
812  if (bin_val != null_sentinel_) {
813  const auto gaussian_weight =
814  gaussian_kernel[x_offset + neighborhood_fill_radius];
815  val += bin_val * gaussian_weight;
816  sum_weights += gaussian_weight;
817  }
818  }
819  }
820  const int64_t bin_idx = x_y_bin_to_bin_index(x_start_bin, y_bin, num_x_bins_);
821  new_z[bin_idx] = sum_weights > 0.0 ? (val / sum_weights) : null_sentinel_;
822  }
823  }
824  });
825  if (fill_only_nulls) {
826  // Only copy convolved results in new_z back to z for
827  // values in z that are null
828  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_bins_),
829  [&](const tbb::blocked_range<int64_t>& r) {
830  const int64_t end_bin_idx = r.end();
831  for (int64_t bin_idx = r.begin(); bin_idx < end_bin_idx;
832  ++bin_idx) {
833  if (z[bin_idx] == null_sentinel_) {
834  z[bin_idx] = new_z[bin_idx];
835  }
836  only_nulls_source_z[bin_idx] = z[bin_idx];
837  }
838  });
839  } else {
840  source_z.swap(new_z);
841  }
842 }
std::vector< double > generate_1d_gaussian_kernel(const int64_t fill_radius, double sigma)
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())

+ Here is the call graph for this function:

template<typename T , typename Z >
void GeoRaster< T, Z >::fill_bins_from_neighbors ( const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
const RasterAggType  raster_agg_type = RasterAggType::GAUSS_AVG 
)

Definition at line 907 of file GeoRasterTableFunctions.hpp.

Referenced by geo_rasterize_impl(), tf_geo_multi_rasterize__cpu_template(), tf_geo_rasterize__cpu_template(), and tf_geo_rasterize_slope__cpu_template().

909  {
911  neighborhood_fill_radius, fill_only_nulls, raster_fill_agg_type, z_);
912 }
void fill_bins_from_neighbors(const int64_t neighborhood_fill_radius, const bool fill_only_nulls, const RasterAggType raster_agg_type=RasterAggType::GAUSS_AVG)
std::vector< Z > z_

+ Here is the caller graph for this function:

template<typename T , typename Z >
void GeoRaster< T, Z >::fill_bins_from_neighbors ( const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
const RasterAggType  raster_agg_type,
std::vector< Z > &  z 
)

Definition at line 915 of file GeoRasterTableFunctions.hpp.

References AVG, BOX_AVG, COUNT, DEBUG_TIMER, GAUSS_AVG, MAX, MIN, SUM, and UNREACHABLE.

918  {
919  auto timer = DEBUG_TIMER(__func__);
920  // Note: only GAUSSIAN_AVG supports Gaussian 2-pass technique currently,
921  // as only an AVG aggregate makes sense for Gaussian blur. However we
922  // should be able to implement 2-pass box convolution for the other aggregates
923  // when time allows for better performance with wide kernel sizes
924  // Todo (Todd): Implement 2-pass box blur
925 
926  switch (raster_fill_agg_type) {
927  case RasterAggType::COUNT: {
928  fill_bins_from_box_neighborhood<RasterAggType::COUNT>(
929  neighborhood_fill_radius, fill_only_nulls, z);
930  break;
931  }
932  case RasterAggType::MIN: {
933  fill_bins_from_box_neighborhood<RasterAggType::MIN>(
934  neighborhood_fill_radius, fill_only_nulls, z);
935  break;
936  }
937  case RasterAggType::MAX: {
938  fill_bins_from_box_neighborhood<RasterAggType::MAX>(
939  neighborhood_fill_radius, fill_only_nulls, z);
940  break;
941  }
942  case RasterAggType::SUM: {
943  fill_bins_from_box_neighborhood<RasterAggType::SUM>(
944  neighborhood_fill_radius, fill_only_nulls, z);
945  break;
946  }
947  case RasterAggType::BOX_AVG: {
948  fill_bins_from_box_neighborhood<RasterAggType::BOX_AVG>(
949  neighborhood_fill_radius, fill_only_nulls, z);
950  break;
951  }
952  case RasterAggType::AVG:
954  fill_bins_from_gaussian_neighborhood(neighborhood_fill_radius, fill_only_nulls, z);
955  break;
956  }
957  default: {
958  UNREACHABLE();
959  }
960  }
961 }
#define UNREACHABLE()
Definition: Logger.h:338
#define DEBUG_TIMER(name)
Definition: Logger.h:412
void fill_bins_from_gaussian_neighborhood(const int64_t neighborhood_fill_radius, const bool fill_only_nulls, std::vector< Z > &z)
template<typename T, typename Z>
std::pair<int64_t, Z> GeoRaster< T, Z >::get_bin_idx_and_z_val_for_xy_bin ( const int64_t  x_bin,
const int64_t  y_bin 
) const
inline

Definition at line 161 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::BIN_OUT_OF_BOUNDS, GeoRaster< T, Z >::is_bin_out_of_bounds(), GeoRaster< T, Z >::null_sentinel_, GeoRaster< T, Z >::num_x_bins_, x_y_bin_to_bin_index(), and GeoRaster< T, Z >::z_.

163  {
164  if (is_bin_out_of_bounds(x_bin, y_bin)) {
165  return std::make_pair(BIN_OUT_OF_BOUNDS, null_sentinel_);
166  }
167  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
168  return std::make_pair(bin_idx, z_[bin_idx]);
169  }
bool is_bin_out_of_bounds(const int64_t x_bin, const int64_t y_bin) const
static constexpr int64_t BIN_OUT_OF_BOUNDS
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
std::vector< Z > z_

+ Here is the call graph for this function:

template<typename T, typename Z>
int64_t GeoRaster< T, Z >::get_bin_idx_for_xy_coords ( const T  x,
const T  y 
) const
inline

Definition at line 171 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::BIN_OUT_OF_BOUNDS, GeoRaster< T, Z >::get_x_bin(), GeoRaster< T, Z >::get_y_bin(), GeoRaster< T, Z >::num_x_bins_, GeoRaster< T, Z >::x_max_, x_y_bin_to_bin_index(), and GeoRaster< T, Z >::y_max_.

171  {
172  if (x < x_min_ || x > x_max_ || y < y_min_ || y > y_max_) {
173  return BIN_OUT_OF_BOUNDS;
174  }
176  }
T get_y_bin(const T input) const
T get_x_bin(const T input) const
static constexpr int64_t BIN_OUT_OF_BOUNDS
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)

+ Here is the call graph for this function:

template<typename T , typename Z >
bool GeoRaster< T, Z >::get_nxn_neighbors_if_not_null ( const int64_t  x_bin,
const int64_t  y_bin,
const int64_t  num_bins_radius,
std::vector< Z > &  neighboring_bins 
) const

Definition at line 964 of file GeoRasterTableFunctions.hpp.

References CHECK_EQ, and x_y_bin_to_bin_index().

968  {
969  const size_t num_bins_per_dim = num_bins_radius * 2 + 1;
970  CHECK_EQ(neighboring_bins.size(), num_bins_per_dim * num_bins_per_dim);
971  const int64_t end_y_bin_idx = y_bin + num_bins_radius;
972  const int64_t end_x_bin_idx = x_bin + num_bins_radius;
973  size_t output_bin = 0;
974  for (int64_t y_bin_idx = y_bin - num_bins_radius; y_bin_idx <= end_y_bin_idx;
975  ++y_bin_idx) {
976  for (int64_t x_bin_idx = x_bin - num_bins_radius; x_bin_idx <= end_x_bin_idx;
977  ++x_bin_idx) {
978  if (x_bin_idx < 0 || x_bin_idx >= num_x_bins_ || y_bin_idx < 0 ||
979  y_bin_idx >= num_y_bins_) {
980  return false;
981  }
982  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin_idx, y_bin_idx, num_x_bins_);
983  neighboring_bins[output_bin++] = z_[bin_idx];
984  if (z_[bin_idx] == null_sentinel_) {
985  return false;
986  }
987  }
988  }
989  return true; // not_null
990 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
std::vector< Z > z_

+ Here is the call graph for this function:

template<typename T, typename Z>
T GeoRaster< T, Z >::get_x_bin ( const T  input) const
inline

Definition at line 147 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::x_min_, and GeoRaster< T, Z >::x_scale_input_to_bin_.

Referenced by GeoRaster< T, Z >::get_bin_idx_for_xy_coords().

147  {
148  return (input - x_min_) * x_scale_input_to_bin_;
149  }

+ Here is the caller graph for this function:

template<typename T, typename Z>
std::pair<T, T> GeoRaster< T, Z >::get_xy_coords_for_bin_idx ( const int64_t  bin_idx) const
inline

Definition at line 178 of file GeoRasterTableFunctions.hpp.

References bin_to_x_y_bin_indexes(), GeoRaster< T, Z >::num_x_bins_, heavydb.dtypes::T, GeoRaster< T, Z >::x_min_, GeoRaster< T, Z >::x_scale_bin_to_input_, GeoRaster< T, Z >::y_min_, and GeoRaster< T, Z >::y_scale_bin_to_input_.

178  {
179  const auto [x_bin, y_bin] = bin_to_x_y_bin_indexes(bin_idx, num_x_bins_);
180  const T x = x_min_ + (x_bin + 0.5) * x_scale_bin_to_input_;
181  const T y = y_min_ + (y_bin + 0.5) * y_scale_bin_to_input_;
182  return std::make_pair(x, y);
183  }
std::pair< int64_t, int64_t > bin_to_x_y_bin_indexes(const int64_t bin, const int64_t num_x_bins)

+ Here is the call graph for this function:

template<typename T, typename Z>
T GeoRaster< T, Z >::get_y_bin ( const T  input) const
inline

Definition at line 151 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::y_min_, and GeoRaster< T, Z >::y_scale_input_to_bin_.

Referenced by GeoRaster< T, Z >::get_bin_idx_for_xy_coords().

151  {
152  return (input - y_min_) * y_scale_input_to_bin_;
153  }

+ Here is the caller graph for this function:

template<typename T, typename Z>
bool GeoRaster< T, Z >::is_bin_out_of_bounds ( const int64_t  x_bin,
const int64_t  y_bin 
) const
inline

Definition at line 157 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::num_x_bins_, and GeoRaster< T, Z >::num_y_bins_.

Referenced by GeoRaster< T, Z >::get_bin_idx_and_z_val_for_xy_bin().

157  {
158  return (x_bin < 0 || x_bin >= num_x_bins_ || y_bin < 0 || y_bin >= num_y_bins_);
159  }

+ Here is the caller graph for this function:

template<typename T, typename Z>
bool GeoRaster< T, Z >::is_null ( const Z  value) const
inline

Definition at line 155 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::null_sentinel_.

155 { return value == null_sentinel_; }
template<typename T , typename Z >
Z GeoRaster< T, Z >::offset_source_z_from_raster_z ( const int64_t  source_x_bin,
const int64_t  source_y_bin,
const Z  source_z_offset 
) const
inline

Definition at line 429 of file GeoRasterTableFunctions.hpp.

References x_y_bin_to_bin_index().

431  {
432  if (is_bin_out_of_bounds(source_x_bin, source_y_bin)) {
433  return null_sentinel_;
434  }
435  const Z terrain_z = z_[x_y_bin_to_bin_index(source_x_bin, source_y_bin, num_x_bins_)];
436  if (terrain_z == null_sentinel_) {
437  return terrain_z;
438  }
439  return terrain_z + source_z_offset;
440 }
bool is_bin_out_of_bounds(const int64_t x_bin, const int64_t y_bin) const
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
std::vector< Z > z_

+ Here is the call graph for this function:

template<typename T , typename Z >
Z GeoRaster< T, Z >::offset_source_z_from_raster_z ( const int64_t  source_x_bin,
const int64_t  source_y_bin,
const Z  source_z_offset,
const int64_t  z_col_idx 
) const
inline

Definition at line 443 of file GeoRasterTableFunctions.hpp.

References x_y_bin_to_bin_index().

446  {
447  if (is_bin_out_of_bounds(source_x_bin, source_y_bin)) {
448  return null_sentinel_;
449  }
450  const Z terrain_z =
451  z_cols_[z_col_idx][x_y_bin_to_bin_index(source_x_bin, source_y_bin, num_x_bins_)];
452  if (terrain_z == null_sentinel_) {
453  return terrain_z;
454  }
455  return terrain_z + source_z_offset;
456 }
std::vector< std::vector< Z > > z_cols_
bool is_bin_out_of_bounds(const int64_t x_bin, const int64_t y_bin) const
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)

+ Here is the call graph for this function:

template<typename T , typename Z >
int64_t GeoRaster< T, Z >::outputDenseColumn ( TableFunctionManager mgr,
Column< Z > &  output_z,
const int64_t  band_idx 
) const

Definition at line 1120 of file GeoRasterTableFunctions.hpp.

References DEBUG_TIMER, threading_serial::parallel_for(), Column< T >::setNull(), and x_y_bin_to_bin_index().

1122  {
1123  const std::vector<Z>& z = z_cols_.empty() ? z_ : z_cols_[band_idx];
1124 
1125  auto timer = DEBUG_TIMER(__func__);
1126  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_y_bins_),
1127  [&](const tbb::blocked_range<int64_t>& r) {
1128  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
1129  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
1130  const int64_t bin_idx =
1131  x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
1132  const Z z_val = z[bin_idx];
1133  if (z_val == null_sentinel_) {
1134  output_z.setNull(bin_idx);
1135  } else {
1136  output_z[bin_idx] = z_val;
1137  }
1138  }
1139  }
1140  });
1141  return num_bins_;
1142 }
std::vector< std::vector< Z > > z_cols_
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
DEVICE void setNull(int64_t index)
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:412
std::vector< Z > z_

+ Here is the call graph for this function:

template<typename T , typename Z >
int64_t GeoRaster< T, Z >::outputDenseColumns ( TableFunctionManager mgr,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Z > &  output_z,
const int64_t  band_idx = 0 
) const

Definition at line 1090 of file GeoRasterTableFunctions.hpp.

References DEBUG_TIMER, threading_serial::parallel_for(), TableFunctionManager::set_output_row_size(), Column< T >::setNull(), and x_y_bin_to_bin_index().

Referenced by geo_rasterize_impl(), tf_geo_multi_rasterize__cpu_template(), tf_geo_rasterize__cpu_template(), and tf_geo_rasterize_slope__cpu_template().

1094  {
1095  const std::vector<Z>& z = z_cols_.empty() ? z_ : z_cols_[band_idx];
1096 
1097  auto timer = DEBUG_TIMER(__func__);
1100  tbb::blocked_range<int64_t>(0, num_y_bins_),
1101  [&](const tbb::blocked_range<int64_t>& r) {
1102  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
1103  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
1104  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
1105  output_x[bin_idx] = x_min_ + (x_bin + 0.5) * x_scale_bin_to_input_;
1106  output_y[bin_idx] = y_min_ + (y_bin + 0.5) * y_scale_bin_to_input_;
1107  const Z z_val = z[bin_idx];
1108  if (z_val == null_sentinel_) {
1109  output_z.setNull(bin_idx);
1110  } else {
1111  output_z[bin_idx] = z_val;
1112  }
1113  }
1114  }
1115  });
1116  return num_bins_;
1117 }
void set_output_row_size(int64_t num_rows)
Definition: heavydbTypes.h:373
std::vector< std::vector< Z > > z_cols_
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
DEVICE void setNull(int64_t index)
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:412
std::vector< Z > z_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T , typename Z >
int64_t GeoRaster< T, Z >::outputDenseColumns ( TableFunctionManager mgr,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Array< Z >> &  output_z 
) const

Definition at line 1171 of file GeoRasterTableFunctions.hpp.

References DEBUG_TIMER, TableFunctionManager::set_output_array_values_total_number(), TableFunctionManager::set_output_row_size(), and x_y_bin_to_bin_index().

1174  {
1175  auto timer = DEBUG_TIMER(__func__);
1176  const int64_t num_z_cols = static_cast<int64_t>(z_cols_.size());
1178  /*output column index=*/2,
1179  /*upper bound to the number of items in all output arrays=*/num_bins_ * num_z_cols);
1181  for (int64_t y_bin = 0; y_bin != num_y_bins_; ++y_bin) {
1182  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
1183  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
1184  output_x[bin_idx] = x_min_ + (x_bin + 0.5) * x_scale_bin_to_input_;
1185  output_y[bin_idx] = y_min_ + (y_bin + 0.5) * y_scale_bin_to_input_;
1186  Array<Z> z_array = output_z.getItem(bin_idx, num_z_cols);
1187  for (int64_t z_col_idx = 0; z_col_idx < num_z_cols; ++z_col_idx) {
1188  const Z z_val = z_cols_[z_col_idx][bin_idx];
1189  z_array[z_col_idx] = z_val;
1190  }
1191  }
1192  }
1193  return num_bins_;
1194 }
void set_output_row_size(int64_t num_rows)
Definition: heavydbTypes.h:373
std::vector< std::vector< Z > > z_cols_
void set_output_array_values_total_number(int32_t index, int64_t output_array_values_total_number)
Definition: heavydbTypes.h:361
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
#define DEBUG_TIMER(name)
Definition: Logger.h:412

+ Here is the call graph for this function:

template<typename T , typename Z >
int64_t GeoRaster< T, Z >::outputDenseColumnsAndFill ( TableFunctionManager mgr,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Z > &  output_z,
const int64_t  neighborhood_null_fill_radius 
) const

Definition at line 1054 of file GeoRasterTableFunctions.hpp.

References DEBUG_TIMER, threading_serial::parallel_for(), TableFunctionManager::set_output_row_size(), Column< T >::setNull(), and x_y_bin_to_bin_index().

1059  {
1060  auto timer = DEBUG_TIMER(__func__);
1063  tbb::blocked_range<int64_t>(0, num_y_bins_),
1064  [&](const tbb::blocked_range<int64_t>& r) {
1065  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
1066  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
1067  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
1068  output_x[bin_idx] = x_min_ + (x_bin + 0.5) * x_scale_bin_to_input_;
1069  output_y[bin_idx] = y_min_ + (y_bin + 0.5) * y_scale_bin_to_input_;
1070  const Z z_val = z_[bin_idx];
1071  if (z_val == null_sentinel_) {
1072  output_z.setNull(bin_idx);
1073  if (neighborhood_null_fill_radius) {
1074  const Z avg_neighbor_value = fill_bin_from_avg_box_neighborhood(
1075  x_bin, y_bin, neighborhood_null_fill_radius);
1076  if (avg_neighbor_value != null_sentinel_) {
1077  output_z[bin_idx] = avg_neighbor_value;
1078  }
1079  }
1080  } else {
1081  output_z[bin_idx] = z_[bin_idx];
1082  }
1083  }
1084  }
1085  });
1086  return num_bins_;
1087 }
void set_output_row_size(int64_t num_rows)
Definition: heavydbTypes.h:373
Z fill_bin_from_avg_box_neighborhood(const int64_t x_centroid_bin, const int64_t y_centroid_bin, const int64_t bins_radius, std::vector< Z > &z) const
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
DEVICE void setNull(int64_t index)
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:412
std::vector< Z > z_

+ Here is the call graph for this function:

template<typename T , typename Z >
void GeoRaster< T, Z >::setMetadata ( TableFunctionManager mgr) const

Definition at line 1197 of file GeoRasterTableFunctions.hpp.

References TableFunctionManager::set_metadata().

Referenced by geo_rasterize_impl(), tf_geo_multi_rasterize__cpu_template(), tf_geo_rasterize__cpu_template(), and tf_geo_rasterize_slope__cpu_template().

1197  {
1198  mgr.set_metadata("geo_raster_num_x_bins", num_x_bins_);
1199  mgr.set_metadata("geo_raster_num_y_bins", num_y_bins_);
1200  mgr.set_metadata("geo_raster_x_min", static_cast<double>(x_min_));
1201  mgr.set_metadata("geo_raster_y_min", static_cast<double>(y_min_));
1202  mgr.set_metadata("geo_raster_x_scale_input_to_bin",
1203  static_cast<double>(x_scale_input_to_bin_));
1204  mgr.set_metadata("geo_raster_y_scale_input_to_bin",
1205  static_cast<double>(y_scale_input_to_bin_));
1206 }
void set_metadata(const std::string &key, const T &value)
Definition: heavydbTypes.h:388

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

template<typename T, typename Z>
const T GeoRaster< T, Z >::bin_dim_meters_

Definition at line 91 of file GeoRasterTableFunctions.hpp.

template<typename T, typename Z>
constexpr int64_t GeoRaster< T, Z >::BIN_OUT_OF_BOUNDS {-1}
static
template<typename T, typename Z>
std::vector<Z> GeoRaster< T, Z >::counts_

Definition at line 97 of file GeoRasterTableFunctions.hpp.

template<typename T, typename Z>
const bool GeoRaster< T, Z >::geographic_coords_

Definition at line 92 of file GeoRasterTableFunctions.hpp.

Referenced by GeoRaster< T, Z >::GeoRaster().

template<typename T, typename Z>
const bool GeoRaster< T, Z >::is_multi_z_

Definition at line 94 of file GeoRasterTableFunctions.hpp.

template<typename T, typename Z>
const Z GeoRaster< T, Z >::null_sentinel_
template<typename T, typename Z>
int64_t GeoRaster< T, Z >::num_bins_ {0}

Definition at line 108 of file GeoRasterTableFunctions.hpp.

Referenced by GeoRaster< T, Z >::GeoRaster().

template<typename T, typename Z>
int64_t GeoRaster< T, Z >::num_y_bins_ {0}
template<typename T, typename Z>
T GeoRaster< T, Z >::x_max_ {0}
template<typename T, typename Z>
T GeoRaster< T, Z >::x_meters_per_degree_ {0}

Definition at line 104 of file GeoRasterTableFunctions.hpp.

template<typename T, typename Z>
T GeoRaster< T, Z >::x_min_
template<typename T, typename Z>
T GeoRaster< T, Z >::x_range_ {0}

Definition at line 102 of file GeoRasterTableFunctions.hpp.

template<typename T, typename Z>
T GeoRaster< T, Z >::x_scale_bin_to_input_ {0}
template<typename T, typename Z>
T GeoRaster< T, Z >::x_scale_input_to_bin_ {0}

Definition at line 109 of file GeoRasterTableFunctions.hpp.

Referenced by GeoRaster< T, Z >::get_x_bin().

template<typename T, typename Z>
T GeoRaster< T, Z >::y_max_ {0}
template<typename T, typename Z>
T GeoRaster< T, Z >::y_meters_per_degree_ {0}

Definition at line 105 of file GeoRasterTableFunctions.hpp.

template<typename T, typename Z>
T GeoRaster< T, Z >::y_min_ {0}
template<typename T, typename Z>
T GeoRaster< T, Z >::y_range_ {0}

Definition at line 103 of file GeoRasterTableFunctions.hpp.

template<typename T, typename Z>
T GeoRaster< T, Z >::y_scale_bin_to_input_ {0}
template<typename T, typename Z>
T GeoRaster< T, Z >::y_scale_input_to_bin_ {0}

Definition at line 110 of file GeoRasterTableFunctions.hpp.

Referenced by GeoRaster< T, Z >::get_y_bin().

template<typename T, typename Z>
std::vector<Z> GeoRaster< T, Z >::z_
template<typename T, typename Z>
std::vector<std::vector<Z> > GeoRaster< T, Z >::z_cols_

The documentation for this struct was generated from the following file: