OmniSciDB  2e3a973ef4
Geospatial::GeoBase Class Referenceabstract

#include <Types.h>

+ Inheritance diagram for Geospatial::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 44 of file Types.h.

Member Enumeration Documentation

◆ GeoOp

Enumerator
kPROJECTION 
kINTERSECTION 
kDIFFERENCE 
kUNION 
kBUFFER 
kISVALID 
kISEMPTY 

Definition at line 59 of file Types.h.

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

◆ GeoType

Enumerator
kPOINT 
kLINESTRING 
kPOLYGON 
kMULTIPOLYGON 
kGEOMETRY 
kGEOMETRYCOLLECTION 

Definition at line 51 of file Types.h.

51  {
52  kPOINT,
54  kPOLYGON,
56  kGEOMETRY,
57  kGEOMETRYCOLLECTION
58  };

Constructor & Destructor Documentation

◆ GeoBase() [1/2]

Geospatial::GeoBase::GeoBase ( )
inline

Definition at line 46 of file Types.h.

46 : owns_geom_obj_(true) {}
bool owns_geom_obj_
Definition: Types.h:84

◆ ~GeoBase()

Geospatial::GeoBase::~GeoBase ( )
virtual

Definition at line 139 of file Types.cpp.

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

◆ GeoBase() [2/2]

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

Definition at line 81 of file Types.h.

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

Member Function Documentation

◆ createFromWkb()

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

Definition at line 167 of file Types.cpp.

References CHECK.

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

◆ createFromWktString()

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

Definition at line 148 of file Types.cpp.

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

◆ getOGRGeometry()

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

Definition at line 69 of file Types.h.

References operator==(), and run.

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

69 { return geom_; }
OGRGeometry * geom_
Definition: Types.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getType()

◆ getWkb()

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

Definition at line 180 of file Types.cpp.

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

◆ getWktString()

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

Definition at line 158 of file Types.cpp.

References CHECK.

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

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

◆ isEmpty()

bool Geospatial::GeoBase::isEmpty ( ) const

Definition at line 190 of file Types.cpp.

190  {
191  return geom_ && geom_->IsEmpty();
192 }
OGRGeometry * geom_
Definition: Types.h:83

◆ operator==()

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

Definition at line 194 of file Types.cpp.

References geom_.

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

◆ optimized_run()

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

Definition at line 235 of file Types.cpp.

References geom_, and run_benchmark_import::result.

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

◆ run() [1/3]

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

Definition at line 202 of file Types.cpp.

References geom_, and run_benchmark_import::result.

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

◆ run() [2/3]

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

Definition at line 293 of file Types.cpp.

References run_benchmark_import::result.

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

◆ run() [3/3]

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

Definition at line 317 of file Types.cpp.

References run_benchmark_import::result.

317  {
318  auto result = false;
319  switch (op) {
321  result = geom_->IsValid();
322  break;
324  result = isEmpty();
325  break;
326  default:
327  break;
328  }
329  return result;
330 }
OGRGeometry * geom_
Definition: Types.h:83
bool isEmpty() const
Definition: Types.cpp:190

Friends And Related Function Documentation

◆ GeoTypesFactory

friend class GeoTypesFactory
friend

Definition at line 89 of file Types.h.

Member Data Documentation

◆ geom_

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

Definition at line 83 of file Types.h.

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

◆ owns_geom_obj_

bool Geospatial::GeoBase::owns_geom_obj_
protected

Definition at line 84 of file Types.h.


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