Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed Apr 8, 2024
1 parent 14a5ff7 commit 9aef365
Show file tree
Hide file tree
Showing 28 changed files with 582 additions and 651 deletions.
5 changes: 3 additions & 2 deletions spatial/include/spatial/gdal/functions/raster_agg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ struct RasterAggBinaryOperation {
}

template <class INPUT_TYPE, class OPTS_TYPE, class STATE, class OP>
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, const OPTS_TYPE &opts, AggregateBinaryInput &agg, idx_t) {
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, const OPTS_TYPE &opts,
AggregateBinaryInput &agg, idx_t) {
Operation<INPUT_TYPE, OPTS_TYPE, STATE, OP>(state, input, opts, agg);
}

Expand All @@ -92,7 +93,7 @@ struct RasterAggBindData : public FunctionData {
std::vector<std::string> options;

explicit RasterAggBindData(ClientContext &context, std::vector<std::string> options)
: context(context), options(options) {
: context(context), options(options) {
}

unique_ptr<FunctionData> Copy() const override {
Expand Down
4 changes: 1 addition & 3 deletions spatial/include/spatial/gdal/raster/raster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class Raster {
bool GetValue(double &value, int32_t band_num, int32_t col, int32_t row) const;

public:

//! Returns the geometric X and Y (longitude and latitude) given a column and row
static bool RasterToWorldCoord(PointXY &point, double matrix[], int32_t col, int32_t row);

Expand All @@ -76,8 +75,7 @@ class Raster {
const std::vector<std::string> &options = std::vector<std::string>());

//! Returns a raster that is clipped by the input geometry
static GDALDataset *Clip(GDALDataset *dataset,
const geometry_t &geometry,
static GDALDataset *Clip(GDALDataset *dataset, const geometry_t &geometry,
const std::vector<std::string> &options = std::vector<std::string>());

//! Get the last error message.
Expand Down
8 changes: 3 additions & 5 deletions spatial/include/spatial/gdal/raster/raster_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ namespace gdal {
//! Does not take ownership of the pointer.
class RasterFactory {
public:

//! Given a file path, returns a GDALDataset
static GDALDataset *FromFile(const std::string &file_path,
const std::vector<std::string> &allowed_drivers = std::vector<std::string>(),
const std::vector<std::string> &open_options = std::vector<std::string>(),
const std::vector<std::string> &sibling_files = std::vector<std::string>());

//! Writes a GDALDataset to a file path
static bool WriteFile(GDALDataset *dataset,
const std::string &file_path,
const std::string &driver_name = "COG",
static bool WriteFile(GDALDataset *dataset, const std::string &file_path, const std::string &driver_name = "COG",
const std::vector<std::string> &write_options = std::vector<std::string>());

//! Transforms a vector of strings as a vector of const char pointers.
static std::vector<char const *> FromVectorOfStrings(const std::vector<std::string> &input);
//! Transforms a map of params as a vector of const char pointers.
static std::vector<char const *> FromNamedParameters(const named_parameter_map_t &input, const std::string &keyname);
static std::vector<char const *> FromNamedParameters(const named_parameter_map_t &input,
const std::string &keyname);
};

} // namespace gdal
Expand Down
49 changes: 23 additions & 26 deletions spatial/include/spatial/gdal/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,30 @@ namespace spatial {
namespace gdal {

//! Supported Pixel data types (GDALDataType).
typedef enum
{
Unknown = 0, /**< Unknown or unspecified type */
Byte = 1, /**< Eight bit unsigned integer */
Int8 = 14, /**< 8-bit signed integer */
UInt16 = 2, /**< Sixteen bit unsigned integer */
Int16 = 3, /**< Sixteen bit signed integer */
UInt32 = 4, /**< Thirty two bit unsigned integer */
Int32 = 5, /**< Thirty two bit signed integer */
UInt64 = 12, /**< 64 bit unsigned integer */
Int64 = 13, /**< 64 bit signed integer */
Float32 = 6, /**< Thirty two bit floating point */
Float64 = 7, /**< Sixty four bit floating point */
CInt16 = 8, /**< Complex Int16 */
CInt32 = 9, /**< Complex Int32 */
CFloat32 = 10, /**< Complex Float32 */
CFloat64 = 11, /**< Complex Float64 */
TypeCount = 15 /**< maximum type # + 1 */
typedef enum {
Unknown = 0, /**< Unknown or unspecified type */
Byte = 1, /**< Eight bit unsigned integer */
Int8 = 14, /**< 8-bit signed integer */
UInt16 = 2, /**< Sixteen bit unsigned integer */
Int16 = 3, /**< Sixteen bit signed integer */
UInt32 = 4, /**< Thirty two bit unsigned integer */
Int32 = 5, /**< Thirty two bit signed integer */
UInt64 = 12, /**< 64 bit unsigned integer */
Int64 = 13, /**< 64 bit signed integer */
Float32 = 6, /**< Thirty two bit floating point */
Float64 = 7, /**< Sixty four bit floating point */
CInt16 = 8, /**< Complex Int16 */
CInt32 = 9, /**< Complex Int32 */
CFloat32 = 10, /**< Complex Float32 */
CFloat64 = 11, /**< Complex Float64 */
TypeCount = 15 /**< maximum type # + 1 */
} PixelType;

//! Returns the name of given PixelType
std::string GetPixelTypeName(const PixelType& pixel_type);
std::string GetPixelTypeName(const PixelType &pixel_type);

//! Supported Types of color interpretation for raster bands (GDALColorInterp).
typedef enum
{
typedef enum {
Undefined = 0, /**< Undefined */
GrayIndex = 1, /**< Greyscale */
PaletteIndex = 2, /**< Paletted (see associated color table) */
Expand All @@ -52,11 +50,10 @@ typedef enum
} ColorInterp;

//! Returns the name of given ColorInterp
std::string GetColorInterpName(const ColorInterp& color_interp);
std::string GetColorInterpName(const ColorInterp &color_interp);

//! Supported Warp Resampling Algorithm (GDALResampleAlg).
typedef enum
{
typedef enum {
NearestNeighbour = 0, /**< Nearest neighbour (select on one input pixel) */
Bilinear = 1, /**< Bilinear (2x2 kernel) */
Cubic = 2, /**< Cubic Convolution Approximation (4x4 kernel) */
Expand All @@ -65,7 +62,7 @@ typedef enum
Average = 5, /**< Average (computes the weighted average of all non-NODATA contributing pixels) */
Mode = 6, /**< Mode (selects the value which appears most often of all the sampled points) */
Max = 8, /**< Max (selects maximum of all non-NODATA contributing pixels) */
Min = 9, /**< Min (selects minimum of all non-NODATA contributing pixels) */
Min = 9, /**< Min (selects minimum of all non-NODATA contributing pixels) */
Med = 10, /**< Med (selects median of all non-NODATA contributing pixels) */
Q1 = 11, /**< Q1 (selects first quartile of all non-NODATA contributing pixels) */
Q3 = 12, /**< Q3 (selects third quartile of all non-NODATA contributing pixels) */
Expand All @@ -74,7 +71,7 @@ typedef enum
} ResampleAlg;

//! Returns the name of given ResampleAlg
std::string GetResampleAlgName(const ResampleAlg& resample_alg);
std::string GetResampleAlgName(const ResampleAlg &resample_alg);

//! Position of a cell in a Raster (upper left corner as column and row)
struct RasterCoord {
Expand Down
3 changes: 1 addition & 2 deletions spatial/src/spatial/gdal/functions/aggregate/raster_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ unique_ptr<FunctionData> BindRasterAggOperation(ClientContext &context, Aggregat
options.push_back(option);
}
} else {
throw BinderException(StringUtil::Format(
"raster_agg: Unknown argument '%s'", arg->alias.c_str()));
throw BinderException(StringUtil::Format("raster_agg: Unknown argument '%s'", arg->alias.c_str()));
}
}

Expand Down
15 changes: 5 additions & 10 deletions spatial/src/spatial/gdal/functions/aggregate/st_mosaic_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ struct MosaicAggUnaryOperation : RasterAggUnaryOperation {
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
RasterMosaicFunction(state, target, finalize_data);
}

};

struct MosaicAggBinaryOperation : RasterAggBinaryOperation {
Expand All @@ -60,7 +59,6 @@ struct MosaicAggBinaryOperation : RasterAggBinaryOperation {
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
RasterMosaicFunction(state, target, finalize_data);
}

};

//------------------------------------------------------------------------
Expand Down Expand Up @@ -92,9 +90,7 @@ static constexpr const char *DOC_EXAMPLE = R"(
;
)";

static constexpr DocTag DOC_TAGS[] = {
{"ext", "spatial"}, {"category", "aggregation"}
};
static constexpr DocTag DOC_TAGS[] = {{"ext", "spatial"}, {"category", "aggregation"}};

//------------------------------------------------------------------------
// Register
Expand All @@ -105,15 +101,14 @@ void GdalAggregateFunctions::RegisterStRasterMosaicAgg(DatabaseInstance &db) {
AggregateFunctionSet st_mosaic_agg("ST_RasterMosaic_Agg");

auto fun01 = AggregateFunction::UnaryAggregate<RasterAggState, uintptr_t, uintptr_t, MosaicAggUnaryOperation>(
GeoTypes::RASTER(), GeoTypes::RASTER()
);
GeoTypes::RASTER(), GeoTypes::RASTER());
fun01.bind = BindRasterAggOperation;

st_mosaic_agg.AddFunction(fun01);

auto fun02 = AggregateFunction::BinaryAggregate<RasterAggState, uintptr_t, list_entry_t, uintptr_t, MosaicAggBinaryOperation>(
GeoTypes::RASTER(), LogicalType::LIST(LogicalType::VARCHAR), GeoTypes::RASTER()
);
auto fun02 = AggregateFunction::BinaryAggregate<RasterAggState, uintptr_t, list_entry_t, uintptr_t,
MosaicAggBinaryOperation>(
GeoTypes::RASTER(), LogicalType::LIST(LogicalType::VARCHAR), GeoTypes::RASTER());
fun02.bind = BindRasterAggOperation;

st_mosaic_agg.AddFunction(fun02);
Expand Down
15 changes: 5 additions & 10 deletions spatial/src/spatial/gdal/functions/aggregate/st_union_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ struct UnionAggUnaryOperation : RasterAggUnaryOperation {
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
RasterUnionFunction(state, target, finalize_data);
}

};

struct UnionAggBinaryOperation : RasterAggBinaryOperation {
Expand All @@ -64,7 +63,6 @@ struct UnionAggBinaryOperation : RasterAggBinaryOperation {
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
RasterUnionFunction(state, target, finalize_data);
}

};

//------------------------------------------------------------------------
Expand Down Expand Up @@ -96,9 +94,7 @@ static constexpr const char *DOC_EXAMPLE = R"(
;
)";

static constexpr DocTag DOC_TAGS[] = {
{"ext", "spatial"}, {"category", "aggregation"}
};
static constexpr DocTag DOC_TAGS[] = {{"ext", "spatial"}, {"category", "aggregation"}};

//------------------------------------------------------------------------
// Register
Expand All @@ -109,15 +105,14 @@ void GdalAggregateFunctions::RegisterStRasterUnionAgg(DatabaseInstance &db) {
AggregateFunctionSet st_union_agg("ST_RasterUnion_Agg");

auto fun01 = AggregateFunction::UnaryAggregate<RasterAggState, uintptr_t, uintptr_t, UnionAggUnaryOperation>(
GeoTypes::RASTER(), GeoTypes::RASTER()
);
GeoTypes::RASTER(), GeoTypes::RASTER());
fun01.bind = BindRasterAggOperation;

st_union_agg.AddFunction(fun01);

auto fun02 = AggregateFunction::BinaryAggregate<RasterAggState, uintptr_t, list_entry_t, uintptr_t, UnionAggBinaryOperation>(
GeoTypes::RASTER(), LogicalType::LIST(LogicalType::VARCHAR), GeoTypes::RASTER()
);
auto fun02 =
AggregateFunction::BinaryAggregate<RasterAggState, uintptr_t, list_entry_t, uintptr_t, UnionAggBinaryOperation>(
GeoTypes::RASTER(), LogicalType::LIST(LogicalType::VARCHAR), GeoTypes::RASTER());
fun02.bind = BindRasterAggOperation;

st_union_agg.AddFunction(fun02);
Expand Down
25 changes: 10 additions & 15 deletions spatial/src/spatial/gdal/functions/cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ namespace gdal {
//------------------------------------------------------------------------------

static bool RasterToVarcharCast(Vector &source, Vector &result, idx_t count, CastParameters &parameters) {
UnaryExecutor::Execute<uintptr_t, string_t>(source, result, count, [&](uintptr_t &input) {
return string_t("RASTER");
});
UnaryExecutor::Execute<uintptr_t, string_t>(source, result, count,
[&](uintptr_t &input) { return string_t("RASTER"); });
return true;
}

Expand Down Expand Up @@ -62,24 +61,20 @@ static bool RasterCoordToVarcharCast(Vector &source, Vector &result, idx_t count

void GdalCastFunctions::Register(DatabaseInstance &db) {

ExtensionUtil::RegisterCastFunction(db, GeoTypes::RASTER(), LogicalType::VARCHAR,
RasterToVarcharCast, 1);
ExtensionUtil::RegisterCastFunction(db, GeoTypes::RASTER(), LogicalType::VARCHAR, RasterToVarcharCast, 1);

ExtensionUtil::RegisterCastFunction(db, GeoTypes::RASTER(), GeoTypes::GEOMETRY(),
BoundCastInfo(RasterToGeometryCast, nullptr,
GeometryFunctionLocalState::InitCast), 1);
ExtensionUtil::RegisterCastFunction(
db, GeoTypes::RASTER(), GeoTypes::GEOMETRY(),
BoundCastInfo(RasterToGeometryCast, nullptr, GeometryFunctionLocalState::InitCast), 1);

// POINTER -> RASTER is implicitly castable
ExtensionUtil::RegisterCastFunction(db, LogicalType::POINTER, GeoTypes::RASTER(),
DefaultCasts::ReinterpretCast, 1);
ExtensionUtil::RegisterCastFunction(db, LogicalType::POINTER, GeoTypes::RASTER(), DefaultCasts::ReinterpretCast, 1);

// RASTER -> POINTER is implicitly castable
ExtensionUtil::RegisterCastFunction(db, GeoTypes::RASTER(), LogicalType::POINTER,
DefaultCasts::ReinterpretCast, 1);

ExtensionUtil::RegisterCastFunction(db, GeoTypes::RASTER_COORD(), LogicalType::VARCHAR,
RasterCoordToVarcharCast, 1);
ExtensionUtil::RegisterCastFunction(db, GeoTypes::RASTER(), LogicalType::POINTER, DefaultCasts::ReinterpretCast, 1);

ExtensionUtil::RegisterCastFunction(db, GeoTypes::RASTER_COORD(), LogicalType::VARCHAR, RasterCoordToVarcharCast,
1);
};

} // namespace gdal
Expand Down
Loading

0 comments on commit 9aef365

Please sign in to comment.