#include #include #include #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int ILLEGAL_TYPE_OF_ARGUMENT; extern const int BAD_ARGUMENT; } template class FunctionReadWkt : public IFunction { public: explicit FunctionReadWkt() {} size_t getNumberOfArguments() const override { return 1; } DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { if (checkAndGetDataType(arguments[0].get()) == nullptr) { throw Exception("First argument should be String", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); } return DataType::nestedDataType(); } void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override { auto column_string = checkAndGetColumn(block.getByPosition(arguments[0]).column.get()); Serializer serializer; Geometry geometry; for (size_t i = 0; i < input_rows_count; i++) { const auto & str = column_string->getDataAt(i).toString(); boost::geometry::read_wkt(str, geometry); serializer.add(geometry); } block.getByPosition(result).column = serializer.finalize(); } bool useDefaultImplementationForConstants() const override { return true; } }; class FunctionReadWktPoint : public FunctionReadWkt { public: static inline const char * name = "readWktPoint"; String getName() const override { return name; } static FunctionPtr create(const Context &) { return std::make_shared(); } }; class FunctionReadWktPolygon : public FunctionReadWkt { public: static inline const char * name = "readWktPolygon"; String getName() const override { return name; } static FunctionPtr create(const Context &) { return std::make_shared(); } }; class FunctionReadWktMultiPolygon : public FunctionReadWkt { public: static inline const char * name = "readWktMultiPolygon"; String getName() const override { return name; } static FunctionPtr create(const Context &) { return std::make_shared(); } }; void registerFunctionReadWkt(FunctionFactory & factory) { factory.registerFunction(); factory.registerFunction(); factory.registerFunction(); } }