OmniSciDB  04ee39c94c
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 (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 (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 Private Member Functions

static std::unique_ptr< Geo_namespace::GeoBasecreateGeoTypeImpl (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 135 of file geo_types.h.

Member Function Documentation

◆ createGeoType() [1/2]

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

Definition at line 446 of file geo_types.cpp.

446  {
447  OGRGeometry* geom = nullptr;
448  const auto err = GeoBase::createFromWktString(wkt, &geom);
449  if (err != OGRERR_NONE) {
450  throw GeoTypesError("GeoFactory", err);
451  }
453 }
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:554

◆ createGeoType() [2/2]

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

Definition at line 455 of file geo_types.cpp.

455  {
456  return GeoTypesFactory::createGeoTypeImpl(geom, false);
457 }
static std::unique_ptr< Geo_namespace::GeoBase > createGeoTypeImpl(OGRGeometry *geom, const bool owns_geom_obj=true)
Definition: geo_types.cpp:554

◆ createGeoTypeImpl()

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

Definition at line 554 of file geo_types.cpp.

555  {
556  switch (wkbFlatten(geom->getGeometryType())) {
557  case wkbPoint:
558  return std::unique_ptr<GeoPoint>(new GeoPoint(geom, owns_geom_obj));
559  case wkbLineString:
560  return std::unique_ptr<GeoLineString>(new GeoLineString(geom, owns_geom_obj));
561  case wkbPolygon:
562  return std::unique_ptr<GeoPolygon>(new GeoPolygon(geom, owns_geom_obj));
563  case wkbMultiPolygon:
564  return std::unique_ptr<GeoMultiPolygon>(new GeoMultiPolygon(geom, owns_geom_obj));
565  default:
566  throw GeoTypesError(
567  "GeoTypesFactory",
568  "Unrecognized geometry type: " + std::string(geom->getGeometryName()));
569  }
570 }

◆ getGeoColumns() [1/3]

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 459 of file geo_types.cpp.

References logger::ERROR, LOG, SQLTypeInfoCore< TYPE_FACET_PACK >::set_input_srid(), and SQLTypeInfoCore< TYPE_FACET_PACK >::set_output_srid().

Referenced by Parser::InsertValuesStmt::analyze(), Importer_NS::TypedImportBuffer::convert_arrow_val_to_import_buffer(), Parser::AddColumnStmt::execute(), Importer_NS::import_thread_delimited(), Importer_NS::import_thread_shapefile(), MapDHandler::load_table(), MapDHandler::load_table_binary_columnar(), and RelAlgTranslator::translateGeoLiteral().

465  {
466  try {
467  const auto geospatial_base = GeoTypesFactory::createGeoType(wkt);
468 
469  int srid = 0;
470  ti.set_input_srid(srid);
471  ti.set_output_srid(srid);
472 
473  getGeoColumnsImpl(geospatial_base,
474  ti,
475  coords,
476  bounds,
477  ring_sizes,
478  poly_rings,
479  promote_poly_to_mpoly);
480 
481  } catch (const std::exception& e) {
482  LOG(ERROR) << "Geospatial Import Error: " << e.what();
483  return false;
484  }
485 
486  return true;
487 }
#define LOG(tag)
Definition: Logger.h:182
void set_input_srid(int d)
Definition: sqltypes.h:417
void set_output_srid(int s)
Definition: sqltypes.h:419
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:572
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt)
Definition: geo_types.cpp:446
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGeoColumns() [2/3]

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 489 of file geo_types.cpp.

References logger::ERROR, LOG, SQLTypeInfoCore< TYPE_FACET_PACK >::set_input_srid(), and SQLTypeInfoCore< TYPE_FACET_PACK >::set_output_srid().

495  {
496  try {
497  const auto geospatial_base = GeoTypesFactory::createGeoType(geom);
498 
499  int srid = 0;
500  ti.set_input_srid(srid);
501  ti.set_output_srid(srid);
502 
503  getGeoColumnsImpl(geospatial_base,
504  ti,
505  coords,
506  bounds,
507  ring_sizes,
508  poly_rings,
509  promote_poly_to_mpoly);
510 
511  } catch (const std::exception& e) {
512  LOG(ERROR) << "Geospatial Import Error: " << e.what();
513  return false;
514  }
515 
516  return true;
517 }
#define LOG(tag)
Definition: Logger.h:182
void set_input_srid(int d)
Definition: sqltypes.h:417
void set_output_srid(int s)
Definition: sqltypes.h:419
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:572
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt)
Definition: geo_types.cpp:446
+ Here is the call graph for this function:

◆ getGeoColumns() [3/3]

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 519 of file geo_types.cpp.

References logger::ERROR, SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), and LOG.

525  {
526  try {
527  for (const auto wkt : *wkt_column) {
528  std::vector<double> coords;
529  std::vector<double> bounds;
530  std::vector<int> ring_sizes;
531  std::vector<int> poly_rings;
532 
533  SQLTypeInfo row_ti;
535  wkt, row_ti, coords, bounds, ring_sizes, poly_rings, promote_poly_to_mpoly);
536 
537  if (ti.get_type() != row_ti.get_type()) {
538  throw GeoTypesError("GeoFactory", "Columnar: Geometry type mismatch");
539  }
540  coords_column.push_back(coords);
541  bounds_column.push_back(bounds);
542  ring_sizes_column.push_back(ring_sizes);
543  poly_rings_column.push_back(poly_rings);
544  }
545 
546  } catch (const std::exception& e) {
547  LOG(ERROR) << "Geospatial column Import Error: " << e.what();
548  return false;
549  }
550 
551  return true;
552 }
#define LOG(tag)
Definition: Logger.h:182
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
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:459
+ Here is the call graph for this function:

◆ getGeoColumnsImpl()

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 572 of file geo_types.cpp.

References CHECK, CHECK_GT, kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, and SQLTypeInfoCore< TYPE_FACET_PACK >::set_type().

578  {
579  switch (geospatial_base->getType()) {
581  const auto geospatial_point = dynamic_cast<GeoPoint*>(geospatial_base.get());
582  CHECK(geospatial_point);
583  geospatial_point->getColumns(coords);
584  ti.set_type(kPOINT);
585  break;
586  }
588  const auto geospatial_linestring =
589  dynamic_cast<GeoLineString*>(geospatial_base.get());
590  CHECK(geospatial_linestring);
591  geospatial_linestring->getColumns(coords, bounds);
592  ti.set_type(kLINESTRING);
593  break;
594  }
596  const auto geospatial_poly = dynamic_cast<GeoPolygon*>(geospatial_base.get());
597  CHECK(geospatial_poly);
598  geospatial_poly->getColumns(coords, ring_sizes, bounds);
599  if (promote_poly_to_mpoly) {
600  if (ring_sizes.size()) {
601  CHECK_GT(coords.size(), 0u);
602  poly_rings.push_back(1 + geospatial_poly->getNumInteriorRings());
603  }
604  }
605  ti.set_type(kPOLYGON);
606  break;
607  }
609  const auto geospatial_mpoly = dynamic_cast<GeoMultiPolygon*>(geospatial_base.get());
610  CHECK(geospatial_mpoly);
611  geospatial_mpoly->getColumns(coords, ring_sizes, poly_rings, bounds);
613  break;
614  }
615  default:
616  throw std::runtime_error("Unrecognized geospatial type");
617  }
618 }
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:413
#define CHECK_GT(x, y)
Definition: Logger.h:199
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

The documentation for this class was generated from the following files: