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

#include <GeoRasterTableFunctions.h>

+ 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 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
 
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, 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)
 
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 outputDenseColumns (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 RasterAggType raster_agg_type_
 
const T bin_dim_meters_
 
const bool geographic_coords_
 
const Z null_sentinel_
 
std::vector< Z > z_
 
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) 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) const
 
template<RasterAggType AggType>
void fill_bins_from_box_neighborhood (const int64_t neighborhood_fill_radius, const bool fill_only_nulls)
 
void fill_bins_from_gaussian_neighborhood (const int64_t neighborhood_fill_radius, const bool fill_only_nulls)
 

Detailed Description

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

Definition at line 101 of file GeoRasterTableFunctions.h.

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 35 of file GeoRasterTableFunctions.cpp.

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_, and GeoRaster< T, Z >::y_min_.

42  : raster_agg_type_(raster_agg_type)
43  , bin_dim_meters_(bin_dim_meters)
44  , geographic_coords_(geographic_coords)
45  , null_sentinel_(inline_null_value<Z>()) {
46  auto timer = DEBUG_TIMER(__func__);
47  const int64_t input_size{input_z.size()};
48  if (input_size <= 0) {
49  num_bins_ = 0;
50  num_x_bins_ = 0;
51  num_y_bins_ = 0;
52  return;
53  }
54  const auto min_max_x = get_column_min_max(input_x);
55  const auto min_max_y = get_column_min_max(input_y);
56  x_min_ = min_max_x.first;
57  x_max_ = min_max_x.second;
58  y_min_ = min_max_y.first;
59  y_max_ = min_max_y.second;
60 
61  if (align_bins_to_zero_based_grid && !geographic_coords_) {
62  // For implicit, data-defined bounds, we treat the max of the x and y ranges as
63  // inclusive (closed interval), since if the max of the data in either x/y dimensions
64  // is at the first value of the next bin, values at that max will be discarded if we
65  // don't include the final bin. For exmaple, if the input data (perhaps already binned
66  // with a group by query) goes from 0.0 to 40.0 in both x and y directions, we should
67  // have the last x/y bins cover the range [40.0, 50.0), not [30.0, 40.0)
69  }
70 
72  compute(input_x, input_y, input_z, max_inputs_per_thread);
73 }
NEVER_INLINE HOST std::pair< T, T > get_column_min_max(const Column< T > &col)
DEVICE int64_t size() const
Definition: heavydbTypes.h:751
const size_t max_inputs_per_thread
const bool geographic_coords_
const RasterAggType raster_agg_type_
void compute(const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, const size_t max_inputs_per_thread)
#define DEBUG_TIMER(name)
Definition: Logger.h:411

+ 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 80 of file GeoRasterTableFunctions.cpp.

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_, and max_inputs_per_thread.

91  : raster_agg_type_(raster_agg_type)
92  , bin_dim_meters_(bin_dim_meters)
93  , geographic_coords_(geographic_coords)
94  , null_sentinel_(inline_null_value<Z>())
95  , x_min_(x_min)
96  , x_max_(x_max)
97  , y_min_(y_min)
98  , y_max_(y_max) {
99  auto timer = DEBUG_TIMER(__func__);
100  if (align_bins_to_zero_based_grid && !geographic_coords_) {
101  // For explicit, user-defined bounds, we treat the max of the x and y ranges as
102  // exclusive (open interval), since if the user specifies the max x/y as the end of
103  // the bin, they do not intend to add the next full bin For example, if a user
104  // specifies a bin_dim_meters of 10.0 and an x and y range from 0 to 40.0, they almost
105  // assuredly intend for there to be 4 bins in each of the x and y dimensions, with the
106  // last bin of range [30.0, 40.0), not 5 with the final bin's range from [40.0, 50.0)
108  }
110  compute(input_x, input_y, input_z, max_inputs_per_thread);
111 }
const size_t max_inputs_per_thread
const bool geographic_coords_
const RasterAggType raster_agg_type_
void compute(const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z, const size_t max_inputs_per_thread)
#define DEBUG_TIMER(name)
Definition: Logger.h:411

+ 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 138 of file GeoRasterTableFunctions.cpp.

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 128 of file GeoRasterTableFunctions.cpp.

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

