OmniSciDB  8a228a1076
Geo_namespace::GeoMultiPolygon Class Reference

#include <geo_types.h>

+ Inheritance diagram for Geo_namespace::GeoMultiPolygon:
+ Collaboration diagram for Geo_namespace::GeoMultiPolygon:

Public Member Functions

 GeoMultiPolygon (const std::vector< double > &coords, const std::vector< int32_t > &ring_sizes, const std::vector< int32_t > &poly_rings)
 
 GeoMultiPolygon (const std::string &wkt)
 
void getColumns (std::vector< double > &coords, std::vector< int32_t > &ring_sizes, std::vector< int32_t > &poly_rings, std::vector< double > &bounds) const
 
GeoType getType () const final
 
- Public Member Functions inherited from Geo_namespace::GeoBase
 GeoBase ()
 
virtual ~GeoBase ()
 
std::string getWktString () const
 
bool getWkb (std::vector< uint8_t > &) const
 
const OGRGeometry * getOGRGeometry () const
 
virtual bool operator== (const GeoBase &other) const
 
bool isEmpty () const
 
std::unique_ptr< GeoBaserun (GeoOp op, const GeoBase &other) const
 
std::unique_ptr< GeoBaseoptimized_run (GeoOp op, const GeoBase &other) const
 
std::unique_ptr< GeoBaserun (GeoOp op, double param) const
 
bool run (GeoOp op) const
 

Protected Member Functions

 GeoMultiPolygon (OGRGeometry *geom, const bool owns_geom_obj)
 
- Protected Member Functions inherited from Geo_namespace::GeoBase
 GeoBase (OGRGeometry *geom, const bool owns_geom_obj)
 

Friends

class GeoTypesFactory
 

Additional Inherited Members

- Public Types inherited from Geo_namespace::GeoBase
enum  GeoType {
  GeoType::kPOINT, GeoType::kLINESTRING, GeoType::kPOLYGON, GeoType::kMULTIPOLYGON,
  GeoType::kGEOMETRY, GeoType::kGEOMETRYCOLLECTION
}
 
enum  GeoOp {
  GeoOp::kPROJECTION = 0, GeoOp::kINTERSECTION = 1, GeoOp::kDIFFERENCE = 2, GeoOp::kUNION = 3,
  GeoOp::kBUFFER = 4, GeoOp::kISVALID = 5, GeoOp::kISEMPTY = 6
}
 
- Static Protected Member Functions inherited from Geo_namespace::GeoBase
static int createFromWktString (const std::string &wkt, OGRGeometry **geom)
 
static int createFromWkb (const std::vector< uint8_t > &wkb, OGRGeometry **geom)
 
- Protected Attributes inherited from Geo_namespace::GeoBase
OGRGeometry * geom_ = nullptr
 
bool owns_geom_obj_
 

Detailed Description

Definition at line 141 of file geo_types.h.

Constructor & Destructor Documentation

◆ GeoMultiPolygon() [1/3]

GeoMultiPolygon::GeoMultiPolygon ( const std::vector< double > &  coords,
const std::vector< int32_t > &  ring_sizes,
const std::vector< int32_t > &  poly_rings 
)

Definition at line 509 of file geo_types.cpp.

References CHECK.

511  {
512  geom_ = OGRGeometryFactory::createGeometry(OGRwkbGeometryType::wkbMultiPolygon);
513  OGRMultiPolygon* multipoly = dynamic_cast<OGRMultiPolygon*>(geom_);
514  CHECK(multipoly);
515 
516  size_t ring_ctr = 0;
517  size_t coords_ctr = 0;
518  for (const auto& rings_in_poly : poly_rings) {
519  OGRPolygon poly;
520  for (auto r = 0; r < rings_in_poly; r++) {
521  OGRLinearRing ring;
522  const auto ring_sz = ring_sizes[ring_ctr];
523  for (auto i = 0; i < 2 * ring_sz; i += 2) {
524  ring.addPoint(coords[coords_ctr + i], coords[coords_ctr + i + 1]);
525  }
526  ring.addPoint(coords[coords_ctr], coords[coords_ctr + 1]);
527  coords_ctr += 2 * ring_sz;
528  poly.addRing(&ring);
529  ring_ctr++;
530  }
531  multipoly->addGeometry(&poly);
532  }
533 }
OGRGeometry * geom_
Definition: geo_types.h:84
#define CHECK(condition)
Definition: Logger.h:197

◆ GeoMultiPolygon() [2/3]

GeoMultiPolygon::GeoMultiPolygon ( const std::string &  wkt)

Definition at line 535 of file geo_types.cpp.

References CHECK.

535  {
536  const auto err = GeoBase::createFromWktString(wkt, &geom_);
537  if (err != OGRERR_NONE) {
538  throw GeoTypesError("MultiPolygon", err);
539  }
540  CHECK(geom_);
541  if (wkbFlatten(geom_->getGeometryType()) != OGRwkbGeometryType::wkbMultiPolygon) {
542  throw GeoTypesError("MultiPolygon",
543  "Unexpected geometry type from WKT string: " +
544  std::string(OGRGeometryTypeToName(geom_->getGeometryType())));
545  }
546 }
static int createFromWktString(const std::string &wkt, OGRGeometry **geom)
Definition: geo_types.cpp:147
OGRGeometry * geom_
Definition: geo_types.h:84
#define CHECK(condition)
Definition: Logger.h:197

◆ GeoMultiPolygon() [3/3]

Geo_namespace::GeoMultiPolygon::GeoMultiPolygon ( OGRGeometry *  geom,
const bool  owns_geom_obj 
)
inlineprotected

Definition at line 155 of file geo_types.h.

156  : GeoBase(geom, owns_geom_obj) {}

Member Function Documentation

◆ getColumns()

void GeoMultiPolygon::getColumns ( std::vector< double > &  coords,
std::vector< int32_t > &  ring_sizes,
std::vector< int32_t > &  poly_rings,
std::vector< double > &  bounds 
) const

Definition at line 548 of file geo_types.cpp.

References CHECK, NULL_DOUBLE, and anonymous_namespace{geo_types.cpp}::process_poly_ring().

551  {
552  const auto mpoly = dynamic_cast<OGRMultiPolygon*>(geom_);
553  CHECK(mpoly);
554 
555  if (mpoly->IsEmpty()) {
556  // until the run-time can handle empties
557  throw GeoTypesError("MultiPolygon", "'EMPTY' not supported");
558  // return null bounds
559  bounds.push_back(NULL_DOUBLE);
560  bounds.push_back(NULL_DOUBLE);
561  bounds.push_back(NULL_DOUBLE);
562  bounds.push_back(NULL_DOUBLE);
563  return;
564  }
565 
566  BoundingBox bbox;
567  for (auto p = 0; p < mpoly->getNumGeometries(); p++) {
568  const auto mpoly_geom = mpoly->getGeometryRef(p);
569  CHECK(mpoly_geom);
570  const auto poly_geom = dynamic_cast<OGRPolygon*>(mpoly_geom);
571  if (!poly_geom) {
572  throw GeoTypesError("MultiPolygon",
573  "Failed to read polygon geometry from multipolygon");
574  }
575  const auto exterior_ring = poly_geom->getExteriorRing();
576  CHECK(exterior_ring);
577  // All exterior rings are imported CCW
578  if (exterior_ring->isClockwise()) {
579  exterior_ring->reverseWindingOrder();
580  }
581  const auto num_points_added = process_poly_ring(exterior_ring, coords, &bbox);
582  ring_sizes.push_back(num_points_added);
583 
584  for (auto r = 0; r < poly_geom->getNumInteriorRings(); r++) {
585  auto interior_ring = poly_geom->getInteriorRing(r);
586  CHECK(interior_ring);
587  // All interior rings are imported CW
588  if (!interior_ring->isClockwise()) {
589  interior_ring->reverseWindingOrder();
590  }
591  const auto num_points_added = process_poly_ring(interior_ring, coords, nullptr);
592  ring_sizes.push_back(num_points_added);
593  }
594  poly_rings.push_back(poly_geom->getNumInteriorRings() + 1);
595  }
596  bounds.push_back(bbox.min.x);
597  bounds.push_back(bbox.min.y);
598  bounds.push_back(bbox.max.x);
599  bounds.push_back(bbox.max.y);
600 }
#define NULL_DOUBLE
Definition: sqltypes.h:186
OGRGeometry * geom_
Definition: geo_types.h:84
#define CHECK(condition)
Definition: Logger.h:197
int process_poly_ring(OGRLinearRing *ring, std::vector< double > &coords, BoundingBox *bbox)
Definition: geo_types.cpp:67
+ Here is the call graph for this function:

◆ getType()

GeoType Geo_namespace::GeoMultiPolygon::getType ( ) const
inlinefinalvirtual

Friends And Related Function Documentation

◆ GeoTypesFactory

friend class GeoTypesFactory
friend

Definition at line 158 of file geo_types.h.


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