OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Geospatial::GeoTypesFactory Class Reference

#include <Types.h>

Static Public Member Functions

static OGRGeometry * createOGRGeometry (const std::string &wkt_or_wkb_hex)
 
static std::unique_ptr< GeoBasecreateGeoType (const std::string &wkt_or_wkb_hex)
 
static std::unique_ptr< GeoBasecreateGeoType (const std::vector< uint8_t > &wkb)
 
static std::unique_ptr< GeoBasecreateGeoType (OGRGeometry *geom)
 
static bool getGeoColumns (const std::string &wkt_or_wkb_hex, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
 
static bool getGeoColumns (const std::vector< uint8_t > &wkb, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
 
static bool getGeoColumns (OGRGeometry *geom, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
 
static bool getGeoColumns (const std::vector< std::string > *wkt_or_wkb_hex_column, SQLTypeInfo &ti, std::vector< std::vector< double >> &coords_column, std::vector< std::vector< double >> &bounds_column, std::vector< std::vector< int >> &ring_sizes_column, std::vector< std::vector< int >> &poly_rings_column, const bool promote_poly_to_mpoly=false)
 
static void getNullGeoColumns (SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
 

Static Private Member Functions

static std::unique_ptr
< Geospatial::GeoBase
createGeoTypeImpl (OGRGeometry *geom, const bool owns_geom_obj=true)
 
static void getGeoColumnsImpl (const std::unique_ptr< GeoBase > &geospatial_base, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
 

Detailed Description

Definition at line 233 of file Types.h.

Member Function Documentation

std::unique_ptr< GeoBase > Geospatial::GeoTypesFactory::createGeoType ( const std::string &  wkt_or_wkb_hex)
static

Definition at line 919 of file Types.cpp.

References createGeoTypeImpl(), and createOGRGeometry().

Referenced by getGeoColumns(), Geospatial::GeoBase::optimized_run(), Geospatial::GeoBase::run(), and RelAlgTranslator::translateGeoFunctionArg().

920  {
922 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1073
static OGRGeometry * createOGRGeometry(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:903

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unique_ptr< GeoBase > Geospatial::GeoTypesFactory::createGeoType ( const std::vector< uint8_t > &  wkb)
static

Definition at line 924 of file Types.cpp.

References Geospatial::GeoBase::createFromWkb(), and createGeoTypeImpl().

924  {
925  OGRGeometry* geom = nullptr;
926  const auto err = GeoBase::createFromWkb(wkb, &geom);
927  if (err != OGRERR_NONE) {
928  throw GeoTypesError("GeoFactory", err);
929  }
931 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1073
static int createFromWkb(const std::vector< uint8_t > &wkb, OGRGeometry **geom)
Definition: Types.cpp:173

+ Here is the call graph for this function:

std::unique_ptr< GeoBase > Geospatial::GeoTypesFactory::createGeoType ( OGRGeometry *  geom)
static

Definition at line 933 of file Types.cpp.

References createGeoTypeImpl().

933  {
934  return GeoTypesFactory::createGeoTypeImpl(geom, false);
935 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1073

+ Here is the call graph for this function:

std::unique_ptr< GeoBase > Geospatial::GeoTypesFactory::createGeoTypeImpl ( OGRGeometry *  geom,
const bool  owns_geom_obj = true 
)
staticprivate

Definition at line 1073 of file Types.cpp.

Referenced by createGeoType().

1074  {
1075  switch (wkbFlatten(geom->getGeometryType())) {
1076  case wkbPoint:
1077  return std::unique_ptr<GeoPoint>(new GeoPoint(geom, owns_geom_obj));
1078  case wkbLineString:
1079  return std::unique_ptr<GeoLineString>(new GeoLineString(geom, owns_geom_obj));
1080  case wkbPolygon:
1081  return std::unique_ptr<GeoPolygon>(new GeoPolygon(geom, owns_geom_obj));
1082  case wkbMultiPolygon:
1083  return std::unique_ptr<GeoMultiPolygon>(new GeoMultiPolygon(geom, owns_geom_obj));
1084  case wkbGeometryCollection:
1085  return std::unique_ptr<GeoGeometryCollection>(
1086  new GeoGeometryCollection(geom, owns_geom_obj));
1087  default:
1088  throw GeoTypesError(
1089  "GeoTypesFactory",
1090  "Unrecognized geometry type: " + std::string(geom->getGeometryName()));
1091  }
1092 }

+ Here is the caller graph for this function:

OGRGeometry * Geospatial::GeoTypesFactory::createOGRGeometry ( const std::string &  wkt_or_wkb_hex)
static

Definition at line 903 of file Types.cpp.

References Geospatial::GeoBase::createFromWkb(), Geospatial::GeoBase::createFromWktString(), and Geospatial::anonymous_namespace{Types.cpp}::hex_string_to_binary_vector().

Referenced by createGeoType(), and import_export::import_thread_delimited().

903  {
904  OGRGeometry* geom = nullptr;
905  OGRErr err = OGRERR_NONE;
906  if (wkt_or_wkb_hex.empty()) {
907  err = OGRERR_NOT_ENOUGH_DATA;
908  } else if (wkt_or_wkb_hex[0] == '0') { // all WKB hex strings start with a 0
909  err = GeoBase::createFromWkb(hex_string_to_binary_vector(wkt_or_wkb_hex), &geom);
910  } else {
911  err = GeoBase::createFromWktString(wkt_or_wkb_hex, &geom);
912  }
913  if (err != OGRERR_NONE) {
914  throw GeoTypesError("GeoFactory", err);
915  }
916  return geom;
917 }
static int createFromWkb(const std::vector< uint8_t > &wkb, OGRGeometry **geom)
Definition: Types.cpp:173
static int createFromWktString(const std::string &wkt, OGRGeometry **geom)
Definition: Types.cpp:154
std::vector< uint8_t > hex_string_to_binary_vector(const std::string &wkb_hex)
Definition: Types.cpp:888

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Geospatial::GeoTypesFactory::getGeoColumns ( const std::string &  wkt_or_wkb_hex,
SQLTypeInfo ti,
std::vector< double > &  coords,
std::vector< double > &  bounds,
std::vector< int > &  ring_sizes,
std::vector< int > &  poly_rings,
const bool  promote_poly_to_mpoly = false 
)
static

Definition at line 937 of file Types.cpp.

References createGeoType(), logger::ERROR, getGeoColumnsImpl(), getNullGeoColumns(), and LOG.

Referenced by Parser::InsertValuesStmt::analyze(), import_export::TypedImportBuffer::convert_arrow_val_to_import_buffer(), Parser::AddColumnStmt::execute(), import_export::fill_missing_columns(), getGeoColumns(), import_export::import_thread_delimited(), import_export::import_thread_shapefile(), DBHandler::load_table(), DBHandler::load_table_binary_columnar_internal(), Analyzer::GeoConstant::makePhysicalConstant(), foreign_storage::csv_file_buffer_parser::process_geo_column(), foreign_storage::ParquetGeospatialEncoder::processGeoElement(), and RelAlgTranslator::translateGeoLiteral().

943  {
944  try {
945  if (wkt_or_wkb_hex.empty() || wkt_or_wkb_hex == "NULL") {
947  ti, coords, bounds, ring_sizes, poly_rings, promote_poly_to_mpoly);
948  return true;
949  }
950 
951  const auto geospatial_base = GeoTypesFactory::createGeoType(wkt_or_wkb_hex);
952 
953  if (!geospatial_base || !geospatial_base->transform(ti)) {
954  return false;
955  }
956 
957  getGeoColumnsImpl(geospatial_base,
958  ti,
959  coords,
960  bounds,
961  ring_sizes,
962  poly_rings,
963  promote_poly_to_mpoly);
964 
965  } catch (const std::exception& e) {
966  LOG(ERROR) << "Geospatial Import Error: " << e.what();
967  return false;
968  }
969 
970  return true;
971 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:919
#define LOG(tag)
Definition: Logger.h:194
static void getGeoColumnsImpl(const std::unique_ptr< GeoBase > &geospatial_base, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
Definition: Types.cpp:1094
static void getNullGeoColumns(SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
Definition: Types.cpp:1144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Geospatial::GeoTypesFactory::getGeoColumns ( const std::vector< uint8_t > &  wkb,
SQLTypeInfo ti,
std::vector< double > &  coords,
std::vector< double > &  bounds,
std::vector< int > &  ring_sizes,
std::vector< int > &  poly_rings,
const bool  promote_poly_to_mpoly = false 
)
static

Definition at line 973 of file Types.cpp.

References createGeoType(), logger::ERROR, getGeoColumnsImpl(), and LOG.

979  {
980  try {
981  const auto geospatial_base = GeoTypesFactory::createGeoType(wkb);
982 
983  if (!geospatial_base || !geospatial_base->transform(ti)) {
984  return false;
985  }
986 
987  getGeoColumnsImpl(geospatial_base,
988  ti,
989  coords,
990  bounds,
991  ring_sizes,
992  poly_rings,
993  promote_poly_to_mpoly);
994 
995  } catch (const std::exception& e) {
996  LOG(ERROR) << "Geospatial Import Error: " << e.what();
997  return false;
998  }
999 
1000  return true;
1001 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:919
#define LOG(tag)
Definition: Logger.h:194
static void getGeoColumnsImpl(const std::unique_ptr< GeoBase > &geospatial_base, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
Definition: Types.cpp:1094

+ Here is the call graph for this function:

bool Geospatial::GeoTypesFactory::getGeoColumns ( OGRGeometry *  geom,
SQLTypeInfo ti,
std::vector< double > &  coords,
std::vector< double > &  bounds,
std::vector< int > &  ring_sizes,
std::vector< int > &  poly_rings,
const bool  promote_poly_to_mpoly = false 
)
static

Definition at line 1003 of file Types.cpp.

References createGeoType(), logger::ERROR, getGeoColumnsImpl(), and LOG.

1009  {
1010  try {
1011  const auto geospatial_base = GeoTypesFactory::createGeoType(geom);
1012 
1013  if (!geospatial_base || !geospatial_base->transform(ti)) {
1014  return false;
1015  }
1016 
1017  getGeoColumnsImpl(geospatial_base,
1018  ti,
1019  coords,
1020  bounds,
1021  ring_sizes,
1022  poly_rings,
1023  promote_poly_to_mpoly);
1024 
1025  } catch (const std::exception& e) {
1026  LOG(ERROR) << "Geospatial Import Error: " << e.what();
1027  return false;
1028  }
1029 
1030  return true;
1031 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:919
#define LOG(tag)
Definition: Logger.h:194
static void getGeoColumnsImpl(const std::unique_ptr< GeoBase > &geospatial_base, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
Definition: Types.cpp:1094

+ Here is the call graph for this function:

bool Geospatial::GeoTypesFactory::getGeoColumns ( const std::vector< std::string > *  wkt_or_wkb_hex_column,
SQLTypeInfo ti,
std::vector< std::vector< double >> &  coords_column,
std::vector< std::vector< double >> &  bounds_column,
std::vector< std::vector< int >> &  ring_sizes_column,
std::vector< std::vector< int >> &  poly_rings_column,
const bool  promote_poly_to_mpoly = false 
)
static

Definition at line 1033 of file Types.cpp.

References logger::ERROR, SQLTypeInfo::get_type(), getGeoColumns(), and LOG.

1039  {
1040  try {
1041  for (const auto& wkt_or_wkb_hex : *wkt_or_wkb_hex_column) {
1042  std::vector<double> coords;
1043  std::vector<double> bounds;
1044  std::vector<int> ring_sizes;
1045  std::vector<int> poly_rings;
1046 
1047  SQLTypeInfo row_ti{ti};
1048  getGeoColumns(wkt_or_wkb_hex,
1049  row_ti,
1050  coords,
1051  bounds,
1052  ring_sizes,
1053  poly_rings,
1054  promote_poly_to_mpoly);
1055 
1056  if (ti.get_type() != row_ti.get_type()) {
1057  throw GeoTypesError("GeoFactory", "Columnar: Geometry type mismatch");
1058  }
1059  coords_column.push_back(coords);
1060  bounds_column.push_back(bounds);
1061  ring_sizes_column.push_back(ring_sizes);
1062  poly_rings_column.push_back(poly_rings);
1063  }
1064 
1065  } catch (const std::exception& e) {
1066  LOG(ERROR) << "Geospatial column Import Error: " << e.what();
1067  return false;
1068  }
1069 
1070  return true;
1071 }
#define LOG(tag)
Definition: Logger.h:194
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
static bool getGeoColumns(const std::string &wkt_or_wkb_hex, SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, const bool promote_poly_to_mpoly=false)
Definition: Types.cpp:937

+ Here is the call graph for this function:

void Geospatial::GeoTypesFactory::getGeoColumnsImpl ( const std::unique_ptr< GeoBase > &  geospatial_base,
SQLTypeInfo ti,
std::vector< double > &  coords,
std::vector< double > &  bounds,
std::vector< int > &  ring_sizes,
std::vector< int > &  poly_rings,
const bool  promote_poly_to_mpoly = false 
)
staticprivate

Definition at line 1094 of file Types.cpp.

References CHECK, CHECK_GT, Geospatial::GeoBase::kGEOMETRY, Geospatial::GeoBase::kGEOMETRYCOLLECTION, Geospatial::GeoBase::kLINESTRING, kLINESTRING, Geospatial::GeoBase::kMULTIPOLYGON, kMULTIPOLYGON, Geospatial::GeoBase::kPOINT, kPOINT, Geospatial::GeoBase::kPOLYGON, kPOLYGON, and SQLTypeInfo::set_type().

Referenced by getGeoColumns().

1100  {
1101  switch (geospatial_base->getType()) {
1102  case GeoBase::GeoType::kPOINT: {
1103  const auto geospatial_point = dynamic_cast<GeoPoint*>(geospatial_base.get());
1104  CHECK(geospatial_point);
1105  geospatial_point->getColumns(coords);
1106  ti.set_type(kPOINT);
1107  break;
1108  }
1110  const auto geospatial_linestring =
1111  dynamic_cast<GeoLineString*>(geospatial_base.get());
1112  CHECK(geospatial_linestring);
1113  geospatial_linestring->getColumns(coords, bounds);
1114  ti.set_type(kLINESTRING);
1115  break;
1116  }
1118  const auto geospatial_poly = dynamic_cast<GeoPolygon*>(geospatial_base.get());
1119  CHECK(geospatial_poly);
1120  geospatial_poly->getColumns(coords, ring_sizes, bounds);
1121  if (promote_poly_to_mpoly) {
1122  if (ring_sizes.size()) {
1123  CHECK_GT(coords.size(), 0u);
1124  poly_rings.push_back(1 + geospatial_poly->getNumInteriorRings());
1125  }
1126  }
1127  ti.set_type(kPOLYGON);
1128  break;
1129  }
1131  const auto geospatial_mpoly = dynamic_cast<GeoMultiPolygon*>(geospatial_base.get());
1132  CHECK(geospatial_mpoly);
1133  geospatial_mpoly->getColumns(coords, ring_sizes, poly_rings, bounds);
1134  ti.set_type(kMULTIPOLYGON);
1135  break;
1136  }
1139  default:
1140  throw std::runtime_error("Unrecognized geospatial type");
1141  }
1142 }
#define CHECK_GT(x, y)
Definition: Logger.h:215
#define CHECK(condition)
Definition: Logger.h:203
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:404

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Geospatial::GeoTypesFactory::getNullGeoColumns ( SQLTypeInfo ti,
std::vector< double > &  coords,
std::vector< double > &  bounds,
std::vector< int > &  ring_sizes,
std::vector< int > &  poly_rings,
const bool  promote_poly_to_mpoly = false 
)
static

Definition at line 1144 of file Types.cpp.

References SQLTypeInfo::get_type(), kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, NULL_ARRAY_DOUBLE, NULL_DOUBLE, and t.

Referenced by import_export::TypedImportBuffer::convert_arrow_val_to_import_buffer(), getGeoColumns(), import_export::import_thread_delimited(), import_export::import_thread_shapefile(), foreign_storage::csv_file_buffer_parser::process_geo_column(), and foreign_storage::ParquetGeospatialEncoder::processNullGeoElement().

1149  {
1150  auto t = ti.get_type();
1151  switch (t) {
1152  case kPOINT: {
1153  // NULL fixlen coords array
1154  coords.push_back(NULL_ARRAY_DOUBLE);
1155  coords.push_back(NULL_DOUBLE);
1156  } break;
1157  case kLINESTRING:
1158  case kPOLYGON:
1159  case kMULTIPOLYGON: {
1160  // Leaving coords array empty
1161  // NULL fixlen bounds array
1162  bounds.push_back(NULL_ARRAY_DOUBLE);
1163  bounds.push_back(NULL_DOUBLE);
1164  bounds.push_back(NULL_DOUBLE);
1165  bounds.push_back(NULL_DOUBLE);
1166  // Leaving ring_sizes and poly_rings arrays empty
1167  } break;
1168  default:
1169  throw std::runtime_error("Unsupported NULL geo");
1170  }
1171 }
#define NULL_DOUBLE
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
#define NULL_ARRAY_DOUBLE
char * t

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


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