OmniSciDB  cde582ebc3
 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 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 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 source_x_bin, const int64_t source_y_bin) 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
 
fill_bin_from_avg_neighbors (const int64_t x_centroid_bin, const int64_t y_centroid_bin, const int64_t bins_radius) 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)
 
template<typename T2 , typename Z2 >
void computeParallel (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)
 
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
 

Public Attributes

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

Detailed Description

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

Definition at line 25 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 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 >::computeParallel(), 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_.

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

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

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

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

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

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

149  {
150  x_min_ = std::floor(x_min_ / bin_dim_meters_) * bin_dim_meters_;
151  x_max_ = std::floor(x_max_ / bin_dim_meters_) * bin_dim_meters_ +
152  bin_dim_meters_; // Snap to end of bin
153  y_min_ = std::floor(y_min_ / bin_dim_meters_) * bin_dim_meters_;
154  y_max_ = std::floor(y_max_ / bin_dim_meters_) * bin_dim_meters_ +
155  bin_dim_meters_; // Snap to end of bin
156 }

+ Here is the caller graph for this function:

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

Definition at line 167 of file GeoRasterTableFunctions.cpp.

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

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

167  {
168  x_range_ = x_max_ - x_min_;
169  y_range_ = y_max_ - y_min_;
170  if (geographic_coords_) {
171  const T x_centroid = (x_min_ + x_max_) * 0.5;
172  const T y_centroid = (y_min_ + y_max_) * 0.5;
174  distance_in_meters(x_min_, y_centroid, x_max_, y_centroid) / x_range_;
175 
177  distance_in_meters(x_centroid, y_min_, x_centroid, y_max_) / y_range_;
178 
181 
186 
187  } else {
190 
195  }
197 }
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 378 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().

381  {
382  auto timer = DEBUG_TIMER(__func__);
383  CHECK_EQ(slope.size(), num_bins_);
385  tbb::blocked_range<int64_t>(0, num_y_bins_),
386  [&](const tbb::blocked_range<int64_t>& r) {
387  std::vector<Z> neighboring_z_vals(9); // 3X3 calc
388  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
389  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
390  const bool not_null =
391  get_nxn_neighbors_if_not_null(x_bin, y_bin, 1, neighboring_z_vals);
392  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
393  if (!not_null) {
394  slope.setNull(bin_idx);
395  aspect.setNull(bin_idx);
396  } else {
397  const auto slope_and_aspect = calculate_slope_and_aspect_of_cell(
398  neighboring_z_vals, compute_slope_in_degrees);
399  slope[bin_idx] = slope_and_aspect.first;
400  if (slope_and_aspect.second == null_sentinel_) {
401  aspect.setNull(bin_idx);
402  } else {
403  aspect[bin_idx] = slope_and_aspect.second;
404  }
405  }
406  }
407  }
408  });
409 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
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:469
DEVICE void setNull(int64_t index)
Definition: heavydbTypes.h:472
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:371
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:

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

References math_consts::radians_to_degrees.

353  {
354  const Z dz_dx =
355  ((neighboring_cells[8] + 2 * neighboring_cells[5] + neighboring_cells[2]) -
356  (neighboring_cells[6] + 2 * neighboring_cells[3] + neighboring_cells[0])) /
357  (8 * bin_dim_meters_);
358  const Z dz_dy =
359  ((neighboring_cells[6] + 2 * neighboring_cells[7] + neighboring_cells[8]) -
360  (neighboring_cells[0] + 2 * neighboring_cells[1] + neighboring_cells[2])) /
361  (8 * bin_dim_meters_);
362  const Z slope = sqrt(dz_dx * dz_dx + dz_dy * dz_dy);
363  std::pair<Z, Z> slope_and_aspect;
364  slope_and_aspect.first =
365  compute_slope_in_degrees ? atan(slope) * math_consts::radians_to_degrees : slope;
366  if (slope < 0.0001) {
367  slope_and_aspect.second = null_sentinel_;
368  } else {
369  const Z aspect_degrees =
370  math_consts::radians_to_degrees * atan2(dz_dx, dz_dy); // -180.0 to 180.0
371  slope_and_aspect.second = aspect_degrees + 180.0;
372  // aspect_degrees < 0.0 ? 180.0 + aspect_degrees : aspect_degrees;
373  }
374  return slope_and_aspect;
375 }
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 
)

Definition at line 201 of file GeoRasterTableFunctions.cpp.

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

203  {
204  auto timer = DEBUG_TIMER(__func__);
205  const int64_t input_size{input_z.size()};
206  z_.resize(num_bins_, null_sentinel_);
207  for (int64_t sparse_idx = 0; sparse_idx != input_size; ++sparse_idx) {
208  const int64_t x_bin = get_x_bin(input_x[sparse_idx]);
209  const int64_t y_bin = get_y_bin(input_y[sparse_idx]);
210  if (x_bin < 0 || x_bin >= num_x_bins_ || y_bin < 0 || y_bin >= num_y_bins_) {
211  continue;
212  }
213  // Take the max height for this version, but may want to allow different metrics
214  // like average as well
215  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
216  if (!(input_z.isNull(sparse_idx)) && input_z[sparse_idx] > z_[bin_idx]) {
217  z_[bin_idx] = input_z[sparse_idx];
218  }
219  }
220 }
DEVICE int64_t size() const
Definition: heavydbTypes.h:469
T get_y_bin(const T input) const
T get_x_bin(const T input) const
DEVICE bool isNull(int64_t index) const
Definition: heavydbTypes.h:471
#define DEBUG_TIMER(name)
Definition: Logger.h:371
std::vector< Z > z_
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<typename T2 , typename Z2 >
void GeoRaster< T, Z >::computeParallel ( 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 224 of file GeoRasterTableFunctions.cpp.

References DEBUG_TIMER, Column< T >::isNull(), max_temp_output_entries, threading_serial::parallel_for(), Column< T >::size(), heavydb.dtypes::T, and x_y_bin_to_bin_index().

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

227  {
228  const size_t input_size = input_z.size();
229  const size_t max_thread_count = std::thread::hardware_concurrency();
230  const size_t num_threads_by_input_elements =
231  std::min(max_thread_count,
232  ((input_size + max_inputs_per_thread - 1) / max_inputs_per_thread));
233  const size_t num_threads_by_output_size =
234  std::min(max_thread_count, ((max_temp_output_entries + num_bins_ - 1) / num_bins_));
235  const size_t num_threads =
236  std::min(num_threads_by_input_elements, num_threads_by_output_size);
237  if (num_threads <= 1) {
238  compute(input_x, input_y, input_z);
239  return;
240  }
241  auto timer = DEBUG_TIMER(__func__);
242 
243  std::vector<std::vector<Z>> per_thread_z_outputs(num_threads);
244 
245  tbb::parallel_for(tbb::blocked_range<size_t>(0, num_threads),
246  [&](const tbb::blocked_range<size_t>& r) {
247  for (size_t t = r.begin(); t != r.end(); ++t) {
248  per_thread_z_outputs[t].resize(num_bins_, null_sentinel_);
249  }
250  });
251 
252  tbb::task_arena limited_arena(num_threads);
253  limited_arena.execute([&] {
255  tbb::blocked_range<int64_t>(0, input_size),
256  [&](const tbb::blocked_range<int64_t>& r) {
257  const int64_t start_idx = r.begin();
258  const int64_t end_idx = r.end();
259  size_t thread_idx = tbb::this_task_arena::current_thread_index();
260  std::vector<Z>& this_thread_z_output = per_thread_z_outputs[thread_idx];
261 
262  for (int64_t sparse_idx = start_idx; sparse_idx != end_idx; ++sparse_idx) {
263  const int64_t x_bin = get_x_bin(input_x[sparse_idx]);
264  const int64_t y_bin = get_y_bin(input_y[sparse_idx]);
265  if (x_bin < 0 || x_bin >= num_x_bins_ || y_bin < 0 || y_bin >= num_y_bins_) {
266  continue;
267  }
268  // Take the max height for this version, but may want to allow different
269  // metrics like average as well
270  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
271  if (!(input_z.isNull(sparse_idx)) &&
272  input_z[sparse_idx] > this_thread_z_output[bin_idx]) {
273  this_thread_z_output[bin_idx] = input_z[sparse_idx];
274  }
275  }
276  });
277  });
278 
279  z_.resize(num_bins_, null_sentinel_);
280 
282  tbb::blocked_range<size_t>(0, num_bins_), [&](const tbb::blocked_range<size_t>& r) {
283  const size_t start_idx = r.begin();
284  const size_t end_idx = r.end();
285  for (size_t bin_idx = start_idx; bin_idx != end_idx; ++bin_idx) {
286  for (size_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
287  const T thread_bin_z_output = per_thread_z_outputs[thread_idx][bin_idx];
288  if (thread_bin_z_output != null_sentinel_ &&
289  thread_bin_z_output > z_[bin_idx]) {
290  z_[bin_idx] = thread_bin_z_output;
291  }
292  }
293  }
294  });
295 }
DEVICE int64_t size() const
Definition: heavydbTypes.h:469
void compute(const Column< T2 > &input_x, const Column< T2 > &input_y, const Column< Z2 > &input_z)
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
DEVICE bool isNull(int64_t index) const
Definition: heavydbTypes.h:471
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:371
std::vector< Z > z_
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:

+ Here is the caller graph for this function:

template<typename T , typename Z >
Z GeoRaster< T, Z >::fill_bin_from_avg_neighbors ( const int64_t  x_centroid_bin,
const int64_t  y_centroid_bin,
const int64_t  bins_radius 
) const
inline

Definition at line 124 of file GeoRasterTableFunctions.cpp.

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

126  {
127  T val = 0.0;
128  int32_t count = 0;
129  for (int64_t y_bin = y_centroid_bin - bins_radius;
130  y_bin <= y_centroid_bin + bins_radius;
131  y_bin++) {
132  for (int64_t x_bin = x_centroid_bin - bins_radius;
133  x_bin <= x_centroid_bin + bins_radius;
134  x_bin++) {
135  if (x_bin >= 0 && x_bin < num_x_bins_ && y_bin >= 0 && y_bin < num_y_bins_) {
136  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
137  const Z bin_val = z_[bin_idx];
138  if (bin_val != null_sentinel_) {
139  count++;
140  val += bin_val;
141  }
142  }
143  }
144  }
145  return (count == 0) ? null_sentinel_ : val / count;
146 }
std::vector< Z > z_
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 >
void GeoRaster< T, Z >::fill_bins_from_neighbors ( const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls 
)

Definition at line 298 of file GeoRasterTableFunctions.cpp.

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

Referenced by tf_geo_rasterize__cpu_template(), and tf_geo_rasterize_slope__cpu_template().

299  {
300  auto timer = DEBUG_TIMER(__func__);
301  std::vector<Z> new_z(num_bins_);
302  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_y_bins_),
303  [&](const tbb::blocked_range<int64_t>& r) {
304  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
305  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
306  const int64_t bin_idx =
307  x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
308  const Z z_val = z_[bin_idx];
309  if (!fill_only_nulls || z_val == null_sentinel_) {
310  new_z[bin_idx] = fill_bin_from_avg_neighbors(
311  x_bin, y_bin, neighborhood_fill_radius);
312  } else {
313  new_z[bin_idx] = z_val;
314  }
315  }
316  }
317  });
318  z_.swap(new_z);
319 }
Z fill_bin_from_avg_neighbors(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:371
std::vector< Z > z_
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:

+ Here is the caller 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 322 of file GeoRasterTableFunctions.cpp.

References CHECK_EQ, and x_y_bin_to_bin_index().

326  {
327  const size_t num_bins_per_dim = num_bins_radius * 2 + 1;
328  CHECK_EQ(neighboring_bins.size(), num_bins_per_dim * num_bins_per_dim);
329  const int64_t end_y_bin_idx = y_bin + num_bins_radius;
330  const int64_t end_x_bin_idx = x_bin + num_bins_radius;
331  size_t output_bin = 0;
332  for (int64_t y_bin_idx = y_bin - num_bins_radius; y_bin_idx <= end_y_bin_idx;
333  ++y_bin_idx) {
334  for (int64_t x_bin_idx = x_bin - num_bins_radius; x_bin_idx <= end_x_bin_idx;
335  ++x_bin_idx) {
336  if (x_bin_idx < 0 || x_bin_idx >= num_x_bins_ || y_bin_idx < 0 ||
337  y_bin_idx >= num_y_bins_) {
338  return false;
339  }
340  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin_idx, y_bin_idx, num_x_bins_);
341  neighboring_bins[output_bin++] = z_[bin_idx];
342  if (z_[bin_idx] == null_sentinel_) {
343  return false;
344  }
345  }
346  }
347  return true; // not_null
348 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::vector< Z > z_
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>
T GeoRaster< T, Z >::get_x_bin ( const T  input) const
inline
template<typename T, typename Z>
T GeoRaster< T, Z >::get_y_bin ( const T  input) const
inline
template<typename T, typename Z>
bool GeoRaster< T, Z >::is_bin_out_of_bounds ( const int64_t  source_x_bin,
const int64_t  source_y_bin 
) const
inline

Definition at line 76 of file GeoRasterTableFunctions.h.

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

77  {
78  return (source_x_bin < 0 || source_x_bin >= num_x_bins_ || source_y_bin < 0 ||
79  source_y_bin >= num_y_bins_);
80  }
template<typename T, typename Z>
bool GeoRaster< T, Z >::is_null ( const Z  value) const
inline

Definition at line 74 of file GeoRasterTableFunctions.h.

References GeoRaster< T, Z >::null_sentinel_.

74 { 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 110 of file GeoRasterTableFunctions.cpp.

References x_y_bin_to_bin_index().

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

Definition at line 448 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 tf_geo_rasterize__cpu_template(), and tf_geo_rasterize_slope__cpu_template().

451  {
452  auto timer = DEBUG_TIMER(__func__);
455  tbb::blocked_range<int64_t>(0, num_y_bins_),
456  [&](const tbb::blocked_range<int64_t>& r) {
457  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
458  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
459  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
460  output_x[bin_idx] = x_min_ + (x_bin + 0.5) * x_scale_bin_to_input_;
461  output_y[bin_idx] = y_min_ + (y_bin + 0.5) * y_scale_bin_to_input_;
462  const Z z_val = z_[bin_idx];
463  if (z_val == null_sentinel_) {
464  output_z.setNull(bin_idx);
465  } else {
466  output_z[bin_idx] = z_[bin_idx];
467  }
468  }
469  }
470  });
471  return num_bins_;
472 }
void set_output_row_size(int64_t num_rows)
Definition: heavydbTypes.h:679
DEVICE void setNull(int64_t index)
Definition: heavydbTypes.h:472
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:371
std::vector< Z > z_
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:

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

