OmniSciDB  8a228a1076
Geo_namespace::GeoBase Class Referenceabstract

#include <geo_types.h>

+ Inheritance diagram for Geo_namespace::GeoBase:

Public Types

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
}
 

Public Member Functions

 GeoBase ()
 
virtual ~GeoBase ()
 
std::string getWktString () const
 
bool getWkb (std::vector< uint8_t > &) const
 
virtual GeoType getType () const =0
 
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

 GeoBase (OGRGeometry *geom, const bool owns_geom_obj)
 

Static Protected Member Functions

static int createFromWktString (const std::string &wkt, OGRGeometry **geom)
 
static int createFromWkb (const std::vector< uint8_t > &wkb, OGRGeometry **geom)
 

Protected Attributes

OGRGeometry * geom_ = nullptr
 
bool owns_geom_obj_
 

Friends

class GeoTypesFactory
 

Detailed Description

Definition at line 45 of file geo_types.h.

Member Enumeration Documentation

◆ GeoOp

Enumerator
kPROJECTION 
kINTERSECTION 
kDIFFERENCE 
kUNION 
kBUFFER 
kISVALID 
kISEMPTY 

Definition at line 60 of file geo_types.h.

60  {
61  kPROJECTION = 0,
62  kINTERSECTION = 1,
63  kDIFFERENCE = 2,
64  kUNION = 3,
65  kBUFFER = 4,
66  kISVALID = 5,
67  kISEMPTY = 6
68  };

◆ GeoType

Enumerator
kPOINT 
kLINESTRING 
kPOLYGON 
kMULTIPOLYGON 
kGEOMETRY 
kGEOMETRYCOLLECTION 

Definition at line 52 of file geo_types.h.

52  {
53  kPOINT,
55  kPOLYGON,
57  kGEOMETRY,
58  kGEOMETRYCOLLECTION
59  };

Constructor & Destructor Documentation

◆ GeoBase() [1/2]

Geo_namespace::GeoBase::GeoBase ( )
inline

Definition at line 47 of file geo_types.h.

47 : owns_geom_obj_(true) {}

◆ ~GeoBase()

Geo_namespace::GeoBase::~GeoBase ( )
virtual

Definition at line 138 of file geo_types.cpp.

138  {
139  // Note: Removing the geometry object that was pulled from an OGRFeature results in a
140  // segfault. If we are wrapping around a pre-existing OGRGeometry object, we let the
141  // caller manage the memory.
142  if (geom_ && owns_geom_obj_) {
143  OGRGeometryFactory::destroyGeometry(geom_);
144  }
145 }
OGRGeometry * geom_
Definition: geo_types.h:84

◆ GeoBase() [2/2]

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

Definition at line 82 of file geo_types.h.

83  : geom_(geom), owns_geom_obj_(owns_geom_obj) {}
OGRGeometry * geom_
Definition: geo_types.h:84

Member Function Documentation

◆ createFromWkb()

OGRErr Geo_namespace::GeoBase::createFromWkb ( const std::vector< uint8_t > &  wkb,
OGRGeometry **  geom 
)
staticprotected

Definition at line 166 of file geo_types.cpp.

References CHECK.

166  {
167 #if (GDAL_VERSION_MAJOR > 2) || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR >= 3)
168  OGRErr ogr_status =
169  OGRGeometryFactory::createFromWkb(wkb.data(), nullptr, geom, wkb.size());
170  return ogr_status;
171 #else
172  CHECK(false);
173 #endif
174 }
#define CHECK(condition)
Definition: Logger.h:197

◆ createFromWktString()

OGRErr Geo_namespace::GeoBase::createFromWktString ( const std::string &  wkt,
OGRGeometry **  geom 
)
staticprotected

Definition at line 147 of file geo_types.cpp.

147  {
148 #if (GDAL_VERSION_MAJOR > 2) || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR >= 3)
149  OGRErr ogr_status = OGRGeometryFactory::createFromWkt(wkt.c_str(), nullptr, geom);
150 #else
151  auto data = (char*)wkt.c_str();
152  OGRErr ogr_status = OGRGeometryFactory::createFromWkt(&data, NULL, geom);
153 #endif
154  return ogr_status;
155 }

◆ getOGRGeometry()

const OGRGeometry* Geo_namespace::GeoBase::getOGRGeometry ( ) const
inline

Definition at line 70 of file geo_types.h.

References operator==(), and run.

Referenced by import_export::anonymous_namespace{QueryExporterGDAL.cpp}::insert_geo_column().

70 { return geom_; }
OGRGeometry * geom_
Definition: geo_types.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getType()

◆ getWkb()

bool Geo_namespace::GeoBase::getWkb ( std::vector< uint8_t > &  wkb) const

Definition at line 179 of file geo_types.cpp.

179  {
180  auto size = geom_->WkbSize();
181  if (size > 0) {
182  wkb.resize(size);
183  geom_->exportToWkb(wkbNDR, wkb.data());
184  return true;
185  }
186  return false;
187 }
OGRGeometry * geom_
Definition: geo_types.h:84

◆ getWktString()

std::string Geo_namespace::GeoBase::getWktString ( ) const

Definition at line 157 of file geo_types.cpp.

References CHECK.

Referenced by GeoWktSerializer< kPOINT >::serialize(), GeoWktSerializer< kLINESTRING >::serialize(), GeoWktSerializer< kPOLYGON >::serialize(), and GeoWktSerializer< kMULTIPOLYGON >::serialize().

157  {
158  char* wkt = nullptr;
159  geom_->exportToWkt(&wkt);
160  CHECK(wkt);
161  std::string wkt_str(wkt);
162  CPLFree(wkt);
163  return wkt_str;
164 }
OGRGeometry * geom_
Definition: geo_types.h:84
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function:

◆ isEmpty()

bool Geo_namespace::GeoBase::isEmpty ( ) const

Definition at line 189 of file geo_types.cpp.

189  {
190  return geom_ && geom_->IsEmpty();
191 }
OGRGeometry * geom_
Definition: geo_types.h:84

◆ operator==()

bool Geo_namespace::GeoBase::operator== ( const GeoBase other) const
virtual

Definition at line 193 of file geo_types.cpp.

References geom_.

193  {
194  if (!this->geom_ || !other.geom_) {
195  return false;
196  }
197  return this->geom_->Equals(other.geom_);
198 }
OGRGeometry * geom_
Definition: geo_types.h:84

◆ optimized_run()

std::unique_ptr< GeoBase > Geo_namespace::GeoBase::optimized_run ( GeoBase::GeoOp  op,
const GeoBase other 
) const

Definition at line 234 of file geo_types.cpp.

References geom_, and run_benchmark_import::result.

235  {
236  OGRGeometry* result = nullptr;
237  // Loop through polys combinations, check validity, do intersections
238  // where needed, return a union of all intersections
239  auto gc1 = geom_->toGeometryCollection();
240  auto gc2 = other.geom_->toGeometryCollection();
241  if (!gc1 || !gc2 || gc1->IsEmpty() || gc2->IsEmpty()) {
242  return nullptr;
243  }
244  for (int i1 = 0; i1 < gc1->getNumGeometries(); i1++) {
245  auto g1 = gc1->getGeometryRef(i1);
246  // Validity check is very slow
247  if (!g1 || g1->IsEmpty() /*|| !g1->IsValid()*/) {
248  continue;
249  }
250  OGREnvelope ge1;
251  g1->getEnvelope(&ge1);
252  for (int i2 = 0; i2 < gc2->getNumGeometries(); i2++) {
253  auto g2 = gc2->getGeometryRef(i2);
254  // Validity check is very slow
255  if (!g2 || g2->IsEmpty() /*|| !g2->IsValid()*/) {
256  continue;
257  }
258  // Check for bounding box overlap
259  OGREnvelope ge2;
260  g2->getEnvelope(&ge2);
261  if (!ge1.Intersects(ge2)) {
262  continue;
263  }
264  // Do intersection
265  auto intermediate_result = g1->Intersection(g2);
266  if (!intermediate_result || intermediate_result->IsEmpty()) {
267  continue;
268  }
269  if (!result) {
270  result = intermediate_result;
271  } else {
272  result = result->Union(intermediate_result);
273  }
274  }
275  }
276 
277  // TODO: Need to handle empty/non-POLYGON result
278  if (!result || result->IsEmpty() ||
279  !(result->getGeometryType() == wkbPolygon ||
280  result->getGeometryType() == wkbMultiPolygon)) {
281  // throw GeoTypesError(std::string(OGRGeometryTypeToName(geom_->getGeometryType())),
282  // "Currenly don't support invalid or empty result");
283  // return GeoTypesFactory::createGeoType("POLYGON EMPTY");
284  // Not supporting EMPTY polygons, return a dot polygon
286  "MULTIPOLYGON(((0 0,0.0000001 0,0 0.0000001)))");
287  }
288  return GeoTypesFactory::createGeoType(result);
289 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: geo_types.cpp:682
OGRGeometry * geom_
Definition: geo_types.h:84

◆ run() [1/3]

std::unique_ptr< GeoBase > Geo_namespace::GeoBase::run ( GeoBase::GeoOp  op,
const GeoBase other 
) const

Definition at line 201 of file geo_types.cpp.

References geom_, and run_benchmark_import::result.

201  {
202  OGRGeometry* result = nullptr;
203  // Invalid geometries are derailing geo op performance,
204  // Checking validity before running an operation doesn't have lesser penalty.
205  // DOES NOT HELP: if (geom_->IsValid() && other.geom_->IsValid()) {
206  switch (op) {
208  result = geom_->Intersection(other.geom_);
209  break;
211  result = geom_->Difference(other.geom_);
212  break;
214  result = geom_->Union(other.geom_);
215  break;
216  default:
217  break;
218  }
219  // TODO: Need to handle empty/non-POLYGON result
220  if (!result || result->IsEmpty() ||
221  !(result->getGeometryType() == wkbPolygon ||
222  result->getGeometryType() == wkbMultiPolygon)) {
223  // throw GeoTypesError(std::string(OGRGeometryTypeToName(geom_->getGeometryType())),
224  // "Currenly don't support invalid or empty result");
225  // return GeoTypesFactory::createGeoType("POLYGON EMPTY");
226  // Not supporting EMPTY polygons, return a dot polygon
228  "MULTIPOLYGON(((0 0,0.0000001 0,0 0.0000001)))");
229  }
230  return GeoTypesFactory::createGeoType(result);
231 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: geo_types.cpp:682
OGRGeometry * geom_
Definition: geo_types.h:84

◆ run() [2/3]

std::unique_ptr< GeoBase > Geo_namespace::GeoBase::run ( GeoBase::GeoOp  op,
double  param 
) const

Definition at line 292 of file geo_types.cpp.

References run_benchmark_import::result.

292  {
293  OGRGeometry* result = nullptr;
294  switch (op) {
296  result = geom_->Buffer(param);
297  break;
298  default:
299  break;
300  }
301  // TODO: Need to handle empty/non-POLYGON result
302  if (!result || result->IsEmpty() ||
303  !(result->getGeometryType() == wkbPolygon ||
304  result->getGeometryType() == wkbMultiPolygon)) {
305  // throw GeoTypesError(std::string(OGRGeometryTypeToName(geom_->getGeometryType())),
306  // "Currenly don't support invalid or empty result");
307  // return GeoTypesFactory::createGeoType("POLYGON EMPTY");
308  // Not supporting EMPTY polygons, return a dot polygon
310  "MULTIPOLYGON(((0 0,0.0000001 0,0 0.0000001)))");
311  }
312  return GeoTypesFactory::createGeoType(result);
313 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: geo_types.cpp:682
OGRGeometry * geom_
Definition: geo_types.h:84

◆ run() [3/3]

bool Geo_namespace::GeoBase::run ( GeoBase::GeoOp  op) const

Definition at line 316 of file geo_types.cpp.

References run_benchmark_import::result.

316  {
317  auto result = false;
318  switch (op) {
320  result = geom_->IsValid();
321  break;
323  result = isEmpty();
324  break;
325  default:
326  break;
327  }
328  return result;
329 }
OGRGeometry * geom_
Definition: geo_types.h:84
bool isEmpty() const
Definition: geo_types.cpp:189

Friends And Related Function Documentation

◆ GeoTypesFactory

friend class GeoTypesFactory
friend

Definition at line 90 of file geo_types.h.

Member Data Documentation

◆ geom_

OGRGeometry* Geo_namespace::GeoBase::geom_ = nullptr
protected

Definition at line 84 of file geo_types.h.

Referenced by operator==(), optimized_run(), and run().

◆ owns_geom_obj_

bool Geo_namespace::GeoBase::owns_geom_obj_
protected

Definition at line 85 of file geo_types.h.


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