Skip to content

Commit

Permalink
Merge pull request #271 from Maxxen/dev
Browse files Browse the repository at this point in the history
Misc Fixes
  • Loading branch information
Maxxen authored Feb 28, 2024
2 parents 09e8781 + 64d0e18 commit c59f064
Show file tree
Hide file tree
Showing 13 changed files with 298 additions and 195 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ concurrency:
jobs:
duckdb-stable-build:
name: Build extension binaries
uses: duckdb/duckdb/.github/workflows/_extension_distribution.yml@3fbbd15390059b8028ad6dfd56a3172e5ebc0ab8
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
with:
vcpkg_commit: a42af01b72c28a8e1d7b48107b33e4f286a55ef6
duckdb_version: main
extension_name: spatial

duckdb-stable-deploy:
name: Deploy extension binaries
needs: duckdb-stable-build
uses: duckdb/duckdb/.github/workflows/_extension_deploy.yml@3fbbd15390059b8028ad6dfd56a3172e5ebc0ab8
uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@main
secrets: inherit
with:
duckdb_version: main
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/StableDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ concurrency:
jobs:
duckdb-stable-build:
name: Build extension binaries
uses: duckdb/duckdb/.github/workflows/_extension_distribution.yml@3fbbd15390059b8028ad6dfd56a3172e5ebc0ab8
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v0.10.0
with:
vcpkg_commit: a42af01b72c28a8e1d7b48107b33e4f286a55ef6
duckdb_version: v0.10.0
extension_name: spatial

duckdb-stable-deploy:
name: Deploy extension binaries
needs: duckdb-stable-build
uses: duckdb/duckdb/.github/workflows/_extension_deploy.yml@3fbbd15390059b8028ad6dfd56a3172e5ebc0ab8
uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@v0.10.0
secrets: inherit
with:
duckdb_version: v0.10.0
Expand Down
62 changes: 32 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,41 @@ add_library(${EXTENSION_NAME} STATIC ${EXTENSION_SOURCES})
# link to their own dependencies if they are building locally. If they have a
# local (compatible) GDAL installation, we should use that instead of building
# our own. (unless a static build is requested)
execute_process(
# Generate project
COMMAND
${CMAKE_COMMAND} -G ${CMAKE_GENERATOR}
-DDUCKDB_ENABLE_DEPRECATED_API=1
-DWASM_LOADABLE_EXTENSIONS=1
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DOSX_BUILD_ARCH=${OSX_BUILD_ARCH}
-DSPATIAL_USE_NETWORK=${SPATIAL_USE_NETWORK}
-DOPENSSL_ROOT_DIR=$ENV{OPENSSL_ROOT_DIR}
-DVCPKG_MANIFEST_DIR='${VCPKG_MANIFEST_DIR}'
-DVCPKG_INSTALLED_DIR='${CMAKE_BINARY_DIR}/vcpkg_installed'
-DCMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'
-DVCPKG_TARGET_TRIPLET='${VCPKG_TARGET_TRIPLET}'
-S ${CMAKE_CURRENT_SOURCE_DIR}/deps -B ${CMAKE_BINARY_DIR}/deps
RESULT_VARIABLE DEPENDENCIES_GENERATE_RESULT)
if(NOT DEPENDENCIES_GENERATE_RESULT EQUAL 0)
message(FATAL_ERROR "Could not generate dependencies project")
endif()
execute_process(
# Build project
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/deps --config
${CMAKE_BUILD_TYPE} RESULT_VARIABLE DEPENDENCIES_BUILD_RESULT)
if(NOT DEPENDENCIES_BUILD_RESULT EQUAL 0)
message(FATAL_ERROR "Could not build dependencies project")

