提交 05953f4c 编写于 作者: A Alexey Ilyukhov 提交者: Nikita Mikhaylov

Add readWkt, svg

上级 938ca686
......@@ -100,8 +100,6 @@ public:
container.reserve(r - l + 1);
container.resize(r - l);
LOG_FATAL(&Poco::Logger::get("geoconv"), "ring: l = {}, r = {}", l, r);
for (size_t j = l; j < r; j++) {
pointParser.get(container[j - l], j);
}
......
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeCustomGeo.h>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionHelpers.h>
#include <Functions/geometryConverters.h>
#include <Columns/ColumnString.h>
#include <string>
#include <memory>
namespace DB
{
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int BAD_ARGUMENT;
}
template <class DataType, class Geometry, class Serializer>
class FunctionReadWkt : public IFunction
{
public:
explicit FunctionReadWkt() {}
size_t getNumberOfArguments() const override
{
return 1;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (checkAndGetDataType<DataTypeString>(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<ColumnString>(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<DataTypeCustomPointSerialization, Float64Point, Float64PointSerializer>
{
public:
static inline const char * name = "readWktPoint";
String getName() const override
{
return name;
}
static FunctionPtr create(const Context &)
{
return std::make_shared<FunctionReadWktPoint>();
}
};
class FunctionReadWktPolygon : public FunctionReadWkt<DataTypeCustomPolygonSerialization, Float64Polygon, Float64PolygonSerializer>
{
public:
static inline const char * name = "readWktPolygon";
String getName() const override
{
return name;
}
static FunctionPtr create(const Context &)
{
return std::make_shared<FunctionReadWktPolygon>();
}
};
class FunctionReadWktMultiPolygon : public FunctionReadWkt<DataTypeCustomMultiPolygonSerialization, Float64MultiPolygon, Float64MultiPolygonSerializer>
{
public:
static inline const char * name = "readWktMultiPolygon";
String getName() const override
{
return name;
}
static FunctionPtr create(const Context &)
{
return std::make_shared<FunctionReadWktMultiPolygon>();
}
};
void registerFunctionReadWkt(FunctionFactory & factory)
{
factory.registerFunction<FunctionReadWktPoint>();
factory.registerFunction<FunctionReadWktPolygon>();
factory.registerFunction<FunctionReadWktMultiPolygon>();
}
}
......@@ -16,6 +16,8 @@ void registerFunctionGeohashEncode(FunctionFactory & factory);
void registerFunctionGeohashDecode(FunctionFactory & factory);
void registerFunctionGeohashesInBox(FunctionFactory & factory);
void registerFunctionWkt(FunctionFactory & factory);
void registerFunctionReadWkt(FunctionFactory & factory);
void registerFunctionSvg(FunctionFactory & factory);
#if USE_H3
void registerFunctionGeoToH3(FunctionFactory &);
......@@ -45,6 +47,8 @@ void registerFunctionsGeo(FunctionFactory & factory)
registerFunctionGeohashDecode(factory);
registerFunctionGeohashesInBox(factory);
registerFunctionWkt(factory);
registerFunctionReadWkt(factory);
registerFunctionSvg(factory);
#if USE_H3
registerFunctionGeoToH3(factory);
......
#include <DataTypes/DataTypeString.h>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionHelpers.h>
#include <Functions/geometryConverters.h>
#include <Columns/ColumnString.h>
#include <string>
#include <memory>
namespace DB
{
namespace ErrorCodes {
extern const int TOO_MANY_ARGUMENTS_FOR_FUNCTION;
extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION;
}
class FunctionSvg : public IFunction
{
public:
static inline const char * name = "svg";
explicit FunctionSvg() {}
static FunctionPtr create(const Context &)
{
return std::make_shared<FunctionSvg>();
}
String getName() const override
{
return name;
}
bool isVariadic() const override
{
return true;
}
size_t getNumberOfArguments() const override
{
return 2;
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (arguments.size() > 2)
{
throw Exception("Too many arguments", ErrorCodes::TOO_MANY_ARGUMENTS_FOR_FUNCTION);
}
if (arguments.size() == 0) {
throw Exception("Too few arguments", ErrorCodes::TOO_FEW_ARGUMENTS_FOR_FUNCTION);
}
if (arguments.size() == 2 && checkAndGetDataType<DataTypeString>(arguments[1].get()) == nullptr)
{
throw Exception("Second argument should be String",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}
return std::make_shared<DataTypeString>();
}
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override
{
const auto * const_col = checkAndGetColumn<ColumnConst>(block.getByPosition(arguments[0]).column.get());
auto parser = const_col ?
makeGeometryFromColumnParser(ColumnWithTypeAndName(const_col->getDataColumnPtr(), block.getByPosition(arguments[0]).type, block.getByPosition(arguments[0]).name)) :
makeGeometryFromColumnParser(block.getByPosition(arguments[0]));
bool geo_column_is_const = static_cast<bool>(const_col);
auto res_column = ColumnString::create();
auto container = createContainer(parser);
bool has_style = arguments.size() > 1;
ColumnPtr style;
if (has_style) {
style = block.getByPosition(arguments[1]).column;
}
for (size_t i = 0; i < input_rows_count; i++)
{
std::stringstream str;
if (!geo_column_is_const || i == 0)
get(parser, container, i);
str << boost::geometry::svg(container, has_style ? style->getDataAt(i).toString() : "");
std::string serialized = str.str();
res_column->insertData(serialized.c_str(), serialized.size());
}
block.getByPosition(result).column = std::move(res_column);
}
bool useDefaultImplementationForConstants() const override
{
return true;
}
};
void registerFunctionSvg(FunctionFactory & factory)
{
factory.registerFunction<FunctionSvg>();
}
}
......@@ -61,7 +61,6 @@ public:
}
};
void registerFunctionWkt(FunctionFactory & factory)
{
factory.registerFunction<FunctionWkt>();
......
......@@ -392,6 +392,7 @@ SRCS(
randomStringUTF8.cpp
regexpQuoteMeta.cpp
registerFunctions.cpp
readWkt.cpp
registerFunctionsArithmetic.cpp
registerFunctionsComparison.cpp
registerFunctionsConditional.cpp
......@@ -448,6 +449,7 @@ SRCS(
subtractSeconds.cpp
subtractWeeks.cpp
subtractYears.cpp
svg.cpp
tan.cpp
tanh.cpp
tcpPort.cpp
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册