417  {
418  auto timer = DEBUG_TIMER(__func__);
421  tbb::blocked_range<int64_t>(0, num_y_bins_),
422  [&](const tbb::blocked_range<int64_t>& r) {
423  for (int64_t y_bin = r.begin(); y_bin != r.end(); ++y_bin) {
424  for (int64_t x_bin = 0; x_bin < num_x_bins_; ++x_bin) {
425  const int64_t bin_idx = x_y_bin_to_bin_index(x_bin, y_bin, num_x_bins_);
426  output_x[bin_idx] = x_min_ + (x_bin + 0.5) * x_scale_bin_to_input_;
427  output_y[bin_idx] = y_min_ + (y_bin + 0.5) * y_scale_bin_to_input_;
428  const Z z_val = z_[bin_idx];
429  if (z_val == null_sentinel_) {
430  output_z.setNull(bin_idx);
431  if (neighborhood_null_fill_radius) {
432  const Z avg_neighbor_value = fill_bin_from_avg_neighbors(
433  x_bin, y_bin, neighborhood_null_fill_radius);
434  if (avg_neighbor_value != null_sentinel_) {
435  output_z[bin_idx] = avg_neighbor_value;
436  }
437  }
438  } else {
439  output_z[bin_idx] = z_[bin_idx];
440  }
441  }
442  }
443  });
444  return num_bins_;
445 }
void set_output_row_size(int64_t num_rows)
Definition: heavydbTypes.h:679
Z fill_bin_from_avg_neighbors(const int64_t x_centroid_bin, const int64_t y_centroid_bin, const int64_t bins_radius) const
DEVICE void setNull(int64_t index)
Definition: heavydbTypes.h:472
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
#define DEBUG_TIMER(name)
Definition: Logger.h:371
std::vector< Z > z_
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:

Member Data Documentation

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

Definition at line 26 of file GeoRasterTableFunctions.h.

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

Definition at line 27 of file GeoRasterTableFunctions.h.

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

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

Definition at line 28 of file GeoRasterTableFunctions.h.

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

template<typename T, typename Z>
int64_t GeoRaster< T, Z >::num_bins_

Definition at line 40 of file GeoRasterTableFunctions.h.

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

template<typename T, typename Z>
int64_t GeoRaster< T, Z >::num_x_bins_
template<typename T, typename Z>
int64_t GeoRaster< T, Z >::num_y_bins_
template<typename T, typename Z>
T GeoRaster< T, Z >::x_max_

Definition at line 31 of file GeoRasterTableFunctions.h.

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

template<typename T, typename Z>
T GeoRaster< T, Z >::x_meters_per_degree_

Definition at line 36 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_

Definition at line 34 of file GeoRasterTableFunctions.h.

template<typename T, typename Z>
T GeoRaster< T, Z >::x_scale_bin_to_input_

Definition at line 43 of file GeoRasterTableFunctions.h.

template<typename T, typename Z>
T GeoRaster< T, Z >::x_scale_input_to_bin_

Definition at line 41 of file GeoRasterTableFunctions.h.

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

template<typename T, typename Z>
T GeoRaster< T, Z >::y_max_

Definition at line 33 of file GeoRasterTableFunctions.h.

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

template<typename T, typename Z>
T GeoRaster< T, Z >::y_meters_per_degree_

Definition at line 37 of file GeoRasterTableFunctions.h.

template<typename T, typename Z>
T GeoRaster< T, Z >::y_min_
template<typename T, typename Z>
T GeoRaster< T, Z >::y_range_

Definition at line 35 of file GeoRasterTableFunctions.h.

template<typename T, typename Z>
T GeoRaster< T, Z >::y_scale_bin_to_input_

Definition at line 44 of file GeoRasterTableFunctions.h.

template<typename T, typename Z>
T GeoRaster< T, Z >::y_scale_input_to_bin_

Definition at line 42 of file GeoRasterTableFunctions.h.

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

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

Definition at line 29 of file GeoRasterTableFunctions.h.


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