if(NOT EXISTS ${CMAKE_BINARY_DIR}/deps)
execute_process(
# Generate project
COMMAND
${CMAKE_COMMAND} -G ${CMAKE_GENERATOR}
-DDUCKDB_ENABLE_DEPRECATED_API=1
-DWASM_LOADABLE_EXTENSIONS=1
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DOSX_BUILD_ARCH=${OSX_BUILD_ARCH}
-DSPATIAL_USE_NETWORK=${SPATIAL_USE_NETWORK}
-DOPENSSL_ROOT_DIR=$ENV{OPENSSL_ROOT_DIR}
-DVCPKG_MANIFEST_DIR='${VCPKG_MANIFEST_DIR}'
-DVCPKG_INSTALLED_DIR='${CMAKE_BINARY_DIR}/vcpkg_installed'
-DCMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'
-DVCPKG_TARGET_TRIPLET='${VCPKG_TARGET_TRIPLET}'
-S ${CMAKE_CURRENT_SOURCE_DIR}/deps -B ${CMAKE_BINARY_DIR}/deps
RESULT_VARIABLE DEPENDENCIES_GENERATE_RESULT)
if(NOT DEPENDENCIES_GENERATE_RESULT EQUAL 0)
message(FATAL_ERROR "Could not generate dependencies project")
endif()

execute_process(
# Build project
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/deps --config
${CMAKE_BUILD_TYPE} RESULT_VARIABLE DEPENDENCIES_BUILD_RESULT)
if(NOT DEPENDENCIES_BUILD_RESULT EQUAL 0)
message(FATAL_ERROR "Could not build dependencies project")
endif()
endif()

# Add dependencies
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}
${CMAKE_BINARY_DIR}/deps/local)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} MD.lib
)# annoyingly for expat on windows
# annoyingly for expat on windows
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} MD.lib)

# Add dependencies
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_BINARY_DIR}/deps/local/")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/deps/local/")

Expand Down
43 changes: 42 additions & 1 deletion docs/src/functions/scalar/st_buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@
"type": "INTEGER"
}
]
},
{
"returns": "GEOMETRY",
"parameters": [
{
"name": "geom",
"type": "GEOMETRY"
},
{
"name": "distance",
"type": "DOUBLE"
},
{
"name": "num_triangles",
"type": "INTEGER"
},
{
"name": "cap_style",
"type": "STRING"
}
{
"name": "join_style",
"type": "STRING"
}
{
"name": "mitre_limit",
"type": "DOUBLE"
}
]
}
],
"summary": "Returns a buffer around the input geometry at the target distance"
Expand All @@ -41,7 +70,19 @@

### Description

TODO
`geom` is the input geometry.

`distance` is the target distance for the buffer, using the same units as the input geometry.

`num_triangles` represents how many triangles that will be produced to approximate a quarter circle. The larger the number, the smoother the resulting geometry. The default value is 8.

`join_style` must be one of "JOIN_ROUND", "JOIN_MITRE", "JOIN_BEVEL". This parameter is case-insensitive.

`cap_style` must be one of "CAP_ROUND", "CAP_FLAT", "CAP_SQUARE". This parameter is case-insensitive.

`mite_limit` only applies when `join_style` is "JOIN_MITRE". It is the ratio of the distance from the corner to the miter point to the corner radius. The default value is 1.0.

This is a planar operation and will not take into account the curvature of the earth.

### Examples

Expand Down
2 changes: 2 additions & 0 deletions spatial/include/spatial/core/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct GeoTypes {
static LogicalType WKB_BLOB();

static void Register(DatabaseInstance &db);

static LogicalType CreateEnumType(const string &name, const vector<string> &members);
};

enum class Side { LEFT, RIGHT, ON };
Expand Down
13 changes: 2 additions & 11 deletions spatial/src/spatial/core/functions/scalar/st_geometrytype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "spatial/common.hpp"
#include "spatial/core/functions/scalar.hpp"
#include "spatial/core/geometry/geometry.hpp"
#include "spatial/core/geometry/geometry_factory.hpp"
#include "spatial/core/functions/common.hpp"
#include "spatial/core/types.hpp"

