OmniSciDB  95562058bd
 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 215 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 846 of file Types.cpp.

References createGeoTypeImpl(), and createOGRGeometry().

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

847  {
849 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1000
static OGRGeometry * createOGRGeometry(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:830

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

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

851  {
852  OGRGeometry* geom = nullptr;
853  const auto err = GeoBase::createFromWkb(wkb, &geom);
854  if (err != OGRERR_NONE) {
855  throw GeoTypesError("GeoFactory", err);
856  }
858 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1000
static int createFromWkb(const std::vector< uint8_t > &wkb, OGRGeometry **geom)
Definition: Types.cpp:167

+ Here is the call graph for this function:

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

Definition at line 860 of file Types.cpp.

References createGeoTypeImpl().

860  {
861  return GeoTypesFactory::createGeoTypeImpl(geom, false);
862 }
static std::unique_ptr< Geospatial::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: Types.cpp:1000

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

Referenced by createGeoType().

1001  {
1002  switch (wkbFlatten(geom->getGeometryType())) {
1003  case wkbPoint:
1004  return std::unique_ptr<GeoPoint>(new GeoPoint(geom, owns_geom_obj));
1005  case wkbLineString:
1006  return std::unique_ptr<GeoLineString>(new GeoLineString(geom, owns_geom_obj));
1007  case wkbPolygon:
1008  return std::unique_ptr<GeoPolygon>(new GeoPolygon(geom, owns_geom_obj));
1009  case wkbMultiPolygon:
1010  return std::unique_ptr<GeoMultiPolygon>(new GeoMultiPolygon(geom, owns_geom_obj));
1011  case wkbGeometryCollection:
1012  return std::unique_ptr<GeoGeometryCollection>(
1013  new GeoGeometryCollection(geom, owns_geom_obj));
1014  default:
1015  throw GeoTypesError(
1016  "GeoTypesFactory",
1017  "Unrecognized geometry type: " + std::string(geom->getGeometryName()));
1018  }
1019 }

+ Here is the caller graph for this function:

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

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

830  {
831  OGRGeometry* geom = nullptr;
832  OGRErr err = OGRERR_NONE;
833  if (wkt_or_wkb_hex.empty()) {
834  err = OGRERR_NOT_ENOUGH_DATA;
835  } else if (wkt_or_wkb_hex[0] == '0') { // all WKB hex strings start with a 0
836  err = GeoBase::createFromWkb(hex_string_to_binary_vector(wkt_or_wkb_hex), &geom);
837  } else {
838  err = GeoBase::createFromWktString(wkt_or_wkb_hex, &geom);
839  }
840  if (err != OGRERR_NONE) {
841  throw GeoTypesError("GeoFactory", err);
842  }
843  return geom;
844 }
static int createFromWkb(const std::vector< uint8_t > &wkb, OGRGeometry **geom)
Definition: Types.cpp:167
static int createFromWktString(const std::string &wkt, OGRGeometry **geom)
Definition: Types.cpp:148
std::vector< uint8_t > hex_string_to_binary_vector(const std::string &wkb_hex)
Definition: Types.cpp:815

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

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

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

870  {
871  try {
872  if (wkt_or_wkb_hex.empty() || wkt_or_wkb_hex == "NULL") {
874  ti, coords, bounds, ring_sizes, poly_rings, promote_poly_to_mpoly);
875  return true;
876  }
877 
878  const auto geospatial_base = GeoTypesFactory::createGeoType(wkt_or_wkb_hex);
879 
880  int srid = 0;
881  ti.set_input_srid(srid);
882  ti.set_output_srid(srid);
883 
884  getGeoColumnsImpl(geospatial_base,
885  ti,
886  coords,
887  bounds,
888  ring_sizes,
889  poly_rings,
890  promote_poly_to_mpoly);
891 
892  } catch (const std::exception& e) {
893  LOG(ERROR) << "Geospatial Import Error: " << e.what();
894  return false;
895  }
896 
897  return true;
898 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:846
#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:1021
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:1071
void set_input_srid(int d)
Definition: sqltypes.h:353
void set_output_srid(int s)
Definition: sqltypes.h:355

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

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

906  {
907  try {
908  const auto geospatial_base = GeoTypesFactory::createGeoType(wkb);
909 
910  int srid = 0;
911  ti.set_input_srid(srid);
912  ti.set_output_srid(srid);
913 
914  getGeoColumnsImpl(geospatial_base,
915  ti,
916  coords,
917  bounds,
918  ring_sizes,
919  poly_rings,
920  promote_poly_to_mpoly);
921 
922  } catch (const std::exception& e) {
923  LOG(ERROR) << "Geospatial Import Error: " << e.what();
924  return false;
925  }
926 
927  return true;
928 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:846
#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:1021
void set_input_srid(int d)
Definition: sqltypes.h:353
void set_output_srid(int s)
Definition: sqltypes.h:355

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

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

936  {
937  try {
938  const auto geospatial_base = GeoTypesFactory::createGeoType(geom);
939 
940  int srid = 0;
941  ti.set_input_srid(srid);
942  ti.set_output_srid(srid);
943 
944  getGeoColumnsImpl(geospatial_base,
945  ti,
946  coords,
947  bounds,
948  ring_sizes,
949  poly_rings,
950  promote_poly_to_mpoly);
951 
952  } catch (const std::exception& e) {
953  LOG(ERROR) << "Geospatial Import Error: " << e.what();
954  return false;
955  }
956 
957  return true;
958 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:846
#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:1021
void set_input_srid(int d)
Definition: sqltypes.h:353
void set_output_srid(int s)
Definition: sqltypes.h:355

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

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

966  {
967  try {
968  for (const auto& wkt_or_wkb_hex : *wkt_or_wkb_hex_column) {
969  std::vector<double> coords;
970  std::vector<double> bounds;
971  std::vector<int> ring_sizes;
972  std::vector<int> poly_rings;
973 
974  SQLTypeInfo row_ti;
975  getGeoColumns(wkt_or_wkb_hex,
976  row_ti,
977  coords,
978  bounds,
979  ring_sizes,
980  poly_rings,
981  promote_poly_to_mpoly);
982 
983  if (ti.get_type() != row_ti.get_type()) {
984  throw GeoTypesError("GeoFactory", "Columnar: Geometry type mismatch");
985  }
986  coords_column.push_back(coords);
987  bounds_column.push_back(bounds);
988  ring_sizes_column.push_back(ring_sizes);
989  poly_rings_column.push_back(poly_rings);
990  }
991 
992  } catch (const std::exception& e) {
993  LOG(ERROR) << "Geospatial column Import Error: " << e.what();
994  return false;
995  }
996 
997  return true;
998 }
#define LOG(tag)
Definition: Logger.h:188
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
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:864

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

1027  {
1028  switch (geospatial_base->getType()) {
1029  case GeoBase::GeoType::kPOINT: {
1030  const auto geospatial_point = dynamic_cast<GeoPoint*>(geospatial_base.get());
1031  CHECK(geospatial_point);
1032  geospatial_point->getColumns(coords);
1033  ti.set_type(kPOINT);
1034  break;
1035  }
1037  const auto geospatial_linestring =
1038  dynamic_cast<GeoLineString*>(geospatial_base.get());
1039  CHECK(geospatial_linestring);
1040  geospatial_linestring->getColumns(coords, bounds);
1041  ti.set_type(kLINESTRING);
1042  break;
1043  }
1045  const auto geospatial_poly = dynamic_cast<GeoPolygon*>(geospatial_base.get());
1046  CHECK(geospatial_poly);
1047  geospatial_poly->getColumns(coords, ring_sizes, bounds);
1048  if (promote_poly_to_mpoly) {
1049  if (ring_sizes.size()) {
1050  CHECK_GT(coords.size(), 0u);
1051  poly_rings.push_back(1 + geospatial_poly->getNumInteriorRings());
1052  }
1053  }
1054  ti.set_type(kPOLYGON);
1055  break;
1056  }
1058  const auto geospatial_mpoly = dynamic_cast<GeoMultiPolygon*>(geospatial_base.get());
1059  CHECK(geospatial_mpoly);
1060  geospatial_mpoly->getColumns(coords, ring_sizes, poly_rings, bounds);
1061  ti.set_type(kMULTIPOLYGON);
1062  break;
1063  }
1066  default:
1067  throw std::runtime_error("Unrecognized geospatial type");
1068  }
1069 }
#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:349

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

1076  {
1077  auto t = ti.get_type();
1078  switch (t) {
1079  case kPOINT: {
1080  // NULL fixlen coords array
1081  coords.push_back(NULL_ARRAY_DOUBLE);
1082  coords.push_back(NULL_DOUBLE);
1083  } break;
1084  case kLINESTRING:
1085  case kPOLYGON:
1086  case kMULTIPOLYGON: {
1087  // Leaving coords array empty
1088  // NULL fixlen bounds array
1089  bounds.push_back(NULL_ARRAY_DOUBLE);
1090  bounds.push_back(NULL_DOUBLE);
1091  bounds.push_back(NULL_DOUBLE);
1092  bounds.push_back(NULL_DOUBLE);
1093  // Leaving ring_sizes and poly_rings arrays empty
1094  } break;
1095  default:
1096  throw std::runtime_error("Unsupported NULL geo");
1097  }
1098 }
#define NULL_DOUBLE
Definition: sqltypes.h:186
#define NULL_ARRAY_DOUBLE
Definition: sqltypes.h:194
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259

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