OmniSciDB  a987f07e93
 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 WkbView)
 
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 291 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 1061 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().

1062  {
1063  return GeoTypesFactory::createGeoTypeImpl(createOGRGeometry(wkt_or_wkb_hex));
1064 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1217
static OGRGeometry * createOGRGeometry(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:1044

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unique_ptr< GeoBase > Geospatial::GeoTypesFactory::createGeoType ( const WkbView  wkb_view)
static

Definition at line 1066 of file Types.cpp.

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

1066  {
1067  OGRGeometry* geom = nullptr;
1068  const auto err = GeoBase::createFromWkbView(&geom, wkb_view);
1069  if (err != OGRERR_NONE) {
1070  throw GeoTypesError("GeoFactory", err);
1071  }
1073 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1217
static int createFromWkbView(OGRGeometry **geom, WkbView const)
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 1075 of file Types.cpp.

References createGeoTypeImpl().

1075  {
1076  return GeoTypesFactory::createGeoTypeImpl(geom, false);
1077 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1217

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

Referenced by createGeoType().

1218  {
1219  switch (wkbFlatten(geom->getGeometryType())) {
1220  case wkbPoint:
1221  return std::unique_ptr<GeoPoint>(new GeoPoint(geom, owns_geom_obj));
1222  case wkbMultiPoint:
1223  return std::unique_ptr<GeoMultiPoint>(new GeoMultiPoint(geom, owns_geom_obj));
1224  case wkbLineString:
1225  return std::unique_ptr<GeoLineString>(new GeoLineString(geom, owns_geom_obj));
1226  case wkbMultiLineString:
1227  return std::unique_ptr<GeoMultiLineString>(
1228  new GeoMultiLineString(geom, owns_geom_obj));
1229  case wkbPolygon:
1230  return std::unique_ptr<GeoPolygon>(new GeoPolygon(geom, owns_geom_obj));
1231  case wkbMultiPolygon:
1232  return std::unique_ptr<GeoMultiPolygon>(new GeoMultiPolygon(geom, owns_geom_obj));
1233  case wkbGeometryCollection:
1234  return std::unique_ptr<GeoGeometryCollection>(
1235  new GeoGeometryCollection(geom, owns_geom_obj));
1236  default:
1237  throw GeoTypesError(
1238  "GeoTypesFactory",
1239  "Unrecognized geometry type: " + std::string(geom->getGeometryName()));
1240  }
1241 }

+ Here is the caller graph for this function:

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

Definition at line 1044 of file Types.cpp.

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

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

1044  {
1045  OGRGeometry* geom = nullptr;
1046  OGRErr err = OGRERR_NONE;
1047  if (wkt_or_wkb_hex.empty()) {
1048  err = OGRERR_NOT_ENOUGH_DATA;
1049  } else if (wkt_or_wkb_hex[0] == '0') { // all WKB hex strings start with a 0
1050  auto const wkb = hex_string_to_binary_vector(wkt_or_wkb_hex);
1051  err = GeoBase::createFromWkbView(&geom, {wkb.data(), wkb.size()});
1052  } else {
1053  err = GeoBase::createFromWktString(wkt_or_wkb_hex, &geom);
1054  }
1055  if (err != OGRERR_NONE) {
1056  throw GeoTypesError("GeoFactory", err);
1057  }
1058  return geom;
1059 }
static int createFromWkbView(OGRGeometry **geom, WkbView const)
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:1029

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

1085  {
1086  try {
1087  if (wkt_or_wkb_hex.empty() || wkt_or_wkb_hex == "NULL") {
1089  ti, coords, bounds, ring_sizes, poly_rings, promote_poly_to_mpoly);
1090  return true;
1091  }
1092 
1093  const auto geospatial_base = GeoTypesFactory::createGeoType(wkt_or_wkb_hex);
1094 
1095  if (!geospatial_base || !geospatial_base->transform(ti)) {
1096  return false;
1097  }
1098 
1099  getGeoColumnsImpl(geospatial_base,
1100  ti,
1101  coords,
1102  bounds,
1103  ring_sizes,
1104  poly_rings,
1105  promote_poly_to_mpoly);
1106 
1107  } catch (const std::exception& e) {
1108  LOG(ERROR) << "Geospatial Import Error: " << e.what();
1109  return false;
1110  }
1111 
1112  return true;
1113 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:1061
#define LOG(tag)
Definition: Logger.h:283
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:1243
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:1309

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

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

1121  {
1122  try {
1123  const auto geospatial_base = GeoTypesFactory::createGeoType({wkb.data(), wkb.size()});
1124 
1125  if (!geospatial_base || !geospatial_base->transform(ti)) {
1126  return false;
1127  }
1128 
1129  getGeoColumnsImpl(geospatial_base,
1130  ti,
1131  coords,
1132  bounds,
1133  ring_sizes,
1134  poly_rings,
1135  promote_poly_to_mpoly);
1136 
1137  } catch (const std::exception& e) {
1138  LOG(ERROR) << "Geospatial Import Error: " << e.what();
1139  return false;
1140  }
1141 
1142  return true;
1143 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:1061
#define LOG(tag)
Definition: Logger.h:283
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:1243

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

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

1151  {
1152  try {
1153  const auto geospatial_base = GeoTypesFactory::createGeoType(geom);
1154 
1155  if (!geospatial_base || !geospatial_base->transform(ti)) {
1156  return false;
1157  }
1158 
1159  getGeoColumnsImpl(geospatial_base,
1160  ti,
1161  coords,
1162  bounds,
1163  ring_sizes,
1164  poly_rings,
1165  promote_poly_to_mpoly);
1166 
1167  } catch (const std::exception& e) {
1168  LOG(ERROR) << "Geospatial Import Error: " << e.what();
1169  return false;
1170  }
1171 
1172  return true;
1173 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:1061
#define LOG(tag)
Definition: Logger.h:283
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:1243

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

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

1181  {
1182  try {
1183  for (const auto& wkt_or_wkb_hex : *wkt_or_wkb_hex_column) {
1184  std::vector<double> coords;
1185  std::vector<double> bounds;
1186  std::vector<int> ring_sizes;
1187  std::vector<int> poly_rings;
1188 
1189  SQLTypeInfo row_ti{ti};
1190  getGeoColumns(wkt_or_wkb_hex,
1191  row_ti,
1192  coords,
1193  bounds,
1194  ring_sizes,
1195  poly_rings,
1196  promote_poly_to_mpoly);
1197  if (ti.get_type() != row_ti.get_type()) {
1198  if (!promote_poly_to_mpoly || !(row_ti.get_type() == SQLTypes::kPOLYGON &&
1199  ti.get_type() == SQLTypes::kMULTIPOLYGON)) {
1200  throw GeoTypesError("GeoFactory", "Columnar: Geometry type mismatch");
1201  }
1202  }
1203  coords_column.push_back(coords);
1204  bounds_column.push_back(bounds);
1205  ring_sizes_column.push_back(ring_sizes);
1206  poly_rings_column.push_back(poly_rings);
1207  }
1208 
1209  } catch (const std::exception& e) {
1210  LOG(ERROR) << "Geospatial column Import Error: " << e.what();
1211  return false;
1212  }
1213 
1214  return true;
1215 }
#define LOG(tag)
Definition: Logger.h:283
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:380
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:1079

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

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

Referenced by getGeoColumns().

1249  {
1250  switch (geospatial_base->getType()) {
1251  case GeoBase::GeoType::kPOINT: {
1252  const auto geospatial_point = dynamic_cast<GeoPoint*>(geospatial_base.get());
1253  CHECK(geospatial_point);
1254  geospatial_point->getColumns(coords);
1255  ti.set_type(kPOINT);
1256  break;
1257  }
1259  const auto geospatial_multipoint =
1260  dynamic_cast<GeoMultiPoint*>(geospatial_base.get());
1261  CHECK(geospatial_multipoint);
1262  geospatial_multipoint->getColumns(coords, bounds);
1263  ti.set_type(kMULTIPOINT);
1264  break;
1265  }
1267  const auto geospatial_linestring =
1268  dynamic_cast<GeoLineString*>(geospatial_base.get());
1269  CHECK(geospatial_linestring);
1270  geospatial_linestring->getColumns(coords, bounds);
1271  ti.set_type(kLINESTRING);
1272  break;
1273  }
1275  const auto geospatial_multilinestring =
1276  dynamic_cast<GeoMultiLineString*>(geospatial_base.get());
1277  CHECK(geospatial_multilinestring);
1278  geospatial_multilinestring->getColumns(coords, ring_sizes, bounds);
1280  break;
1281  }
1283  const auto geospatial_poly = dynamic_cast<GeoPolygon*>(geospatial_base.get());
1284  CHECK(geospatial_poly);
1285  geospatial_poly->getColumns(coords, ring_sizes, bounds);
1286  if (promote_poly_to_mpoly) {
1287  if (ring_sizes.size()) {
1288  CHECK_GT(coords.size(), 0u);
1289  poly_rings.push_back(1 + geospatial_poly->getNumInteriorRings());
1290  }
1291  }
1292  ti.set_type(kPOLYGON);
1293  break;
1294  }
1296  const auto geospatial_mpoly = dynamic_cast<GeoMultiPolygon*>(geospatial_base.get());
1297  CHECK(geospatial_mpoly);
1298  geospatial_mpoly->getColumns(coords, ring_sizes, poly_rings, bounds);
1299  ti.set_type(kMULTIPOLYGON);
1300  break;
1301  }
1304  default:
1305  throw std::runtime_error("Unrecognized geospatial type");
1306  }
1307 }
Simplified core of GeoJSON Polygon coordinates definition.
Definition: heavydbTypes.h:636
#define CHECK_GT(x, y)
Definition: Logger.h:301
Simplified core of GeoJSON MultiPolygon coordinates definition.
Definition: heavydbTypes.h:657
#define CHECK(condition)
Definition: Logger.h:289
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:490

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

References SQLTypeInfo::get_type(), kLINESTRING, kMULTILINESTRING, kMULTIPOINT, 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().

1314  {
1315  auto t = ti.get_type();
1316  switch (t) {
1317  case kPOINT: {
1318  // NULL fixlen coords array
1319  coords.push_back(NULL_ARRAY_DOUBLE);
1320  coords.push_back(NULL_DOUBLE);
1321  } break;
1322  case kMULTIPOINT:
1323  case kLINESTRING:
1324  case kMULTILINESTRING:
1325  case kPOLYGON:
1326  case kMULTIPOLYGON: {
1327  // Leaving coords array empty
1328  // NULL fixlen bounds array
1329  bounds.push_back(NULL_ARRAY_DOUBLE);
1330  bounds.push_back(NULL_DOUBLE);
1331  bounds.push_back(NULL_DOUBLE);
1332  bounds.push_back(NULL_DOUBLE);
1333  // Leaving ring_sizes and poly_rings arrays empty
1334  } break;
1335  default:
1336  throw std::runtime_error("Unsupported NULL geo");
1337  }
1338 }
#define NULL_DOUBLE
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:380
#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: