OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeoRasterTableFunctions.hpp File Reference
#include <cmath>
#include <vector>
#include <tbb/parallel_for.h>
#include <tbb/task_arena.h>
#include "QueryEngine/heavydbTypes.h"
#include "Shared/StringTransform.h"
#include "Shared/TableFunctionsCommon.hpp"
#include "Shared/math_consts.h"
+ Include dependency graph for GeoRasterTableFunctions.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ComputeAgg< AggType >
 
struct  ComputeAgg< RasterAggType::COUNT >
 
struct  ComputeAgg< RasterAggType::MAX >
 
struct  ComputeAgg< RasterAggType::MIN >
 
struct  ComputeAgg< RasterAggType::SUM >
 
struct  ComputeAgg< RasterAggType::BOX_AVG >
 
struct  GeoRaster< T, Z >
 

Enumerations

enum  RasterAggType {
  RasterAggType::COUNT, RasterAggType::MIN, RasterAggType::MAX, RasterAggType::SUM,
  RasterAggType::AVG, RasterAggType::GAUSS_AVG, RasterAggType::BOX_AVG, RasterAggType::INVALID
}
 

Functions

RasterAggType get_raster_agg_type (const std::string &agg_type_str, const bool is_fill_agg)
 
std::vector< double > generate_1d_gaussian_kernel (const int64_t fill_radius, double sigma)
 
template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t geo_rasterize_impl (TableFunctionManager &mgr, const Column< T > &input_x, const Column< T > &input_y, const Column< Z > &input_z, const RasterAggType raster_agg_type, const RasterAggType raster_fill_agg_type, const T bin_dim_meters, const bool geographic_coords, const int64_t neighborhood_fill_radius, const bool fill_only_nulls, Column< T > &output_x, Column< T > &output_y, Column< Z > &output_z)
 
template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_rasterize__cpu_template (TableFunctionManager &mgr, const Column< T > &input_x, const Column< T > &input_y, const Column< Z > &input_z, const TextEncodingNone &agg_type_str, const T bin_dim_meters, const bool geographic_coords, const int64_t neighborhood_fill_radius, const bool fill_only_nulls, Column< T > &output_x, Column< T > &output_y, Column< Z > &output_z)
 
template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_rasterize__cpu_template (TableFunctionManager &mgr, const Column< T > &input_x, const Column< T > &input_y, const Column< Z > &input_z, const TextEncodingNone &agg_type_str, const TextEncodingNone &fill_agg_type_str, const T bin_dim_meters, const bool geographic_coords, const int64_t neighborhood_fill_radius, const bool fill_only_nulls, Column< T > &output_x, Column< T > &output_y, Column< Z > &output_z)
 
template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_rasterize__cpu_template (TableFunctionManager &mgr, const Column< T > &input_x, const Column< T > &input_y, const Column< Z > &input_z, const TextEncodingNone &agg_type_str, const TextEncodingNone &fill_agg_type_str, const T bin_dim_meters, const bool geographic_coords, const int64_t neighborhood_fill_radius, const bool fill_only_nulls, const T x_min, const T x_max, const T y_min, const T y_max, Column< T > &output_x, Column< T > &output_y, Column< Z > &output_z)
 
template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_multi_rasterize__cpu_template (TableFunctionManager &mgr, const Column< T > &input_x, const Column< T > &input_y, const ColumnList< Z > &input_z_cols, const TextEncodingNone &agg_types_str, const TextEncodingNone &fill_agg_types_str, const T bin_dim_meters, const bool geographic_coords, const int64_t neighborhood_fill_radius, const bool fill_only_nulls, Column< T > &output_x, Column< T > &output_y, Column< Array< Z >> &output_z)
 
template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_rasterize_slope__cpu_template (TableFunctionManager &mgr, const Column< T > &input_x, const Column< T > &input_y, const Column< Z > &input_z, const TextEncodingNone &agg_type_str, const T bin_dim_meters, const bool geographic_coords, const int64_t neighborhood_fill_radius, const bool fill_only_nulls, const bool compute_slope_in_degrees, Column< T > &output_x, Column< T > &output_y, Column< Z > &output_z, Column< Z > &output_slope, Column< Z > &output_aspect)
 

Variables

const size_t max_inputs_per_thread = 1000000L
 
const size_t max_temp_output_entries = 200000000L
 

Enumeration Type Documentation

Function Documentation

std::vector<double> generate_1d_gaussian_kernel ( const int64_t  fill_radius,
double  sigma 
)

Definition at line 46 of file GeoRasterTableFunctions.cpp.

References M_PI.

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

46  {
47  const int64_t kernel_size = fill_radius * 2 + 1;
48  std::vector<double> gaussian_kernel(kernel_size);
49  const double expr = 1.0 / (sigma * sqrt(2.0 * M_PI));
50  for (int64_t kernel_idx = -fill_radius; kernel_idx <= fill_radius; ++kernel_idx) {
51  gaussian_kernel[kernel_idx + fill_radius] =
52  expr * exp((kernel_idx * kernel_idx) / (-2.0 * (sigma * sigma)));
53  }
54  return gaussian_kernel;
55 }
#define M_PI
Definition: constants.h:25

+ Here is the caller graph for this function:

template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t geo_rasterize_impl ( TableFunctionManager mgr,
const Column< T > &  input_x,
const Column< T > &  input_y,
const Column< Z > &  input_z,
const RasterAggType  raster_agg_type,
const RasterAggType  raster_fill_agg_type,
const T  bin_dim_meters,
const bool  geographic_coords,
const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Z > &  output_z 
)

Definition at line 1209 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::fill_bins_from_neighbors(), GeoRaster< T, Z >::outputDenseColumns(), and GeoRaster< T, Z >::setMetadata().

Referenced by tf_geo_rasterize__cpu_template().

