OmniSciDB  c07336695a
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
 
virtual bool operator== (const GeoBase &other) 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 }
 
- Static Protected Member Functions inherited from Geo_namespace::GeoBase
static int createFromWktString (const std::string &wkt, OGRGeometry **geom)
 
- Protected Attributes inherited from Geo_namespace::GeoBase
OGRGeometry * geom_ = nullptr
 
bool owns_geom_obj_
 

Detailed Description

Definition at line 115 of file geo_types.h.

Constructor & Destructor Documentation

◆ GeoMultiPolygon() [1/3]

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

Definition at line 353 of file geo_types.cpp.

References CHECK.

355  {
356  geom_ = OGRGeometryFactory::createGeometry(OGRwkbGeometryType::wkbMultiPolygon);
357  OGRMultiPolygon* multipoly = dynamic_cast<OGRMultiPolygon*>(geom_);
358  CHECK(multipoly);
359 
360  size_t ring_ctr = 0;
361  size_t coords_ctr = 0;
362  for (const auto& rings_in_poly : poly_rings) {
363  OGRPolygon poly;
364  for (auto r = 0; r < rings_in_poly; r++) {
365  OGRLinearRing ring;
366  const auto ring_sz = ring_sizes[ring_ctr];
367  for (auto i = 0; i < 2 * ring_sz; i += 2) {
368  ring.addPoint(coords[coords_ctr + i], coords[coords_ctr + i + 1]);
369  }
370  ring.addPoint(coords[coords_ctr], coords[coords_ctr + 1]);
371  coords_ctr += 2 * ring_sz;
372  poly.addRing(&ring);
373  ring_ctr++;
374  }
375  multipoly->addGeometry(&poly);
376  }
377 }
OGRGeometry * geom_
Definition: geo_types.h:59
#define CHECK(condition)
Definition: Logger.h:187

◆ GeoMultiPolygon() [2/3]

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

Definition at line 379 of file geo_types.cpp.

References CHECK.

379  {
380  const auto err = GeoBase::createFromWktString(wkt, &geom_);
381  if (err != OGRERR_NONE) {
382  throw GeoTypesError("MultiPolygon", err);
383  }
384  CHECK(geom_);
385  if (wkbFlatten(geom_->getGeometryType()) != OGRwkbGeometryType::wkbMultiPolygon) {
386  throw GeoTypesError("MultiPolygon",
387  "Unexpected geometry type from WKT string: " +
388  std::string(OGRGeometryTypeToName(geom_->getGeometryType())));
389  }
390 }
static int createFromWktString(const std::string &wkt, OGRGeometry **geom)
Definition: geo_types.cpp:147
OGRGeometry * geom_
Definition: geo_types.h:59
#define CHECK(condition)
Definition: Logger.h:187

◆ GeoMultiPolygon() [3/3]

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

Definition at line 129 of file geo_types.h.

130  : GeoBase(geom, owns_geom_obj) {}

Member Function Documentation

◆ getColumns()

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

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

395  {
396  const auto mpoly = dynamic_cast<OGRMultiPolygon*>(geom_);
397  CHECK(mpoly);
398 
399  if (mpoly->IsEmpty()) {
400  // until the run-time can handle empties
401  throw GeoTypesError("MultiPolygon", "'EMPTY' not supported");
402  // return null bounds
403  bounds.push_back(NULL_DOUBLE);
404  bounds.push_back(NULL_DOUBLE);
405  bounds.push_back(NULL_DOUBLE);
406  bounds.push_back(NULL_DOUBLE);
407  return;
408  }
409 
410  BoundingBox bbox;
411  for (auto p = 0; p < mpoly->getNumGeometries(); p++) {
412  const auto mpoly_geom = mpoly->getGeometryRef(p);
413  CHECK(mpoly_geom);
414  const auto poly_geom = dynamic_cast<OGRPolygon*>(mpoly_geom);
415  if (!poly_geom) {
416  throw GeoTypesError("MultiPolygon",
417  "Failed to read polygon geometry from multipolygon");
418  }
419  const auto exterior_ring = poly_geom->getExteriorRing();
420  CHECK(exterior_ring);
421  // All exterior rings are imported CCW
422  if (exterior_ring->isClockwise()) {
423  exterior_ring->reverseWindingOrder();
424  }
425  const auto num_points_added = process_poly_ring(exterior_ring, coords, &bbox);
426  ring_sizes.push_back(num_points_added);
427 
428  for (auto r = 0; r < poly_geom->getNumInteriorRings(); r++) {
429  auto interior_ring = poly_geom->getInteriorRing(r);
430  CHECK(interior_ring);
431  // All interior rings are imported CW
432  if (!interior_ring->isClockwise()) {
433  interior_ring->reverseWindingOrder();
434  }
435  const auto num_points_added = process_poly_ring(interior_ring, coords, nullptr);
436  ring_sizes.push_back(num_points_added);
437  }
438  poly_rings.push_back(poly_geom->getNumInteriorRings() + 1);
439  }
440  bounds.push_back(bbox.min.x);
441  bounds.push_back(bbox.min.y);
442  bounds.push_back(bbox.max.x);
443  bounds.push_back(bbox.max.y);
444 }
#define NULL_DOUBLE
Definition: sqltypes.h:177
OGRGeometry * geom_
Definition: geo_types.h:59
#define CHECK(condition)
Definition: Logger.h:187
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 132 of file geo_types.h.


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