128  {
129  x_min_ = std::floor(x_min_ / bin_dim_meters_) * bin_dim_meters_;
130  x_max_ = std::floor(x_max_ / bin_dim_meters_) * bin_dim_meters_ +
131  bin_dim_meters_; // Snap to end of bin
132  y_min_ = std::floor(y_min_ / bin_dim_meters_) * bin_dim_meters_;
133  y_max_ = std::floor(y_max_ / bin_dim_meters_) * bin_dim_meters_ +
134  bin_dim_meters_; // Snap to end of bin
135 }

+ Here is the caller graph for this function:

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

Definition at line 146 of file GeoRasterTableFunctions.cpp.

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

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

146  {
147  x_range_ = x_max_ - x_min_;
148  y_range_ = y_max_ - y_min_;
149  if (geographic_coords_) {
150  const T x_centroid = (x_min_ + x_max_) * 0.5;
151  const T y_centroid = (y_min_ + y_max_) * 0.5;
153  distance_in_meters(x_min_, y_centroid, x_max_, y_centroid) / x_range_;
154 
156  distance_in_meters(x_centroid, y_min_, x_centroid, y_max_) / y_range_;
157 
160 
165 
166  } else {
169 
174  }
176 }
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 664 of file GeoRasterTableFunctions.cpp.

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().

667  {
668  auto timer = DEBUG_TIMER(__func__);
669  CHECK_EQ(slope.size(), num_bins_);
671  tbb::blocked_range<int64_t>(0, num_y_bins_),
672  [&](const tbb::blocked_range<int64_t>& r) {
673  std::vector<Z> neighboring_z_vals(9); // 3X3 calc
674  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
675  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
676  const bool not_null =
677  get_nxn_neighbors_if_not_null(x_bin, y_bin, 1, neighboring_z_vals);
678  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
679  if (!not_null) {
680  slope.setNull(bin_idx);
681  aspect.setNull(bin_idx);
682  } else {
683  const auto slope_and_aspect = calculate_slope_and_aspect_of_cell(
684  neighboring_z_vals, compute_slope_in_degrees);
685  slope[bin_idx] = slope_and_aspect.first;
686  if (slope_and_aspect.second == null_sentinel_) {
687  aspect.setNull(bin_idx);
688  } else {
689  aspect[bin_idx] = slope_and_aspect.second;
690  }
691  }
692  }
693  }
694  });
695 }
#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
Definition: heavydbTypes.h:751
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)
Definition: heavydbTypes.h:755
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:411

+ 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 637 of file GeoRasterTableFunctions.cpp.

References math_consts::radians_to_degrees.

639  {
640  const Z dz_dx =
641  ((neighboring_cells[8] + 2 * neighboring_cells[5] + neighboring_cells[2]) -
642  (neighboring_cells[6] + 2 * neighboring_cells[3] + neighboring_cells[0])) /
643  (8 * bin_dim_meters_);
644  const Z dz_dy =
645  ((neighboring_cells[6] + 2 * neighboring_cells[7] + neighboring_cells[8]) -
646  (neighboring_cells[0] + 2 * neighboring_cells[1] + neighboring_cells[2])) /
647  (8 * bin_dim_meters_);
648  const Z slope = sqrt(dz_dx * dz_dx + dz_dy * dz_dy);
649  std::pair<Z, Z> slope_and_aspect;
650  slope_and_aspect.first =
651  compute_slope_in_degrees ? atan(slope) * math_consts::radians_to_degrees : slope;
652  if (slope < 0.0001) {
653  slope_and_aspect.second = null_sentinel_;
654  } else {
655  const Z aspect_degrees =
656  math_consts::radians_to_degrees * atan2(dz_dx, dz_dy); // -180.0 to 180.0
657  slope_and_aspect.second = aspect_degrees + 180.0;
658  // aspect_degrees < 0.0 ? 180.0 + aspect_degrees : aspect_degrees;
659  }
660  return slope_and_aspect;
661 }
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,
const size_t  max_inputs_per_thread 
)

Definition at line 313 of file GeoRasterTableFunctions.cpp.

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

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

