OmniSciDB  bf83d84833
 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 219 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 889 of file Types.cpp.

References createGeoTypeImpl(), and createOGRGeometry().

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

890  {
892 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1043
static OGRGeometry * createOGRGeometry(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:873

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

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

894  {
895  OGRGeometry* geom = nullptr;
896  const auto err = GeoBase::createFromWkb(wkb, &geom);
897  if (err != OGRERR_NONE) {
898  throw GeoTypesError("GeoFactory", err);
899  }
901 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1043
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 903 of file Types.cpp.

References createGeoTypeImpl().

903  {
904  return GeoTypesFactory::createGeoTypeImpl(geom, false);
905 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1043

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

Referenced by createGeoType().

1044  {
1045  switch (wkbFlatten(geom->getGeometryType())) {
1046  case wkbPoint:
1047  return std::unique_ptr<GeoPoint>(new GeoPoint(geom, owns_geom_obj));
1048  case wkbLineString:
1049  return std::unique_ptr<GeoLineString>(new GeoLineString(geom, owns_geom_obj));
1050  case wkbPolygon:
1051  return std::unique_ptr<GeoPolygon>(new GeoPolygon(geom, owns_geom_obj));
1052  case wkbMultiPolygon:
1053  return std::unique_ptr<GeoMultiPolygon>(new GeoMultiPolygon(geom, owns_geom_obj));
1054  case wkbGeometryCollection:
1055  return std::unique_ptr<GeoGeometryCollection>(
1056  new GeoGeometryCollection(geom, owns_geom_obj));
1057  default:
1058  throw GeoTypesError(
1059  "GeoTypesFactory",
1060  "Unrecognized geometry type: " + std::string(geom->getGeometryName()));
1061  }
1062 }

+ Here is the caller graph for this function:

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

Definition at line 873 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().

873  {
874  OGRGeometry* geom = nullptr;
875  OGRErr err = OGRERR_NONE;
876  if (wkt_or_wkb_hex.empty()) {
877  err = OGRERR_NOT_ENOUGH_DATA;
878  } else if (wkt_or_wkb_hex[0] == '0') { // all WKB hex strings start with a 0
879  err = GeoBase::createFromWkb(hex_string_to_binary_vector(wkt_or_wkb_hex), &geom);
880  } else {
881  err = GeoBase::createFromWktString(wkt_or_wkb_hex, &geom);
882  }
883  if (err != OGRERR_NONE) {
884  throw GeoTypesError("GeoFactory", err);
885  }
886  return geom;
887 }
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:858

+ 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 907 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(), getGeoColumns(), import_export::import_thread_delimited(), import_export::import_thread_shapefile(), DBHandler::load_table(), DBHandler::load_table_binary_columnar(), foreign_storage::csv_file_buffer_parser::process_geo_column(), foreign_storage::ParquetGeospatialEncoder::processGeoElement(), and RelAlgTranslator::translateGeoLiteral().

913  {
914  try {
915  if (wkt_or_wkb_hex.empty() || wkt_or_wkb_hex == "NULL") {
917  ti, coords, bounds, ring_sizes, poly_rings, promote_poly_to_mpoly);
918  return true;
919  }
920 
921  const auto geospatial_base = GeoTypesFactory::createGeoType(wkt_or_wkb_hex);
922 
923  if (!geospatial_base || !geospatial_base->transform(ti)) {
924  return false;
925  }
926 
927  getGeoColumnsImpl(geospatial_base,
928  ti,
929  coords,
930  bounds,
931  ring_sizes,
932  poly_rings,
933  promote_poly_to_mpoly);
934 
935  } catch (const std::exception& e) {
936  LOG(ERROR) << "Geospatial Import Error: " << e.what();
937  return false;
938  }
939 
940  return true;
941 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:889
#define LOG(tag)
Definition: Logger.h:188
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:1064
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:1114

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

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

949  {
950  try {
951  const auto geospatial_base = GeoTypesFactory::createGeoType(wkb);
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:889
#define LOG(tag)
Definition: Logger.h:188
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:1064

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

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

979  {
980  try {
981  const auto geospatial_base = GeoTypesFactory::createGeoType(geom);
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:889
#define LOG(tag)
Definition: Logger.h:188
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:1064

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

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

1009  {
1010  try {
1011  for (const auto& wkt_or_wkb_hex : *wkt_or_wkb_hex_column) {
1012  std::vector<double> coords;
1013  std::vector<double> bounds;
1014  std::vector<int> ring_sizes;
1015  std::vector<int> poly_rings;
1016 
1017  SQLTypeInfo row_ti{ti};
1018  getGeoColumns(wkt_or_wkb_hex,
1019  row_ti,
1020  coords,
1021  bounds,
1022  ring_sizes,
1023  poly_rings,
1024  promote_poly_to_mpoly);
1025 
1026  if (ti.get_type() != row_ti.get_type()) {
1027  throw GeoTypesError("GeoFactory", "Columnar: Geometry type mismatch");
1028  }
1029  coords_column.push_back(coords);
1030  bounds_column.push_back(bounds);
1031  ring_sizes_column.push_back(ring_sizes);
1032  poly_rings_column.push_back(poly_rings);
1033  }
1034 
1035  } catch (const std::exception& e) {
1036  LOG(ERROR) << "Geospatial column Import Error: " << e.what();
1037  return false;
1038  }
1039 
1040  return true;
1041 }
#define LOG(tag)
Definition: Logger.h:188
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:311
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:907

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

1070  {
1071  switch (geospatial_base->getType()) {
1072  case GeoBase::GeoType::kPOINT: {
1073  const auto geospatial_point = dynamic_cast<GeoPoint*>(geospatial_base.get());
1074  CHECK(geospatial_point);
1075  geospatial_point->getColumns(coords);
1076  ti.set_type(kPOINT);
1077  break;
1078  }
1080  const auto geospatial_linestring =
1081  dynamic_cast<GeoLineString*>(geospatial_base.get());
1082  CHECK(geospatial_linestring);
1083  geospatial_linestring->getColumns(coords, bounds);
1084  ti.set_type(kLINESTRING);
1085  break;
1086  }
1088  const auto geospatial_poly = dynamic_cast<GeoPolygon*>(geospatial_base.get());
1089  CHECK(geospatial_poly);
1090  geospatial_poly->getColumns(coords, ring_sizes, bounds);
1091  if (promote_poly_to_mpoly) {
1092  if (ring_sizes.size()) {
1093  CHECK_GT(coords.size(), 0u);
1094  poly_rings.push_back(1 + geospatial_poly->getNumInteriorRings());
1095  }
1096  }
1097  ti.set_type(kPOLYGON);
1098  break;
1099  }
1101  const auto geospatial_mpoly = dynamic_cast<GeoMultiPolygon*>(geospatial_base.get());
1102  CHECK(geospatial_mpoly);
1103  geospatial_mpoly->getColumns(coords, ring_sizes, poly_rings, bounds);
1104  ti.set_type(kMULTIPOLYGON);
1105  break;
1106  }
1109  default:
1110  throw std::runtime_error("Unrecognized geospatial type");
1111  }
1112 }
#define CHECK_GT(x, y)
Definition: Logger.h:209
#define CHECK(condition)
Definition: Logger.h:197
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:401

+ 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 1114 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::csv_file_buffer_parser::process_geo_column(), and foreign_storage::ParquetGeospatialEncoder::processNullGeoElement().

1119  {
1120  auto t = ti.get_type();
1121  switch (t) {
1122  case kPOINT: {
1123  // NULL fixlen coords array
1124  coords.push_back(NULL_ARRAY_DOUBLE);
1125  coords.push_back(NULL_DOUBLE);
1126  } break;
1127  case kLINESTRING:
1128  case kPOLYGON:
1129  case kMULTIPOLYGON: {
1130  // Leaving coords array empty
1131  // NULL fixlen bounds array
1132  bounds.push_back(NULL_ARRAY_DOUBLE);
1133  bounds.push_back(NULL_DOUBLE);
1134  bounds.push_back(NULL_DOUBLE);
1135  bounds.push_back(NULL_DOUBLE);
1136  // Leaving ring_sizes and poly_rings arrays empty
1137  } break;
1138  default:
1139  throw std::runtime_error("Unsupported NULL geo");
1140  }
1141 }
#define NULL_DOUBLE
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:311
#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: