OmniSciDB  a5dc49c757
 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, const bool validate_with_geos_if_available)
 
static std::unique_ptr< GeoBasecreateGeoType (const std::string &wkt_or_wkb_hex, const bool validate_with_geos_if_available)
 
static std::unique_ptr< GeoBasecreateGeoType (const WkbView, const bool validate_with_geos_if_available)
 
static std::unique_ptr< GeoBasecreateGeoType (OGRGeometry *geom, const bool validate_with_geos_if_available)
 
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 validate_with_geos_if_available)
 
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 validate_with_geos_if_available)
 
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 validate_with_geos_if_available)
 
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 validate_with_geos_if_available)
 
static void getNullGeoColumns (SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings)
 

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)
 

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,
const bool  validate_with_geos_if_available 
)
static

Definition at line 1085 of file Types.cpp.

References createGeoTypeImpl(), createOGRGeometry(), and Geospatial::anonymous_namespace{Types.cpp}::validate_ogr().

Referenced by getGeoColumns(), Geospatial::GeoBase::optimized_run(), Geospatial::GeoBase::run(), RelAlgTranslator::translateGeoFunctionArg(), and ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal().

1087  {
1089  createOGRGeometry(wkt_or_wkb_hex, false)); // validate next
1090  if (validate_with_geos_if_available) {
1091  validate_ogr(g->getOGRGeometry());
1092  }
1093  return g;
1094 }
void validate_ogr(const OGRGeometry *geom)
Definition: Types.cpp:1049
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1241
static OGRGeometry * createOGRGeometry(const std::string &wkt_or_wkb_hex, const bool validate_with_geos_if_available)
Definition: Types.cpp:1063

+ 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,
const bool  validate_with_geos_if_available 
)
static

Definition at line 1096 of file Types.cpp.

References Geospatial::GeoBase::createFromWkbView(), createGeoTypeImpl(), and Geospatial::anonymous_namespace{Types.cpp}::validate_ogr().

1098  {
1099  OGRGeometry* geom = nullptr;
1100  const auto err = GeoBase::createFromWkbView(&geom, wkb_view);
1101  if (err != OGRERR_NONE) {
1102  throw GeoTypesError("GeoFactory", err);
1103  }
1104  auto g = GeoTypesFactory::createGeoTypeImpl(geom);
1105  if (validate_with_geos_if_available) {
1106  validate_ogr(g->getOGRGeometry());
1107  }
1108  return g;
1109 }
void validate_ogr(const OGRGeometry *geom)
Definition: Types.cpp:1049
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1241
static int createFromWkbView(OGRGeometry **geom, WkbView const)
Definition: Types.cpp:174

+ Here is the call graph for this function:

std::unique_ptr< GeoBase > Geospatial::GeoTypesFactory::createGeoType ( OGRGeometry *  geom,
const bool  validate_with_geos_if_available 
)
static

Definition at line 1111 of file Types.cpp.

References createGeoTypeImpl(), and Geospatial::anonymous_namespace{Types.cpp}::validate_ogr().

1113  {
1114  auto g = GeoTypesFactory::createGeoTypeImpl(geom, false);
1115  if (validate_with_geos_if_available) {
1116  validate_ogr(g->getOGRGeometry());
1117  }
1118  return g;
1119 }
void validate_ogr(const OGRGeometry *geom)
Definition: Types.cpp:1049
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1241

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

Referenced by createGeoType().

1242  {
1243  switch (wkbFlatten(geom->getGeometryType())) {
1244  case wkbPoint:
1245  return std::unique_ptr<GeoPoint>(new GeoPoint(geom, owns_geom_obj));
1246  case wkbMultiPoint:
1247  return std::unique_ptr<GeoMultiPoint>(new GeoMultiPoint(geom, owns_geom_obj));
1248  case wkbLineString:
1249  return std::unique_ptr<GeoLineString>(new GeoLineString(geom, owns_geom_obj));
1250  case wkbMultiLineString:
1251  return std::unique_ptr<GeoMultiLineString>(
1252  new GeoMultiLineString(geom, owns_geom_obj));
1253  case wkbPolygon:
1254  return std::unique_ptr<GeoPolygon>(new GeoPolygon(geom, owns_geom_obj));
1255  case wkbMultiPolygon:
1256  return std::unique_ptr<GeoMultiPolygon>(new GeoMultiPolygon(geom, owns_geom_obj));
1257  case wkbGeometryCollection:
1258  return std::unique_ptr<GeoGeometryCollection>(
1259  new GeoGeometryCollection(geom, owns_geom_obj));
1260  default:
1261  throw GeoTypesError(
1262  "GeoTypesFactory",
1263  "Unrecognized geometry type: " + std::string(geom->getGeometryName()));
1264  }
1265 }

+ Here is the caller graph for this function:

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

Definition at line 1063 of file Types.cpp.

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

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