1221  {
1222  GeoRaster<T, Z> geo_raster(input_x,
1223  input_y,
1224  input_z,
1225  raster_agg_type,
1226  bin_dim_meters,
1227  geographic_coords,
1228  true);
1229 
1230  geo_raster.setMetadata(mgr);
1231 
1232  if (neighborhood_fill_radius > 0) {
1233  geo_raster.fill_bins_from_neighbors(
1234  neighborhood_fill_radius, fill_only_nulls, raster_fill_agg_type);
1235  }
1236 
1237  return geo_raster.outputDenseColumns(mgr, output_x, output_y, output_z);
1238 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RasterAggType get_raster_agg_type ( const std::string &  agg_type_str,
const bool  is_fill_agg 
)

Definition at line 21 of file GeoRasterTableFunctions.cpp.

References AVG, BOX_AVG, COUNT, GAUSS_AVG, INVALID, MAX, MIN, SUM, and to_upper().

Referenced by tf_geo_multi_rasterize__cpu_template(), tf_geo_rasterize__cpu_template(), tf_geo_rasterize_slope__cpu_template(), and GDALTableFunctions::tf_raster_contour_rasterize_impl().

22  {
23  const auto upper_agg_type_str = to_upper(agg_type_str);
24  const static std::map<std::string, RasterAggType> agg_type_map = {
25  {"COUNT", RasterAggType::COUNT},
26  {"MIN", RasterAggType::MIN},
27  {"MAX", RasterAggType::MAX},
28  {"SUM", RasterAggType::SUM},
29  {"AVG", RasterAggType::AVG},
30  {"GAUSS_AVG", RasterAggType::GAUSS_AVG},
31  {"BOX_AVG", RasterAggType::BOX_AVG}};
32  const auto itr = agg_type_map.find(upper_agg_type_str);
33  if (itr == agg_type_map.end()) {
35  }
36  if (is_fill_agg && itr->second == RasterAggType::AVG) {
38  } else if (!is_fill_agg && (itr->second == RasterAggType::BOX_AVG ||
39  itr->second == RasterAggType::GAUSS_AVG)) {
40  // GAUSS_AVG and BOX_AVG are fill-only aggregates
42  }
43  return itr->second;
44 }
std::string to_upper(const std::string &str)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_multi_rasterize__cpu_template ( TableFunctionManager mgr,
const Column< T > &  input_x,
const Column< T > &  input_y,
const ColumnList< Z > &  input_z_cols,
const TextEncodingNone agg_types_str,
const TextEncodingNone fill_agg_types_str,
const T  bin_dim_meters,
const bool  geographic_coords,
const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Array< Z >> &  output_z 
)

Definition at line 1429 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::fill_bins_from_neighbors(), get_raster_agg_type(), TextEncodingNone::getString(), INVALID, ColumnList< T >::numCols(), GeoRaster< T, Z >::outputDenseColumns(), GeoRaster< T, Z >::setMetadata(), split(), and GeoRaster< T, Z >::z_cols_.

1441  {
1442  const int64_t num_z_cols = input_z_cols.numCols();
1443  const auto agg_types_strs = split(agg_types_str.getString(), "|");
1444  const auto fill_agg_types_strs = split(fill_agg_types_str.getString(), "|");
1445  if (num_z_cols != static_cast<int64_t>(agg_types_strs.size()) ||
1446  num_z_cols != static_cast<int64_t>(fill_agg_types_strs.size())) {
1447  const std::string error_msg =
1448  "Mismatch between number of cols and number of agg or fill agg types.";
1449  return mgr.ERROR_MESSAGE(error_msg);
1450  }
1451 
1452  auto get_agg_types = [](const std::vector<std::string>& agg_types_strs,
1453  const bool is_fill_agg) {
1454  std::vector<RasterAggType> agg_types;
1455  for (const auto& agg_type_str : agg_types_strs) {
1456  agg_types.emplace_back(get_raster_agg_type(agg_type_str, is_fill_agg));
1457  if (agg_types.back() == RasterAggType::INVALID) {
1458  throw std::runtime_error("Invalid agg type");
1459  }
1460  }
1461  return agg_types;
1462  };
1463 
1464  std::vector<RasterAggType> raster_agg_types;
1465  std::vector<RasterAggType> raster_fill_agg_types;
1466  try {
1467  raster_agg_types = get_agg_types(agg_types_strs, false);
1468  raster_fill_agg_types = get_agg_types(fill_agg_types_strs, true);
1469  } catch (std::exception& e) {
1470  return mgr.ERROR_MESSAGE(e.what());
1471  }
1472 
1473  GeoRaster<T, Z> geo_raster(input_x,
1474  input_y,
1475  input_z_cols,
1476  raster_agg_types,
1477  bin_dim_meters,
1478  geographic_coords,
1479  true);
1480  geo_raster.setMetadata(mgr);
1481 
1482  if (neighborhood_fill_radius > 0) {
1483  for (int64_t z_col_idx = 0; z_col_idx < num_z_cols; ++z_col_idx) {
1484  geo_raster.fill_bins_from_neighbors(neighborhood_fill_radius,
1485  fill_only_nulls,
1486  raster_fill_agg_types[z_col_idx],
1487  geo_raster.z_cols_[z_col_idx]);
1488  }
1489  }
1490  return geo_raster.outputDenseColumns(mgr, output_x, output_y, output_z);
1491 }
std::string getString() const
Definition: heavydbTypes.h:641
DEVICE int64_t numCols() const
RasterAggType get_raster_agg_type(const std::string &agg_type_str, const bool is_fill_agg)
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings

+ Here is the call graph for this function:

template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_rasterize__cpu_template ( TableFunctionManager mgr,
const Column< T > &  input_x,
const Column< T > &  input_y,
const Column< Z > &  input_z,
const TextEncodingNone agg_type_str,
const T  bin_dim_meters,
const bool  geographic_coords,
const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Z > &  output_z 
)

Definition at line 1255 of file GeoRasterTableFunctions.hpp.

References GAUSS_AVG, geo_rasterize_impl(), get_raster_agg_type(), TextEncodingNone::getString(), and INVALID.

1266  {
1267  const auto raster_agg_type = get_raster_agg_type(agg_type_str, false);
1268  if (raster_agg_type == RasterAggType::INVALID) {
1269  const std::string error_msg =
1270  "Invalid Raster Aggregate Type: " + agg_type_str.getString();
1271  return mgr.ERROR_MESSAGE(error_msg);
1272  }
1273  return geo_rasterize_impl(mgr,
1274  input_x,
1275  input_y,
1276  input_z,
1277  raster_agg_type,
1279  bin_dim_meters,
1280  geographic_coords,
1281  neighborhood_fill_radius,
1282  fill_only_nulls,
1283  output_x,
1284  output_y,
1285  output_z);
1286 }
TEMPLATE_NOINLINE int32_t geo_rasterize_impl(TableFunctionManager &mgr, const Column< T > &input_x, const Column< T > &input_y, const Column< Z > &input_z, const RasterAggType raster_agg_type, const RasterAggType raster_fill_agg_type, const T bin_dim_meters, const bool geographic_coords, const int64_t neighborhood_fill_radius, const bool fill_only_nulls, Column< T > &output_x, Column< T > &output_y, Column< Z > &output_z)
std::string getString() const
Definition: heavydbTypes.h:641
RasterAggType get_raster_agg_type(const std::string &agg_type_str, const bool is_fill_agg)

+ Here is the call graph for this function:

template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_rasterize__cpu_template ( TableFunctionManager mgr,
const Column< T > &  input_x,
const Column< T > &  input_y,
const Column< Z > &  input_z,
const TextEncodingNone agg_type_str,
const TextEncodingNone fill_agg_type_str,
const T  bin_dim_meters,
const bool  geographic_coords,
const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Z > &  output_z 
)

Definition at line 1304 of file GeoRasterTableFunctions.hpp.

References geo_rasterize_impl(), get_raster_agg_type(), TextEncodingNone::getString(), and INVALID.

1316  {
1317  const auto raster_agg_type = get_raster_agg_type(agg_type_str, false);
1318  if (raster_agg_type == RasterAggType::INVALID) {
1319  const std::string error_msg =
1320  "Invalid Raster Aggregate Type: " + agg_type_str.getString();
1321  return mgr.ERROR_MESSAGE(error_msg);
1322  }
1323  const auto raster_fill_agg_type = get_raster_agg_type(fill_agg_type_str, true);
1324  if (raster_fill_agg_type == RasterAggType::INVALID) {
1325  const std::string error_msg =
1326  "Invalid Raster Fill Aggregate Type: " + fill_agg_type_str.getString();
1327  return mgr.ERROR_MESSAGE(error_msg);
1328  }
1329  return geo_rasterize_impl(mgr,
1330  input_x,
1331  input_y,
1332  input_z,
1333  raster_agg_type,
1334  raster_fill_agg_type,
1335  bin_dim_meters,
1336  geographic_coords,
1337  neighborhood_fill_radius,
1338  fill_only_nulls,
1339  output_x,
1340  output_y,
1341  output_z);
1342 }
TEMPLATE_NOINLINE int32_t geo_rasterize_impl(TableFunctionManager &mgr, const Column< T > &input_x, const Column< T > &input_y, const Column< Z > &input_z, const RasterAggType raster_agg_type, const RasterAggType raster_fill_agg_type, const T bin_dim_meters, const bool geographic_coords, const int64_t neighborhood_fill_radius, const bool fill_only_nulls, Column< T > &output_x, Column< T > &output_y, Column< Z > &output_z)
std::string getString() const
Definition: heavydbTypes.h:641
RasterAggType get_raster_agg_type(const std::string &agg_type_str, const bool is_fill_agg)

+ Here is the call graph for this function:

template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_rasterize__cpu_template ( TableFunctionManager mgr,
const Column< T > &  input_x,
const Column< T > &  input_y,
const Column< Z > &  input_z,
const TextEncodingNone agg_type_str,
const TextEncodingNone fill_agg_type_str,
const T  bin_dim_meters,
const bool  geographic_coords,
const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
const T  x_min,
const T  x_max,
const T  y_min,
const T  y_max,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Z > &  output_z 
)

Definition at line 1361 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::fill_bins_from_neighbors(), get_raster_agg_type(), TextEncodingNone::getString(), INVALID, GeoRaster< T, Z >::outputDenseColumns(), and GeoRaster< T, Z >::setMetadata().

1377  {
1378  const auto raster_agg_type = get_raster_agg_type(agg_type_str, false);
1379  if (raster_agg_type == RasterAggType::INVALID) {
1380  const std::string error_msg =
1381  "Invalid Raster Aggregate Type: " + agg_type_str.getString();
1382  return mgr.ERROR_MESSAGE(error_msg);
1383  }
1384  const auto raster_fill_agg_type = get_raster_agg_type(fill_agg_type_str, true);
1385  if (raster_fill_agg_type == RasterAggType::INVALID) {
1386  const std::string error_msg =
1387  "Invalid Raster Fill Aggregate Type: " + fill_agg_type_str.getString();
1388  return mgr.ERROR_MESSAGE(error_msg);
1389  }
1390 
1391  GeoRaster<T, Z> geo_raster(input_x,
1392  input_y,
1393  input_z,
1394  raster_agg_type,
1395  bin_dim_meters,
1396  geographic_coords,
1397  true,
1398  x_min,
1399  x_max,
1400  y_min,
1401  y_max);
1402 
1403  geo_raster.setMetadata(mgr);
1404 
1405  if (neighborhood_fill_radius > 0) {
1406  geo_raster.fill_bins_from_neighbors(
1407  neighborhood_fill_radius, fill_only_nulls, raster_fill_agg_type);
1408  }
1409 
1410  return geo_raster.outputDenseColumns(mgr, output_x, output_y, output_z);
1411 }
std::string getString() const
Definition: heavydbTypes.h:641
RasterAggType get_raster_agg_type(const std::string &agg_type_str, const bool is_fill_agg)

+ Here is the call graph for this function:

template<typename T , typename Z >
TEMPLATE_NOINLINE int32_t tf_geo_rasterize_slope__cpu_template ( TableFunctionManager mgr,
const Column< T > &  input_x,
const Column< T > &  input_y,
const Column< Z > &  input_z,
const TextEncodingNone agg_type_str,
const T  bin_dim_meters,
const bool  geographic_coords,
const int64_t  neighborhood_fill_radius,
const bool  fill_only_nulls,
const bool  compute_slope_in_degrees,
Column< T > &  output_x,
Column< T > &  output_y,
Column< Z > &  output_z,
Column< Z > &  output_slope,
Column< Z > &  output_aspect 
)

Definition at line 1509 of file GeoRasterTableFunctions.hpp.

References GeoRaster< T, Z >::calculate_slope_and_aspect(), GeoRaster< T, Z >::fill_bins_from_neighbors(), GAUSS_AVG, get_raster_agg_type(), TextEncodingNone::getString(), INVALID, GeoRaster< T, Z >::outputDenseColumns(), and GeoRaster< T, Z >::setMetadata().

1523  {
1524  const auto raster_agg_type = get_raster_agg_type(agg_type_str, false);
1525  if (raster_agg_type == RasterAggType::INVALID) {
1526  const std::string error_msg =
1527  "Invalid Raster Aggregate Type: " + agg_type_str.getString();
1528  return mgr.ERROR_MESSAGE(error_msg);
1529  }
1530 
1531  GeoRaster<T, Z> geo_raster(input_x,
1532  input_y,
1533  input_z,
1534  raster_agg_type,
1535  bin_dim_meters,
1536  geographic_coords,
1537  true);
1538  geo_raster.setMetadata(mgr);
1539 
1540  if (neighborhood_fill_radius > 0) {
1541  geo_raster.fill_bins_from_neighbors(
1542  neighborhood_fill_radius, fill_only_nulls, RasterAggType::GAUSS_AVG);
1543  }
1544 
1545  const size_t output_rows =
1546  geo_raster.outputDenseColumns(mgr, output_x, output_y, output_z);
1547  geo_raster.calculate_slope_and_aspect(
1548  output_slope, output_aspect, compute_slope_in_degrees);
1549  return output_rows;
1550 }
std::string getString() const
Definition: heavydbTypes.h:641
RasterAggType get_raster_agg_type(const std::string &agg_type_str, const bool is_fill_agg)

+ Here is the call graph for this function:

Variable Documentation

const size_t max_temp_output_entries = 200000000L

Definition at line 33 of file GeoRasterTableFunctions.hpp.

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