OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Geo_namespace::GeoTypesFactory Class Reference

#include <geo_types.h>

Static Public Member Functions

static std::unique_ptr< GeoBasecreateGeoType (const std::string &wkt)
 
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, 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_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
< Geo_namespace::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 213 of file geo_types.h.

Member Function Documentation

std::unique_ptr< GeoBase > Geo_namespace::GeoTypesFactory::createGeoType ( const std::string &  wkt)
static

Definition at line 615 of file geo_types.cpp.

References Geo_namespace::GeoBase::createFromWktString(), and createGeoTypeImpl().

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

615  {
616  OGRGeometry* geom = nullptr;
617  const auto err = GeoBase::createFromWktString(wkt, &geom);
618  if (err != OGRERR_NONE) {
619  throw GeoTypesError("GeoFactory", err);
620  }
622 }
static int createFromWktString(const std::string &wkt, OGRGeometry **geom)
Definition: geo_types.cpp:147
static std::unique_ptr< Geo_namespace::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: geo_types.cpp:768

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unique_ptr< GeoBase > Geo_namespace::GeoTypesFactory::createGeoType ( const std::vector< uint8_t > &  wkb)
static

Definition at line 624 of file geo_types.cpp.

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

624  {
625  OGRGeometry* geom = nullptr;
626  const auto err = GeoBase::createFromWkb(wkb, &geom);
627  if (err != OGRERR_NONE) {
628  throw GeoTypesError("GeoFactory", err);
629  }
631 }
static std::unique_ptr< Geo_namespace::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: geo_types.cpp:768
static int createFromWkb(const std::vector< uint8_t > &wkb, OGRGeometry **geom)
Definition: geo_types.cpp:166

+ Here is the call graph for this function:

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

Definition at line 633 of file geo_types.cpp.

References createGeoTypeImpl().

633  {
634  return GeoTypesFactory::createGeoTypeImpl(geom, false);
635 }
static std::unique_ptr< Geo_namespace::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: geo_types.cpp:768

+ Here is the call graph for this function:

std::unique_ptr< GeoBase > Geo_namespace::GeoTypesFactory::createGeoTypeImpl ( OGRGeometry *  geom,
const bool  owns_geom_obj = true 
)
staticprivate

Definition at line 768 of file geo_types.cpp.

Referenced by createGeoType().

769  {
770  switch (wkbFlatten(geom->getGeometryType())) {
771  case wkbPoint:
772  return std::unique_ptr<GeoPoint>(new GeoPoint(geom, owns_geom_obj));
773  case wkbLineString:
774  return std::unique_ptr<GeoLineString>(new GeoLineString(geom, owns_geom_obj));
775  case wkbPolygon:
776  return std::unique_ptr<GeoPolygon>(new GeoPolygon(geom, owns_geom_obj));
777  case wkbMultiPolygon:
778  return std::unique_ptr<GeoMultiPolygon>(new GeoMultiPolygon(geom, owns_geom_obj));
779  case wkbGeometryCollection:
780  return std::unique_ptr<GeoGeometryCollection>(
781  new GeoGeometryCollection(geom, owns_geom_obj));
782  default:
783  throw GeoTypesError(
784  "GeoTypesFactory",
785  "Unrecognized geometry type: " + std::string(geom->getGeometryName()));
786  }
787 }

+ Here is the caller graph for this function:

bool Geo_namespace::GeoTypesFactory::getGeoColumns ( const std::string &  wkt,
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 637 of file geo_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(), and RelAlgTranslator::translateGeoLiteral().

643  {
644  try {
645  if (wkt.empty() || wkt == "NULL") {
647  ti, coords, bounds, ring_sizes, poly_rings, promote_poly_to_mpoly);
648  return true;
649  }
650 
651  const auto geospatial_base = GeoTypesFactory::createGeoType(wkt);
652 
653  int srid = 0;
654  ti.set_input_srid(srid);
655  ti.set_output_srid(srid);
656 
657  getGeoColumnsImpl(geospatial_base,
658  ti,
659  coords,
660  bounds,
661  ring_sizes,
662  poly_rings,
663  promote_poly_to_mpoly);
664 
665  } catch (const std::exception& e) {
666  LOG(ERROR) << "Geospatial Import Error: " << e.what();
667  return false;
668  }
669 
670  return true;
671 }
#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: geo_types.cpp:789
void set_input_srid(int d)
Definition: sqltypes.h:352
void set_output_srid(int s)
Definition: sqltypes.h:354
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: geo_types.cpp:839
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt)
Definition: geo_types.cpp:615

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Geo_namespace::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 673 of file geo_types.cpp.

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

679  {
680  try {
681  const auto geospatial_base = GeoTypesFactory::createGeoType(wkb);
682 
683  int srid = 0;
684  ti.set_input_srid(srid);
685  ti.set_output_srid(srid);
686 
687  getGeoColumnsImpl(geospatial_base,
688  ti,
689  coords,
690  bounds,
691  ring_sizes,
692  poly_rings,
693  promote_poly_to_mpoly);
694 
695  } catch (const std::exception& e) {
696  LOG(ERROR) << "Geospatial Import Error: " << e.what();
697  return false;
698  }
699 
700  return true;
701 }
#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: geo_types.cpp:789
void set_input_srid(int d)
Definition: sqltypes.h:352
void set_output_srid(int s)
Definition: sqltypes.h:354
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt)
Definition: geo_types.cpp:615

