OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 234 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(), RelAlgTranslator::translateGeoFunctionArg(), and ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal().

920  {
922 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1075
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:1075
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:1075

+ 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 1075 of file Types.cpp.

Referenced by createGeoType().

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

+ 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(), DBHandler::fillGeoColumns(), getGeoColumns(), import_export::import_thread_delimited(), import_export::import_thread_shapefile(), Analyzer::GeoConstant::makePhysicalConstant(), foreign_storage::TextFileBufferParser::processGeoColumn(), foreign_storage::GeospatialEncoder::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:216
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:1096
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:1146

+ 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:216
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:1096

+ 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:216
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:1096

+ 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(), kMULTIPOLYGON, kPOLYGON, 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  if (ti.get_type() != row_ti.get_type()) {
1056  if (!promote_poly_to_mpoly || !(row_ti.get_type() == SQLTypes::kPOLYGON &&
1057  ti.get_type() == SQLTypes::kMULTIPOLYGON)) {
1058  throw GeoTypesError("GeoFactory", "Columnar: Geometry type mismatch");
1059  }
1060  }
1061  coords_column.push_back(coords);
1062  bounds_column.push_back(bounds);
1063  ring_sizes_column.push_back(ring_sizes);
1064  poly_rings_column.push_back(poly_rings);
1065  }
1066 
1067  } catch (const std::exception& e) {
1068  LOG(ERROR) << "Geospatial column Import Error: " << e.what();
1069  return false;
1070  }
1071 
1072  return true;
1073 }
#define LOG(tag)
Definition: Logger.h:216
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
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 1096 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().

1102  {
1103  switch (geospatial_base->getType()) {
1104  case GeoBase::GeoType::kPOINT: {
1105  const auto geospatial_point = dynamic_cast<GeoPoint*>(geospatial_base.get());
1106  CHECK(geospatial_point);
1107  geospatial_point->getColumns(coords);
1108  ti.set_type(kPOINT);
1109  break;
1110  }
1112  const auto geospatial_linestring =
1113  dynamic_cast<GeoLineString*>(geospatial_base.get());
1114  CHECK(geospatial_linestring);
1115  geospatial_linestring->getColumns(coords, bounds);
1116  ti.set_type(kLINESTRING);
1117  break;
1118  }
1120  const auto geospatial_poly = dynamic_cast<GeoPolygon*>(geospatial_base.get());
1121  CHECK(geospatial_poly);
1122  geospatial_poly->getColumns(coords, ring_sizes, bounds);
1123  if (promote_poly_to_mpoly) {
1124  if (ring_sizes.size()) {
1125  CHECK_GT(coords.size(), 0u);
1126  poly_rings.push_back(1 + geospatial_poly->getNumInteriorRings());
1127  }
1128  }
1129  ti.set_type(kPOLYGON);
1130  break;
1131  }
1133  const auto geospatial_mpoly = dynamic_cast<GeoMultiPolygon*>(geospatial_base.get());
1134  CHECK(geospatial_mpoly);
1135  geospatial_mpoly->getColumns(coords, ring_sizes, poly_rings, bounds);
1136  ti.set_type(kMULTIPOLYGON);
1137  break;
1138  }
1141  default:
1142  throw std::runtime_error("Unrecognized geospatial type");
1143  }
1144 }
Simplified core of GeoJSON Polygon coordinates definition.
Definition: heavydbTypes.h:390
#define CHECK_GT(x, y)
Definition: Logger.h:234
Simplified core of GeoJSON MultiPolygon coordinates definition.
Definition: heavydbTypes.h:411
#define CHECK(condition)
Definition: Logger.h:222
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:429

+ 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 1146 of file Types.cpp.

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

Referenced by import_export::TypedImportBuffer::convert_arrow_val_to_import_buffer(), getGeoColumns(), import_export::import_thread_delimited(), import_export::import_thread_shapefile(), foreign_storage::TextFileBufferParser::processGeoColumn(), foreign_storage::TextFileBufferParser::processInvalidGeoColumn(), and foreign_storage::GeospatialEncoder::processNullGeoElement().

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

+ 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: