OmniSciDB  04ee39c94c
Geo_namespace::GeoPolygon Class Reference

#include <geo_types.h>

+ Inheritance diagram for Geo_namespace::GeoPolygon:
+ Collaboration diagram for Geo_namespace::GeoPolygon:

Public Member Functions

 GeoPolygon (const std::vector< double > &coords, const std::vector< int32_t > &ring_sizes)
 
 GeoPolygon (const std::string &wkt)
 
void getColumns (std::vector< double > &coords, std::vector< int32_t > &ring_sizes, std::vector< double > &bounds) const
 
GeoType getType () const final
 
int32_t getNumInteriorRings () const
 
- 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

 GeoPolygon (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 96 of file geo_types.h.

Constructor & Destructor Documentation

◆ GeoPolygon() [1/3]

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

Definition at line 273 of file geo_types.cpp.

References CHECK.

274  {
275  geom_ = OGRGeometryFactory::createGeometry(OGRwkbGeometryType::wkbPolygon);
276  OGRPolygon* poly = dynamic_cast<OGRPolygon*>(geom_);
277  CHECK(poly);
278 
279  size_t coords_ctr = 0;
280  for (size_t r = 0; r < ring_sizes.size(); r++) {
281  OGRLinearRing ring;
282  const auto ring_sz = ring_sizes[r];
283  for (auto i = 0; i < 2 * ring_sz; i += 2) {
284  ring.addPoint(coords[coords_ctr + i], coords[coords_ctr + i + 1]);
285  }
286  ring.addPoint(coords[coords_ctr], coords[coords_ctr + 1]);
287  coords_ctr += 2 * ring_sz;
288  poly->addRing(&ring);
289  }
290 }
OGRGeometry * geom_
Definition: geo_types.h:59
#define CHECK(condition)
Definition: Logger.h:187

◆ GeoPolygon() [2/3]

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

Definition at line 292 of file geo_types.cpp.

References CHECK.

292  {
293  const auto err = GeoBase::createFromWktString(wkt, &geom_);
294  if (err != OGRERR_NONE) {
295  throw GeoTypesError("Polygon", err);
296  }
297  CHECK(geom_);
298  if (wkbFlatten(geom_->getGeometryType()) != OGRwkbGeometryType::wkbPolygon) {
299  throw GeoTypesError("Polygon",
300  "Unexpected geometry type from WKT string: " +
301  std::string(OGRGeometryTypeToName(geom_->getGeometryType())));
302  }
303 }
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

◆ GeoPolygon() [3/3]

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

Definition at line 109 of file geo_types.h.

110  : GeoBase(geom, owns_geom_obj) {}

Member Function Documentation

◆ getColumns()

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

Definition at line 305 of file geo_types.cpp.

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

307  {
308  const auto poly_geom = dynamic_cast<OGRPolygon*>(geom_);
309  CHECK(poly_geom);
310 
311  if (poly_geom->IsEmpty()) {
312  // until the run-time can handle empties
313  throw GeoTypesError("Polygon", "'EMPTY' not supported");
314  // return null bounds
315  bounds.push_back(NULL_DOUBLE);
316  bounds.push_back(NULL_DOUBLE);
317  bounds.push_back(NULL_DOUBLE);
318  bounds.push_back(NULL_DOUBLE);
319  return;
320  }
321 
322  BoundingBox bbox;
323  const auto exterior_ring = poly_geom->getExteriorRing();
324  CHECK(exterior_ring);
325  // All exterior rings are imported CCW
326  if (exterior_ring->isClockwise()) {
327  exterior_ring->reverseWindingOrder();
328  }
329  const auto num_points_added = process_poly_ring(exterior_ring, coords, &bbox);
330  ring_sizes.push_back(num_points_added);
331  for (auto r = 0; r < poly_geom->getNumInteriorRings(); r++) {
332  auto interior_ring = poly_geom->getInteriorRing(r);
333  CHECK(interior_ring);
334  // All interior rings are imported CW
335  if (!interior_ring->isClockwise()) {
336  interior_ring->reverseWindingOrder();
337  }
338  const auto num_points_added = process_poly_ring(interior_ring, coords, nullptr);
339  ring_sizes.push_back(num_points_added);
340  }
341  bounds.push_back(bbox.min.x);
342  bounds.push_back(bbox.min.y);
343  bounds.push_back(bbox.max.x);
344  bounds.push_back(bbox.max.y);
345 }
#define NULL_DOUBLE
Definition: sqltypes.h:176
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:

◆ getNumInteriorRings()

int32_t Geo_namespace::GeoPolygon::getNumInteriorRings ( ) const

Definition at line 347 of file geo_types.cpp.

References CHECK.

347  {
348  const auto poly_geom = dynamic_cast<OGRPolygon*>(geom_);
349  CHECK(poly_geom);
350  return poly_geom->getNumInteriorRings();
351 }
OGRGeometry * geom_
Definition: geo_types.h:59
#define CHECK(condition)
Definition: Logger.h:187

◆ getType()

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

Implements Geo_namespace::GeoBase.

Definition at line 104 of file geo_types.h.

References kPOLYGON.

Friends And Related Function Documentation

◆ GeoTypesFactory

friend class GeoTypesFactory
friend

Definition at line 112 of file geo_types.h.


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