1065  {
1066  OGRGeometry* geom = nullptr;
1067  OGRErr err = OGRERR_NONE;
1068  if (wkt_or_wkb_hex.empty()) {
1069  err = OGRERR_NOT_ENOUGH_DATA;
1070  } else if (wkt_or_wkb_hex[0] == '0') { // all WKB hex strings start with a 0
1071  auto const wkb = hex_string_to_binary_vector(wkt_or_wkb_hex);
1072  err = GeoBase::createFromWkbView(&geom, {wkb.data(), wkb.size()});
1073  } else {
1074  err = GeoBase::createFromWktString(wkt_or_wkb_hex, &geom);
1075  }
1076  if (err != OGRERR_NONE) {
1077  throw GeoTypesError("GeoFactory", err);
1078  }
1079  if (validate_with_geos_if_available) {
1080  validate_ogr(geom);
1081  }
1082  return geom;
1083 }
void validate_ogr(const OGRGeometry *geom)
Definition: Types.cpp:1049
static int createFromWkbView(OGRGeometry **geom, WkbView const)
Definition: Types.cpp:174
static int createFromWktString(const std::string &wkt, OGRGeometry **geom)
Definition: Types.cpp:155
std::vector< uint8_t > hex_string_to_binary_vector(const std::string &wkb_hex)
Definition: Types.cpp:1030

+ 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  validate_with_geos_if_available 
)
static

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

1127  {
1128  try {
1129  if (wkt_or_wkb_hex.empty() || wkt_or_wkb_hex == "NULL") {
1130  getNullGeoColumns(ti, coords, bounds, ring_sizes, poly_rings);
1131  return true;
1132  }
1133 
1134  const auto geospatial_base =
1135  GeoTypesFactory::createGeoType(wkt_or_wkb_hex, validate_with_geos_if_available);
1136 
1137  if (!geospatial_base || !geospatial_base->transform(ti)) {
1138  return false;
1139  }
1140 
1141  getGeoColumnsImpl(geospatial_base, ti, coords, bounds, ring_sizes, poly_rings);
1142 
1143  } catch (const std::exception& e) {
1144  LOG(ERROR) << "Geospatial Import Error: " << e.what();
1145  return false;
1146  }
1147 
1148  return true;
1149 }
#define LOG(tag)
Definition: Logger.h:285
static void getNullGeoColumns(SQLTypeInfo &ti, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings)
Definition: Types.cpp:1342
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)
Definition: Types.cpp:1267
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex, const bool validate_with_geos_if_available)
Definition: Types.cpp:1085

+ 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  validate_with_geos_if_available 
)
static

Definition at line 1151 of file Types.cpp.

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

1157  {
1158  try {
1159  const auto geospatial_base = GeoTypesFactory::createGeoType(
1160  {wkb.data(), wkb.size()}, validate_with_geos_if_available);
1161 
1162  if (!geospatial_base || !geospatial_base->transform(ti)) {
1163  return false;
1164  }
1165 
1166  getGeoColumnsImpl(geospatial_base, ti, coords, bounds, ring_sizes, poly_rings);
1167 
1168  } catch (const std::exception& e) {
1169  LOG(ERROR) << "Geospatial Import Error: " << e.what();
1170  return false;
1171  }
1172 
1173  return true;
1174 }
#define LOG(tag)
Definition: Logger.h:285
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)
Definition: Types.cpp:1267
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex, const bool validate_with_geos_if_available)
Definition: Types.cpp:1085

+ 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  validate_with_geos_if_available 
)
static

Definition at line 1176 of file Types.cpp.

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

1182  {
1183  try {
1184  const auto geospatial_base =
1185  GeoTypesFactory::createGeoType(geom, validate_with_geos_if_available);
1186 
1187  if (!geospatial_base || !geospatial_base->transform(ti)) {
1188  return false;
1189  }
1190 
1191  getGeoColumnsImpl(geospatial_base, ti, coords, bounds, ring_sizes, poly_rings);
1192 
1193  } catch (const std::exception& e) {
1194  LOG(ERROR) << "Geospatial Import Error: " << e.what();
1195  return false;
1196  }
1197 
1198  return true;
1199 }
#define LOG(tag)
Definition: Logger.h:285
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)
Definition: Types.cpp:1267
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex, const bool validate_with_geos_if_available)
Definition: Types.cpp:1085

+ 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  validate_with_geos_if_available 
)
static

Definition at line 1201 of file Types.cpp.

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

