2020-02-18 13:32:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "PolygonDictionary.h"
|
|
|
|
#include "PolygonDictionaryUtils.h"
|
|
|
|
|
2020-03-22 12:42:08 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2020-02-18 13:32:18 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Simple implementation of the polygon dictionary. Doesn't generate anything during its construction.
|
2020-05-24 12:09:36 +00:00
|
|
|
* Iterates over all stored polygons for each query, checking each of them in linear time.
|
2020-05-25 15:57:03 +00:00
|
|
|
* Retrieves the polygon with the smallest area containing the given point.
|
|
|
|
* If there is more than one any such polygon may be returned.
|
2020-05-24 12:09:36 +00:00
|
|
|
*/
|
2020-05-25 15:57:03 +00:00
|
|
|
class PolygonDictionarySimple : public IPolygonDictionary
|
2020-02-18 13:32:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-05-25 15:57:03 +00:00
|
|
|
PolygonDictionarySimple(
|
2020-02-18 13:32:18 +00:00
|
|
|
const std::string & database_,
|
|
|
|
const std::string & name_,
|
|
|
|
const DictionaryStructure & dict_struct_,
|
|
|
|
DictionarySourcePtr source_ptr_,
|
|
|
|
DictionaryLifetime dict_lifetime_,
|
|
|
|
InputType input_type_,
|
|
|
|
PointType point_type_);
|
|
|
|
|
|
|
|
std::shared_ptr<const IExternalLoadable> clone() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool find(const Point & point, size_t & id) const override;
|
|
|
|
};
|
|
|
|
|
2020-05-25 15:57:03 +00:00
|
|
|
/** A polygon dictionary which generates a recursive grid in order to efficiently cut the number
|
|
|
|
* of polygons to be checked for a given point.
|
|
|
|
* For more detail see the GridRoot and FinalCell classes.
|
|
|
|
* Separately, a slab index is built for each individual polygon. This allows to check the
|
|
|
|
* candidates more efficiently.
|
2020-05-24 12:09:36 +00:00
|
|
|
*/
|
2020-05-25 15:57:03 +00:00
|
|
|
class PolygonDictionaryIndexEach : public IPolygonDictionary
|
2020-02-18 13:32:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-05-25 15:57:03 +00:00
|
|
|
PolygonDictionaryIndexEach(
|
2020-03-21 23:12:23 +00:00
|
|
|
const std::string & database_,
|
|
|
|
const std::string & name_,
|
|
|
|
const DictionaryStructure & dict_struct_,
|
|
|
|
DictionarySourcePtr source_ptr_,
|
|
|
|
DictionaryLifetime dict_lifetime_,
|
|
|
|
InputType input_type_,
|
2020-05-24 22:51:15 +00:00
|
|
|
PointType point_type_,
|
|
|
|
int min_intersections_,
|
|
|
|
int max_depth_);
|
2020-03-21 23:12:23 +00:00
|
|
|
|
|
|
|
std::shared_ptr<const IExternalLoadable> clone() const override;
|
|
|
|
|
2020-05-24 23:16:04 +00:00
|
|
|
static constexpr size_t kMinIntersectionsDefault = 1;
|
|
|
|
static constexpr size_t kMaxDepthDefault = 5;
|
|
|
|
|
2020-03-21 23:12:23 +00:00
|
|
|
private:
|
|
|
|
bool find(const Point & point, size_t & id) const override;
|
|
|
|
|
2020-05-24 12:09:36 +00:00
|
|
|
std::vector<SlabsPolygonIndex> buckets;
|
2020-05-21 00:50:19 +00:00
|
|
|
GridRoot<FinalCell> grid;
|
2020-05-24 22:51:15 +00:00
|
|
|
|
|
|
|
const size_t min_intersections;
|
|
|
|
const size_t max_depth;
|
2020-03-21 23:12:23 +00:00
|
|
|
};
|
|
|
|
|
2020-05-24 12:09:36 +00:00
|
|
|
/** Uses single SlabsPolygonIndex for all queries. */
|
2020-05-25 15:57:03 +00:00
|
|
|
class PolygonDictionaryIndexCell : public IPolygonDictionary
|
2020-03-23 00:16:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-05-25 15:57:03 +00:00
|
|
|
PolygonDictionaryIndexCell(
|
2020-03-23 00:16:46 +00:00
|
|
|
const std::string & database_,
|
|
|
|
const std::string & name_,
|
|
|
|
const DictionaryStructure & dict_struct_,
|
|
|
|
DictionarySourcePtr source_ptr_,
|
|
|
|
DictionaryLifetime dict_lifetime_,
|
|
|
|
InputType input_type_,
|
2020-05-24 22:51:15 +00:00
|
|
|
PointType point_type_,
|
|
|
|
size_t min_intersections_,
|
|
|
|
size_t max_depth_);
|
2020-03-23 00:16:46 +00:00
|
|
|
|
|
|
|
std::shared_ptr<const IExternalLoadable> clone() const override;
|
|
|
|
|
2020-05-24 23:16:04 +00:00
|
|
|
static constexpr size_t kMinIntersectionsDefault = 1;
|
|
|
|
static constexpr size_t kMaxDepthDefault = 5;
|
|
|
|
|
2020-03-23 00:16:46 +00:00
|
|
|
private:
|
|
|
|
bool find(const Point & point, size_t & id) const override;
|
|
|
|
|
2020-05-21 01:32:18 +00:00
|
|
|
GridRoot<FinalCellWithSlabs> index;
|
|
|
|
|
2020-05-24 22:51:15 +00:00
|
|
|
const size_t min_intersections;
|
|
|
|
const size_t max_depth;
|
2020-03-23 00:16:46 +00:00
|
|
|
};
|
|
|
|
|
2020-02-26 12:41:07 +00:00
|
|
|
}
|
2020-03-22 12:42:08 +00:00
|
|
|
|