Expand All @@ -14,20 +13,12 @@ static unique_ptr<FunctionData> GeometryTypeFunctionBind(ClientContext &context,
vector<unique_ptr<Expression>> &arguments) {
// Create an enum type for all geometry types
// Ensure that these are in the same order as the GeometryType enum
vector<string_t> enum_values = {"POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING", "MULTIPOLYGON",
vector<string> enum_values = {"POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING", "MULTIPOLYGON",
"GEOMETRYCOLLECTION",
// or...
"UNKNOWN"};

auto varchar_vector = Vector(LogicalType::VARCHAR, enum_values.size());
auto varchar_data = FlatVector::GetData<string_t>(varchar_vector);
for (idx_t i = 0; i < enum_values.size(); i++) {
auto str = enum_values[i];
varchar_data[i] = str.IsInlined() ? str : StringVector::AddString(varchar_vector, str);
}
auto enum_type = LogicalType::ENUM("GEOMETRY_TYPE", varchar_vector, enum_values.size());
enum_type.SetAlias("GEOMETRY_TYPE");
bound_function.return_type = enum_type;
bound_function.return_type = GeoTypes::CreateEnumType("GEOMETRY_TYPE", enum_values);

return nullptr;
}
Expand Down
12 changes: 12 additions & 0 deletions spatial/src/spatial/core/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ LogicalType GeoTypes::WKB_BLOB() {
return blob_type;
}

LogicalType GeoTypes::CreateEnumType(const string &name, const vector<string> &members) {
auto varchar_vector = Vector(LogicalType::VARCHAR, members.size());
auto varchar_data = FlatVector::GetData<string_t>(varchar_vector);
for (idx_t i = 0; i < members.size(); i++) {
auto str = string_t(members[i]);
varchar_data[i] = str.IsInlined() ? str : StringVector::AddString(varchar_vector, str);
}
auto enum_type = LogicalType::ENUM(name, varchar_vector, members.size());
enum_type.SetAlias(name);
return enum_type;
}

void GeoTypes::Register(DatabaseInstance &db) {

// POINT_2D
Expand Down
29 changes: 24 additions & 5 deletions spatial/src/spatial/gdal/file_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class DuckDBFileHandle : public VSIVirtualHandle {
return static_cast<vsi_l_offset>(file_handle->SeekPosition());
}
int Seek(vsi_l_offset nOffset, int nWhence) override {
if(nWhence == SEEK_SET && nOffset == 0) {
// Use the reset function instead to allow compressed file handles to rewind
// even if they don't support seeking
file_handle->Reset();
return 0;
}
switch (nWhence) {
case SEEK_SET:
file_handle->Seek(nOffset);
Expand Down Expand Up @@ -161,13 +167,26 @@ class DuckDBFileSystemHandler : public VSIFilesystemHandler {
return new DuckDBFileHandle(std::move(file));
}
#endif
auto file = fs.OpenFile(file_name, flags);
auto file = fs.OpenFile(file_name, flags, FileSystem::DEFAULT_LOCK, FileCompressionType::AUTO_DETECT);
return new DuckDBFileHandle(std::move(file));
} catch (std::exception &ex) {
if (bSetError) {
VSIError(VSIE_FileError, "Failed to open file %s: %s", file_name, ex.what());
// Failed to open file via DuckDB File System. If this doesnt have a VSI prefix we can return an error here.
if (strncmp(file_name, "/vsi", 4) != 0) {
if (bSetError) {
VSIError(VSIE_FileError, "Failed to open file %s: %s", file_name, ex.what());
}
return nullptr;
}
return nullptr;
// Fall back to GDAL instead
auto handler = VSIFileManager::GetHandler(file_name);
if(handler) {
return handler->Open(file_name, access);
} else {
if (bSetError) {
VSIError(VSIE_FileError, "Failed to open file %s: %s", file_name, ex.what());
}
return nullptr;
}
}
}

Expand All @@ -190,7 +209,7 @@ class DuckDBFileSystemHandler : public VSIFilesystemHandler {

unique_ptr<FileHandle> file;
try {
file = fs.OpenFile(file_name, FileFlags::FILE_FLAGS_READ);
file = fs.OpenFile(file_name, FileFlags::FILE_FLAGS_READ, FileSystem::DEFAULT_LOCK, FileCompressionType::AUTO_DETECT);
} catch (std::exception &ex) {
return -1;
}
Expand Down
Loading

0 comments on commit c59f064

Please sign in to comment.