316  {
317  switch (raster_agg_type_) {
318  case RasterAggType::COUNT: {
319  computeParallelImpl<RasterAggType::COUNT, T2, Z2>(
320  input_x, input_y, input_z, z_, max_inputs_per_thread);
321  break;
322  }
323  case RasterAggType::MIN: {
324  computeParallelImpl<RasterAggType::MIN, T2, Z2>(
325  input_x, input_y, input_z, z_, max_inputs_per_thread);
326  break;
327  }
328  case RasterAggType::MAX: {
329  computeParallelImpl<RasterAggType::MAX, T2, Z2>(
330  input_x, input_y, input_z, z_, max_inputs_per_thread);
331  break;
332  }
333  case RasterAggType::SUM: {
334  computeParallelImpl<RasterAggType::SUM, T2, Z2>(
335  input_x, input_y, input_z, z_, max_inputs_per_thread);
336  break;
337  }
338  case RasterAggType::AVG: {
339  computeParallelImpl<RasterAggType::SUM, T2, Z2>(
340  input_x, input_y, input_z, z_, max_inputs_per_thread);
341  computeParallelImpl<RasterAggType::COUNT, T2, Z2>(
342  input_x, input_y, input_z, counts_, max_inputs_per_thread);
343  tbb::parallel_for(tbb::blocked_range<size_t>(0, num_bins_),
344  [&](const tbb::blocked_range<size_t>& r) {
345  const size_t start_idx = r.begin();
346  const size_t end_idx = r.end();
347  for (size_t bin_idx = start_idx; bin_idx != end_idx;
348  ++bin_idx) {
349  // counts[bin_idx] > 1 will avoid division for nulls and 1
350  // counts
351  if (counts_[bin_idx] > 1) {
352  z_[bin_idx] /= counts_[bin_idx];
353  }
354  }
355  });
356  break;
357  }
358  default: {
359  CHECK(false);
360  }
361  }
362 }
const size_t max_inputs_per_thread
const RasterAggType raster_agg_type_
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
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 >
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 242 of file GeoRasterTableFunctions.cpp.

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

246  {
247  const size_t input_size = input_z.size();
248  const size_t max_thread_count = std::thread::hardware_concurrency();
249  const size_t num_threads_by_input_elements =
250  std::min(max_thread_count,
251  ((input_size + max_inputs_per_thread - 1) / max_inputs_per_thread));
252  const size_t num_threads_by_output_size =
253  std::min(max_thread_count, ((max_temp_output_entries + num_bins_ - 1) / num_bins_));
254  const size_t num_threads =
255  std::min(num_threads_by_input_elements, num_threads_by_output_size);
256  if (num_threads <= 1) {
257  computeSerialImpl<AggType, T2, Z2>(input_x, input_y, input_z, output_z);
258  return;
259  }
260  auto timer = DEBUG_TIMER(__func__);
261 
262  std::vector<std::vector<Z>> per_thread_z_outputs(num_threads);
263  // Fix
264  const Z agg_sentinel = raster_agg_type_ == RasterAggType::MIN
265  ? std::numeric_limits<Z>::max()
266  : std::numeric_limits<Z>::lowest();
267 
268  tbb::parallel_for(tbb::blocked_range<size_t>(0, num_threads),
269  [&](const tbb::blocked_range<size_t>& r) {
270  for (size_t t = r.begin(); t != r.end(); ++t) {
271  per_thread_z_outputs[t].resize(num_bins_, agg_sentinel);
272  }
273  });
274 
275  ComputeAgg<AggType> compute_agg;
276  tbb::task_arena limited_arena(num_threads);
277  limited_arena.execute([&] {
279  tbb::blocked_range<int64_t>(0, input_size),
280  [&](const tbb::blocked_range<int64_t>& r) {
281  const int64_t start_idx = r.begin();
282  const int64_t end_idx = r.end();
283  size_t thread_idx = tbb::this_task_arena::current_thread_index();
284  std::vector<Z>& this_thread_z_output = per_thread_z_outputs[thread_idx];
285 
286  for (int64_t sparse_idx = start_idx; sparse_idx != end_idx; ++sparse_idx) {
287  const int64_t x_bin = get_x_bin(input_x[sparse_idx]);
288  const int64_t y_bin = get_y_bin(input_y[sparse_idx]);
289  if (x_bin < 0 || x_bin >= num_x_bins_ || y_bin < 0 || y_bin >= num_y_bins_) {
290  continue;
291  }
292  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
293  compute_agg(input_z[sparse_idx],
294  this_thread_z_output[bin_idx],
295  inline_null_value<Z2>());
296  }
297  });
298  });
299 
300  // Reduce
301  if constexpr (AggType == RasterAggType::COUNT) {
302  // Counts can't be counted, they must be summed
303  computeParallelReductionAggImpl<RasterAggType::SUM>(
304  per_thread_z_outputs, output_z, agg_sentinel);
305  } else {
306  computeParallelReductionAggImpl<AggType>(
307  per_thread_z_outputs, output_z, agg_sentinel);
308  }
309 }
DEVICE int64_t size() const
Definition: heavydbTypes.h:751
const size_t max_inputs_per_thread
T get_y_bin(const T input) const
T get_x_bin(const T input) const
const size_t max_temp_output_entries
int64_t x_y_bin_to_bin_index(const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
const RasterAggType raster_agg_type_
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:411

+ 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 209 of file GeoRasterTableFunctions.cpp.

References threading_serial::parallel_for().

212  {
213  const size_t num_inputs = z_inputs.size();
214  output_z.resize(num_bins_, agg_sentinel);
215 
216  ComputeAgg<AggType> reduction_agg;
218  tbb::blocked_range<size_t>(0, num_bins_), [&](const tbb::blocked_range<size_t>& r) {
219  const size_t start_idx = r.begin();
220  const size_t end_idx = r.end();
221  for (size_t bin_idx = start_idx; bin_idx != end_idx; ++bin_idx) {
222  for (size_t input_idx = 0; input_idx < num_inputs; ++input_idx) {
223  reduction_agg(z_inputs[input_idx][bin_idx], output_z[bin_idx], agg_sentinel);
224  }
225  }
226  });
227 
228  tbb::parallel_for(tbb::blocked_range<size_t>(0, num_bins_),
229  [&](const tbb::blocked_range<size_t>& r) {
230  const size_t start_idx = r.begin();
231  const size_t end_idx = r.end();
232  for (size_t bin_idx = start_idx; bin_idx != end_idx; ++bin_idx) {
233  if (output_z[bin_idx] == agg_sentinel) {
234  output_z[bin_idx] = null_sentinel_;
235  }
236  }
237  });
238 }
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 180 of file GeoRasterTableFunctions.cpp.

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

183  {
184  auto timer = DEBUG_TIMER(__func__);
185  const int64_t input_size{input_z.size()};
186  const Z agg_sentinel = raster_agg_type_ == RasterAggType::MIN
187  ? std::numeric_limits<Z>::max()
188  : std::numeric_limits<Z>::lowest();
189  output_z.resize(num_bins_, agg_sentinel);
190  ComputeAgg<AggType> compute_agg;
191  for (int64_t sparse_idx = 0; sparse_idx != input_size; ++sparse_idx) {
192  const int64_t x_bin = get_x_bin(input_x[sparse_idx]);
193  const int64_t y_bin = get_y_bin(input_y[sparse_idx]);
194  if (x_bin < 0 || x_bin >= num_x_bins_ || y_bin < 0 || y_bin >= num_y_bins_) {
195  continue;
196  }
197  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
198  compute_agg(input_z[sparse_idx], output_z[bin_idx], inline_null_value<Z2>());
199  }
200  for (int64_t bin_idx = 0; bin_idx != num_bins_; ++bin_idx) {
201  if (output_z[bin_idx] == agg_sentinel) {
202  output_z[bin_idx] = null_sentinel_;
203  }
204  }
205 }
DEVICE int64_t size() const
Definition: heavydbTypes.h:751
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)
const RasterAggType raster_agg_type_
#define DEBUG_TIMER(name)
Definition: Logger.h:411

+ 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 
) const
inlineprivate

Definition at line 365 of file GeoRasterTableFunctions.cpp.

References x_y_bin_to_bin_index().

368  {
369  Z val = 0.0;
370  int32_t count = 0;
371  for (int64_t y_bin = y_centroid_bin - bins_radius;
372  y_bin <= y_centroid_bin + bins_radius;
373  y_bin++) {
374  for (int64_t x_bin = x_centroid_bin - bins_radius;
375  x_bin <= x_centroid_bin + bins_radius;
376  x_bin++) {
377  if (x_bin >= 0 && x_bin < num_x_bins_ && y_bin >= 0 && y_bin < num_y_bins_) {
378  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
379  const Z bin_val = z_[bin_idx];
380  if (bin_val != null_sentinel_) {
381  count++;
382  val += bin_val;
383  }
384  }
385  }
386  }
387  return (count == 0) ? null_sentinel_ : val / count;
388 }
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 >
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 
) const
inlineprivate

Definition at line 502 of file GeoRasterTableFunctions.cpp.

References MIN, and x_y_bin_to_bin_index().

506  {
507  const Z agg_sentinel = AggType == RasterAggType::MIN ? std::numeric_limits<Z>::max()
508  : std::numeric_limits<Z>::lowest();
509  Z val{agg_sentinel};
510  for (int64_t y_bin = y_centroid_bin - bins_radius;
511  y_bin <= y_centroid_bin + bins_radius;
512  y_bin++) {
513  for (int64_t x_bin = x_centroid_bin - bins_radius;
514  x_bin <= x_centroid_bin + bins_radius;
515  x_bin++) {
516  if (x_bin >= 0 && x_bin < num_x_bins_ && y_bin >= 0 && y_bin < num_y_bins_) {
517  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
518  compute_agg(z_[bin_idx], val, null_sentinel_);
519  }
520  }
521  }
522  return val == agg_sentinel ? null_sentinel_ : val;
523 }
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 >
template<RasterAggType AggType>
void GeoRaster< T, Z >::fill_bins_from_box_neighborhood ( const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls 
)
private

Definition at line 527 of file GeoRasterTableFunctions.cpp.

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

529  {
530  CHECK(AggType != RasterAggType::GAUSS_AVG); // Should have gone down Gaussian path
531  CHECK(AggType != RasterAggType::AVG); // Should be BOX_AVG for fill pass
532  CHECK(AggType != RasterAggType::INVALID);
533  std::vector<Z> new_z(num_bins_);
534  ComputeAgg<AggType> compute_agg;
535  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_y_bins_),
536  [&](const tbb::blocked_range<int64_t>& r) {
537  const int64_t end_y_bin = r.end();
538  for (int64_t y_bin = r.begin(); y_bin != end_y_bin; ++y_bin) {
539  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
540  const int64_t bin_idx =
541  x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
542  const Z z_val = z_[bin_idx];
543  if (!fill_only_nulls || z_val == null_sentinel_) {
544  if constexpr (AggType == RasterAggType::BOX_AVG) {
545  new_z[bin_idx] = fill_bin_from_avg_box_neighborhood(
546  x_bin, y_bin, neighborhood_fill_radius);
547  } else {
548  new_z[bin_idx] = fill_bin_from_box_neighborhood(
549  x_bin, y_bin, neighborhood_fill_radius, compute_agg);
550  }
551  } else {
552  new_z[bin_idx] = z_val;
553  }
554  }
555  }
556  });
557  z_.swap(new_z);
558 }
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) const
Z fill_bin_from_avg_box_neighborhood(const int64_t x_centroid_bin, const int64_t y_centroid_bin, const int64_t bins_radius) const
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define CHECK(condition)
Definition: Logger.h:291
std::vector< Z > z_

+ 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 
)
private

Definition at line 402 of file GeoRasterTableFunctions.cpp.

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