+ Here is the call graph for this function:

bool Geo_namespace::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 703 of file geo_types.cpp.

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

709  {
710  try {
711  const auto geospatial_base = GeoTypesFactory::createGeoType(geom);
712 
713  int srid = 0;
714  ti.set_input_srid(srid);
715  ti.set_output_srid(srid);
716 
717  getGeoColumnsImpl(geospatial_base,
718  ti,
719  coords,
720  bounds,
721  ring_sizes,
722  poly_rings,
723  promote_poly_to_mpoly);
724 
725  } catch (const std::exception& e) {
726  LOG(ERROR) << "Geospatial Import Error: " << e.what();
727  return false;
728  }
729 
730  return true;
731 }
#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: geo_types.cpp:789
void set_input_srid(int d)
Definition: sqltypes.h:352
void set_output_srid(int s)
Definition: sqltypes.h:354
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt)
Definition: geo_types.cpp:615

+ Here is the call graph for this function:

bool Geo_namespace::GeoTypesFactory::getGeoColumns ( const std::vector< std::string > *  wkt_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 733 of file geo_types.cpp.

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

739  {
740  try {
741  for (const auto& wkt : *wkt_column) {
742  std::vector<double> coords;
743  std::vector<double> bounds;
744  std::vector<int> ring_sizes;
745  std::vector<int> poly_rings;
746 
747  SQLTypeInfo row_ti;
749  wkt, row_ti, coords, bounds, ring_sizes, poly_rings, promote_poly_to_mpoly);
750 
751  if (ti.get_type() != row_ti.get_type()) {
752  throw GeoTypesError("GeoFactory", "Columnar: Geometry type mismatch");
753  }
754  coords_column.push_back(coords);
755  bounds_column.push_back(bounds);
756  ring_sizes_column.push_back(ring_sizes);
757  poly_rings_column.push_back(poly_rings);
758  }
759 
760  } catch (const std::exception& e) {
761  LOG(ERROR) << "Geospatial column Import Error: " << e.what();
762  return false;
763  }
764 
765  return true;
766 }
#define LOG(tag)
Definition: Logger.h:188
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
static bool getGeoColumns(const std::string &wkt, 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: geo_types.cpp:637

+ Here is the call graph for this function:

void Geo_namespace::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 789 of file geo_types.cpp.

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

Referenced by getGeoColumns().

795  {
796  switch (geospatial_base->getType()) {
798  const auto geospatial_point = dynamic_cast<GeoPoint*>(geospatial_base.get());
799  CHECK(geospatial_point);
800  geospatial_point->getColumns(coords);
801  ti.set_type(kPOINT);
802  break;
803  }
805  const auto geospatial_linestring =
806  dynamic_cast<GeoLineString*>(geospatial_base.get());
807  CHECK(geospatial_linestring);
808  geospatial_linestring->getColumns(coords, bounds);
809  ti.set_type(kLINESTRING);
810  break;
811  }
813  const auto geospatial_poly = dynamic_cast<GeoPolygon*>(geospatial_base.get());
814  CHECK(geospatial_poly);
815  geospatial_poly->getColumns(coords, ring_sizes, bounds);
816  if (promote_poly_to_mpoly) {
817  if (ring_sizes.size()) {
818  CHECK_GT(coords.size(), 0u);
819  poly_rings.push_back(1 + geospatial_poly->getNumInteriorRings());
820  }
821  }
822  ti.set_type(kPOLYGON);
823  break;
824  }
826  const auto geospatial_mpoly = dynamic_cast<GeoMultiPolygon*>(geospatial_base.get());
827  CHECK(geospatial_mpoly);
828  geospatial_mpoly->getColumns(coords, ring_sizes, poly_rings, bounds);
830  break;
831  }
834  default:
835  throw std::runtime_error("Unrecognized geospatial type");
836  }
837 }
#define CHECK_GT(x, y)
Definition: Logger.h:209
CHECK(cgen_state)
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:348

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Geo_namespace::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 839 of file geo_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(), and foreign_storage::csv_file_buffer_parser::process_geo_column().

844  {
845  auto t = ti.get_type();
846  switch (t) {
847  case kPOINT: {
848  // NULL fixlen coords array
849  coords.push_back(NULL_ARRAY_DOUBLE);
850  coords.push_back(NULL_DOUBLE);
851  } break;
852  case kLINESTRING:
853  case kPOLYGON:
854  case kMULTIPOLYGON: {
855  // Leaving coords array empty
856  // NULL fixlen bounds array
857  bounds.push_back(NULL_ARRAY_DOUBLE);
858  bounds.push_back(NULL_DOUBLE);
859  bounds.push_back(NULL_DOUBLE);
860  bounds.push_back(NULL_DOUBLE);
861  // Leaving ring_sizes and poly_rings arrays empty
862  } break;
863  default:
864  throw std::runtime_error("Unsupported NULL geo");
865  }
866 }
#define NULL_DOUBLE
Definition: sqltypes.h:185
#define NULL_ARRAY_DOUBLE
Definition: sqltypes.h:193
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258

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