OmniSciDB  2e3a973ef4
Geospatial::GeoMultiPolygon Class Reference

#include <Types.h>

+ Inheritance diagram for Geospatial::GeoMultiPolygon:
+ Collaboration diagram for Geospatial::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 Geospatial::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 Geospatial::GeoBase
 GeoBase (OGRGeometry *geom, const bool owns_geom_obj)
 

Friends

class GeoTypesFactory
 

Additional Inherited Members

- Public Types inherited from Geospatial::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 Geospatial::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 Geospatial::GeoBase
OGRGeometry * geom_ = nullptr
 
bool owns_geom_obj_
 

Detailed Description

Definition at line 140 of file 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 510 of file Types.cpp.

References CHECK.

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

◆ GeoMultiPolygon() [2/3]

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

Definition at line 536 of file Types.cpp.

References CHECK.

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

◆ GeoMultiPolygon() [3/3]

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

Definition at line 154 of file Types.h.

155  : 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 549 of file Types.cpp.

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

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

◆ getType()

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

Implements Geospatial::GeoBase.

Definition at line 151 of file Types.h.

References kMULTIPOLYGON.

Friends And Related Function Documentation

◆ GeoTypesFactory

friend class GeoTypesFactory
friend

Definition at line 157 of file Types.h.


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