404  {
405  const double sigma = neighborhood_fill_radius * 2.0 / 6.0;
406  const auto gaussian_kernel =
407  generate_1d_gaussian_kernel(neighborhood_fill_radius, sigma);
408  std::vector<Z> only_nulls_source_z;
409  if (fill_only_nulls) {
410  // Copy z_
411  only_nulls_source_z.resize(z_.size());
412  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_bins_),
413  [&](const tbb::blocked_range<int64_t>& r) {
414  const int64_t end_bin_idx = r.end();
415  for (int64_t bin_idx = r.begin(); bin_idx < end_bin_idx;
416  ++bin_idx) {
417  only_nulls_source_z[bin_idx] = z_[bin_idx];
418  }
419  });
420  }
421  auto& source_z = fill_only_nulls ? only_nulls_source_z : z_;
422 
423  std::vector<Z> new_z(num_bins_);
425  tbb::blocked_range<int64_t>(0, num_y_bins_),
426  [&](const tbb::blocked_range<int64_t>& r) {
427  const int64_t end_y_bin = r.end();
428  for (int64_t y_start_bin = r.begin(); y_start_bin != end_y_bin; ++y_start_bin) {
429  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
430  Z val = 0.0;
431  Z sum_weights = 0.0;
432  for (int64_t y_offset = -neighborhood_fill_radius;
433  y_offset <= neighborhood_fill_radius;
434  ++y_offset) {
435  const auto y_bin = y_start_bin + y_offset;
436  if (y_bin >= 0 && y_bin < num_y_bins_) {
437  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
438  const Z bin_val = source_z[bin_idx];
439  if (bin_val != null_sentinel_) {
440  const auto gaussian_weight =
441  gaussian_kernel[y_offset + neighborhood_fill_radius];
442  val += bin_val * gaussian_weight;
443  sum_weights += gaussian_weight;
444  }
445  }
446  }
447  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_start_bin, num_x_bins_);
448  new_z[bin_idx] = sum_weights > 0.0 ? (val / sum_weights) : null_sentinel_;
449  }
450  }
451  });
452  source_z.swap(new_z);
454  tbb::blocked_range<int64_t>(0, num_x_bins_),
455  [&](const tbb::blocked_range<int64_t>& r) {
456  const int64_t end_x_bin = r.end();
457  for (int64_t x_start_bin = r.begin(); x_start_bin != end_x_bin; ++x_start_bin) {
458  for (int64_t y_bin = 0; y_bin < num_y_bins_; ++y_bin) {
459  Z val = 0.0;
460  Z sum_weights = 0.0;
461  for (int64_t x_offset = -neighborhood_fill_radius;
462  x_offset <= neighborhood_fill_radius;
463  ++x_offset) {
464  const auto x_bin = x_start_bin + x_offset;
465  if (x_bin >= 0 && x_bin < num_x_bins_) {
466  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
467  const Z bin_val = source_z[bin_idx];
468  if (bin_val != null_sentinel_) {
469  const auto gaussian_weight =
470  gaussian_kernel[x_offset + neighborhood_fill_radius];
471  val += bin_val * gaussian_weight;
472  sum_weights += gaussian_weight;
473  }
474  }
475  }
476  const int64_t bin_idx = x_y_bin_to_bin_index(x_start_bin, y_bin, num_x_bins_);
477  new_z[bin_idx] = sum_weights > 0.0 ? (val / sum_weights) : null_sentinel_;
478  }
479  }
480  });
481  if (fill_only_nulls) {
482  // Only copy convolved results in new_z back to z_ for
483  // values in z_ that are null
484  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_bins_),
485  [&](const tbb::blocked_range<int64_t>& r) {
486  const int64_t end_bin_idx = r.end();
487  for (int64_t bin_idx = r.begin(); bin_idx < end_bin_idx;
488  ++bin_idx) {
489  if (z_[bin_idx] == null_sentinel_) {
490  z_[bin_idx] = new_z[bin_idx];
491  }
492  only_nulls_source_z[bin_idx] = z_[bin_idx];
493  }
494  });
495  } else {
496  source_z.swap(new_z);
497  }
498 }
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())
std::vector< Z > z_

+ 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 561 of file GeoRasterTableFunctions.cpp.

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

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

563  {
564  auto timer = DEBUG_TIMER(__func__);
565  // Note: only GAUSSIAN_AVG supports Gaussian 2-pass technique currently,
566  // as only an AVG aggregate makes sense for Gaussian blur. However we
567  // should be able to implement 2-pass box convolution for the other aggregates
568  // when time allows for better performance with wide kernel sizes
569  // Todo (Todd): Implement 2-pass box blur
570 
571  switch (raster_fill_agg_type) {
572  case RasterAggType::COUNT: {
573  fill_bins_from_box_neighborhood<RasterAggType::COUNT>(neighborhood_fill_radius,
574  fill_only_nulls);
575  break;
576  }
577  case RasterAggType::MIN: {
578  fill_bins_from_box_neighborhood<RasterAggType::MIN>(neighborhood_fill_radius,
579  fill_only_nulls);
580  break;
581  }
582  case RasterAggType::MAX: {
583  fill_bins_from_box_neighborhood<RasterAggType::MAX>(neighborhood_fill_radius,
584  fill_only_nulls);
585  break;
586  }
587  case RasterAggType::SUM: {
588  fill_bins_from_box_neighborhood<RasterAggType::SUM>(neighborhood_fill_radius,
589  fill_only_nulls);
590  break;
591  }
592  case RasterAggType::BOX_AVG: {
593  fill_bins_from_box_neighborhood<RasterAggType::BOX_AVG>(neighborhood_fill_radius,
594  fill_only_nulls);
595  break;
596  }
598  fill_bins_from_gaussian_neighborhood(neighborhood_fill_radius, fill_only_nulls);
599  break;
600  }
601  default: {
602  UNREACHABLE();
603  }
604  }
605 }
#define UNREACHABLE()
Definition: Logger.h:337
void fill_bins_from_gaussian_neighborhood(const int64_t neighborhood_fill_radius, const bool fill_only_nulls)
#define DEBUG_TIMER(name)
Definition: Logger.h:411

+ Here is the caller graph for this function:

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 162 of file GeoRasterTableFunctions.h.

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_.

164  {
165  if (is_bin_out_of_bounds(x_bin, y_bin)) {
166  return std::make_pair(BIN_OUT_OF_BOUNDS, null_sentinel_);
167  }
168  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
169  return std::make_pair(bin_idx, z_[bin_idx]);
170  }
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 172 of file GeoRasterTableFunctions.h.

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_.

172  {
173  if (x < x_min_ || x > x_max_ || y < y_min_ || y > y_max_) {
174  return BIN_OUT_OF_BOUNDS;
175  }
177  }
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 608 of file GeoRasterTableFunctions.cpp.

References CHECK_EQ, and x_y_bin_to_bin_index().

612  {
613  const size_t num_bins_per_dim = num_bins_radius * 2 + 1;
614  CHECK_EQ(neighboring_bins.size(), num_bins_per_dim * num_bins_per_dim);
615  const int64_t end_y_bin_idx = y_bin + num_bins_radius;
616  const int64_t end_x_bin_idx = x_bin + num_bins_radius;
617  size_t output_bin = 0;
618  for (int64_t y_bin_idx = y_bin - num_bins_radius; y_bin_idx <= end_y_bin_idx;
619  ++y_bin_idx) {
620  for (int64_t x_bin_idx = x_bin - num_bins_radius; x_bin_idx <= end_x_bin_idx;
621  ++x_bin_idx) {
622  if (x_bin_idx < 0 || x_bin_idx >= num_x_bins_ || y_bin_idx < 0 ||
623  y_bin_idx >= num_y_bins_) {
624  return false;
625  }
626  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin_idx, y_bin_idx, num_x_bins_);
627  neighboring_bins[output_bin++] = z_[bin_idx];
628  if (z_[bin_idx] == null_sentinel_) {
629  return false;
630  }
631  }
632  }
633  return true; // not_null
634 }
#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 148 of file GeoRasterTableFunctions.h.

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().

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

+ 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 179 of file GeoRasterTableFunctions.h.

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_.

179  {
180  const auto [x_bin, y_bin] = bin_to_x_y_bin_indexes(bin_idx, num_x_bins_);
181  const T x = x_min_ + (x_bin + 0.5) * x_scale_bin_to_input_;
182  const T y = y_min_ + (y_bin + 0.5) * y_scale_bin_to_input_;
183  return std::make_pair(x, y);
184  }
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 152 of file GeoRasterTableFunctions.h.

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().

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

+ 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 158 of file GeoRasterTableFunctions.h.

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().

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

+ 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 156 of file GeoRasterTableFunctions.h.

References GeoRaster< T, Z >::null_sentinel_.

156 { 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 114 of file GeoRasterTableFunctions.cpp.

References x_y_bin_to_bin_index().

116  {
117  if (is_bin_out_of_bounds(source_x_bin, source_y_bin)) {
118  return null_sentinel_;
119  }
120  const Z terrain_z = z_[x_y_bin_to_bin_index(source_x_bin, source_y_bin, num_x_bins_)];
121  if (terrain_z == null_sentinel_) {
122  return terrain_z;
123  }
124  return terrain_z + source_z_offset;
125 }
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 >
int64_t GeoRaster< T, Z >::outputDenseColumns ( TableFunctionManager mgr,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Z > &  output_z 
) const

Definition at line 734 of file GeoRasterTableFunctions.cpp.

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_rasterize__cpu_template(), and tf_geo_rasterize_slope__cpu_template().

737  {
738  auto timer = DEBUG_TIMER(__func__);
741  tbb::blocked_range<int64_t>(0, num_y_bins_),
742  [&](const tbb::blocked_range<int64_t>& r) {
743  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
744  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
745  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
746  output_x[bin_idx] = x_min_ + (x_bin + 0.5) * x_scale_bin_to_input_;
747  output_y[bin_idx] = y_min_ + (y_bin + 0.5) * y_scale_bin_to_input_;
748  const Z z_val = z_[bin_idx];
749  if (z_val == null_sentinel_) {
750  output_z.setNull(bin_idx);
751  } else {
752  output_z[bin_idx] = z_[bin_idx];
753  }
754  }
755  }
756  });
757  return num_bins_;
758 }
void set_output_row_size(int64_t num_rows)
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)
Definition: heavydbTypes.h:755
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:411
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< Z > &  output_z,
const int64_t  neighborhood_null_fill_radius 
) const

Definition at line 698 of file GeoRasterTableFunctions.cpp.

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

703  {
704  auto timer = DEBUG_TIMER(__func__);
707  tbb::blocked_range<int64_t>(0, num_y_bins_),
708  [&](const tbb::blocked_range<int64_t>& r) {
709  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
710  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
711  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
712  output_x[bin_idx] = x_min_ + (x_bin + 0.5) * x_scale_bin_to_input_;
713  output_y[bin_idx] = y_min_ + (y_bin + 0.5) * y_scale_bin_to_input_;
714  const Z z_val = z_[bin_idx];
715  if (z_val == null_sentinel_) {
716  output_z.setNull(bin_idx);
717  if (neighborhood_null_fill_radius) {
718  const Z avg_neighbor_value = fill_bin_from_avg_box_neighborhood(
719  x_bin, y_bin, neighborhood_null_fill_radius);
720  if (avg_neighbor_value != null_sentinel_) {
721  output_z[bin_idx] = avg_neighbor_value;
722  }
723  }
724  } else {
725  output_z[bin_idx] = z_[bin_idx];
726  }
727  }
728  }
729  });
730  return num_bins_;
731 }
void set_output_row_size(int64_t num_rows)
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)
Definition: heavydbTypes.h:755
Z fill_bin_from_avg_box_neighborhood(const int64_t x_centroid_bin, const int64_t y_centroid_bin, const int64_t bins_radius) const
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:411
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 761 of file GeoRasterTableFunctions.cpp.

References TableFunctionManager::set_metadata().

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

761  {
762  mgr.set_metadata("geo_raster_num_x_bins", num_x_bins_);
763  mgr.set_metadata("geo_raster_num_y_bins", num_y_bins_);
764  mgr.set_metadata("geo_raster_x_min", static_cast<double>(x_min_));
765  mgr.set_metadata("geo_raster_y_min", static_cast<double>(y_min_));
766  mgr.set_metadata("geo_raster_x_scale_input_to_bin",
767  static_cast<double>(x_scale_input_to_bin_));
768  mgr.set_metadata("geo_raster_y_scale_input_to_bin",
769  static_cast<double>(y_scale_input_to_bin_));
770 }
void set_metadata(const std::string &key, const T &value)

+ 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 103 of file GeoRasterTableFunctions.h.

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 107 of file GeoRasterTableFunctions.h.

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

Definition at line 104 of file GeoRasterTableFunctions.h.

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

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 118 of file GeoRasterTableFunctions.h.

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>
const RasterAggType GeoRaster< T, Z >::raster_agg_type_

Definition at line 102 of file GeoRasterTableFunctions.h.

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 114 of file GeoRasterTableFunctions.h.

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 112 of file GeoRasterTableFunctions.h.

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 119 of file GeoRasterTableFunctions.h.

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 115 of file GeoRasterTableFunctions.h.

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 113 of file GeoRasterTableFunctions.h.

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 120 of file GeoRasterTableFunctions.h.

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

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

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