1207  {
1208  try {
1209  for (const auto& wkt_or_wkb_hex : *wkt_or_wkb_hex_column) {
1210  std::vector<double> coords;
1211  std::vector<double> bounds;
1212  std::vector<int> ring_sizes;
1213  std::vector<int> poly_rings;
1214 
1215  SQLTypeInfo row_ti{ti};
1216  getGeoColumns(wkt_or_wkb_hex,
1217  row_ti,
1218  coords,
1219  bounds,
1220  ring_sizes,
1221  poly_rings,
1222  validate_with_geos_if_available);
1223 
1224  if (!geo_promoted_type_match(row_ti.get_type(), ti.get_type())) {
1225  throw GeoTypesError("GeoFactory", "Columnar: Geometry type mismatch");
1226  }
1227  coords_column.push_back(coords);
1228  bounds_column.push_back(bounds);
1229  ring_sizes_column.push_back(ring_sizes);
1230  poly_rings_column.push_back(poly_rings);
1231  }
1232 
1233  } catch (const std::exception& e) {
1234  LOG(ERROR) << "Geospatial column Import Error: " << e.what();
1235  return false;
1236  }
1237 
1238  return true;
1239 }
bool geo_promoted_type_match(const SQLTypes a, const SQLTypes b)
Definition: sqltypes.h:2031
#define LOG(tag)
Definition: Logger.h:285
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
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 validate_with_geos_if_available)
Definition: Types.cpp:1121

+ 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 
)
staticprivate

Definition at line 1267 of file Types.cpp.

References CHECK, CHECK_EQ, 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().

1272  {
1273  switch (geospatial_base->getType()) {
1274  case GeoBase::GeoType::kPOINT: {
1275  const auto geospatial_point = dynamic_cast<GeoPoint*>(geospatial_base.get());
1276  CHECK(geospatial_point);
1277  geospatial_point->getColumns(coords);
1278  ti.set_type(kPOINT);
1279  // in case of promotion to MULTIPOINT
1280  CHECK_EQ(coords.size(), 2u);
1281  bounds.reserve(4);
1282  bounds.push_back(coords[0]);
1283  bounds.push_back(coords[1]);
1284  bounds.push_back(coords[0]);
1285  bounds.push_back(coords[1]);
1286  break;
1287  }
1289  const auto geospatial_multipoint =
1290  dynamic_cast<GeoMultiPoint*>(geospatial_base.get());
1291  CHECK(geospatial_multipoint);
1292  geospatial_multipoint->getColumns(coords, bounds);
1293  ti.set_type(kMULTIPOINT);
1294  break;
1295  }
1297  const auto geospatial_linestring =
1298  dynamic_cast<GeoLineString*>(geospatial_base.get());
1299  CHECK(geospatial_linestring);
1300  geospatial_linestring->getColumns(coords, bounds);
1301  ti.set_type(kLINESTRING);
1302  // in case of promotion to MULTILINESTRING
1303  ring_sizes.push_back(coords.size() / 2);
1304  break;
1305  }
1307  const auto geospatial_multilinestring =
1308  dynamic_cast<GeoMultiLineString*>(geospatial_base.get());
1309  CHECK(geospatial_multilinestring);
1310  geospatial_multilinestring->getColumns(coords, ring_sizes, bounds);
1312  break;
1313  }
1315  const auto geospatial_poly = dynamic_cast<GeoPolygon*>(geospatial_base.get());
1316  CHECK(geospatial_poly);
1317  geospatial_poly->getColumns(coords, ring_sizes, bounds);
1318  ti.set_type(kPOLYGON);
1319  // in case of promotion to MULTIPOLYGON
1320  if (ring_sizes.size()) {
1321  CHECK_GT(coords.size(), 0u);
1322  poly_rings.push_back(1 + geospatial_poly->getNumInteriorRings());
1323  } else {
1324  poly_rings.push_back(0);
1325  }
1326  break;
1327  }
1329  const auto geospatial_mpoly = dynamic_cast<GeoMultiPolygon*>(geospatial_base.get());
1330  CHECK(geospatial_mpoly);
1331  geospatial_mpoly->getColumns(coords, ring_sizes, poly_rings, bounds);
1332  ti.set_type(kMULTIPOLYGON);
1333  break;
1334  }
1337  default:
1338  throw std::runtime_error("Unrecognized geospatial type");
1339  }
1340 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Simplified core of GeoJSON Polygon coordinates definition.
#define CHECK_GT(x, y)
Definition: Logger.h:305
Simplified core of GeoJSON MultiPolygon coordinates definition.
#define CHECK(condition)
Definition: Logger.h:291
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:470

+ 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 
)
static

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

1346  {
1347  auto t = ti.get_type();
1348  switch (t) {
1349  case kPOINT: {
1350  // NULL fixlen coords array
1351  coords.push_back(NULL_ARRAY_DOUBLE);
1352  coords.push_back(NULL_DOUBLE);
1353  } break;
1354  case kMULTIPOINT:
1355  case kLINESTRING:
1356  case kMULTILINESTRING:
1357  case kPOLYGON:
1358  case kMULTIPOLYGON: {
1359  // Leaving coords array empty
1360  // NULL fixlen bounds array
1361  bounds.push_back(NULL_ARRAY_DOUBLE);
1362  bounds.push_back(NULL_DOUBLE);
1363  bounds.push_back(NULL_DOUBLE);
1364  bounds.push_back(NULL_DOUBLE);
1365  // Leaving ring_sizes and poly_rings arrays empty
1366  } break;
1367  default:
1368  throw std::runtime_error("Unsupported NULL geo");
1369  }
1370 }
#define NULL_DOUBLE
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
#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: