Closed marklit closed 1 year ago
Hi! Thanks for raising this issue. I've pushed a fix for this. If you're working with points you can cast to POINT_2D
and use that overload for the ST_Distance
function, which should still work, in the meantime.
That ::POINT_2D
trick works well, thank you. That said, the latest master branch isn't compiling atm.
$ git pull
$ GEN=ninja OPENSSL_ROOT_DIR=/usr/local/Cellar/openssl\@3/3.1.0/ make release
[10/193] Building CXX object extension/spatial/CMakeFiles/sp...xtension.dir/spatial/src/spatial/core/functions/common.cpp.
FAILED: extension/spatial/CMakeFiles/spatial_extension.dir/spatial/src/spatial/core/functions/common.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCURL_STATICLIB -DDUCKDB_BUILD_LIBRARY -DPROJ_DLL="" -I/Volumes/Seagate/duckdb_spatial/duckdb/src/include -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/fsst -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/fmt/include -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/hyperloglog -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/fastpforlib -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/fast_float -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/re2 -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/miniz -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/utf8proc/include -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/miniparquet -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/concurrentqueue -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/pcg -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/tdigest -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/mbedtls/include -I/Volumes/Seagate/duckdb_spatial/duckdb/third_party/jaro_winkler -I/Volumes/Seagate/duckdb_spatial/spatial/include -I/Volumes/Seagate/duckdb_spatial/spatial/third_party/ryu/include -I/Volumes/Seagate/duckdb_spatial/spatial/third_party/yyjson/include -isystem /Volumes/Seagate/duckdb_spatial/build/release/deps/local/include -isystem /Volumes/Seagate/duckdb_spatial/build/release/dependencies/local/include -isystem /Volumes/Seagate/duckdb_spatial/build/release/dependencies/local/include/geos -isystem /usr/local/Cellar/openssl@3/3.1.0/include -O3 -DNDEBUG -O3 -DNDEBUG -std=c++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -mmacosx-version-min=13.2 -fPIC -fcolor-diagnostics -MD -MT extension/spatial/CMakeFiles/spatial_extension.dir/spatial/src/spatial/core/functions/common.cpp.o -MF extension/spatial/CMakeFiles/spatial_extension.dir/spatial/src/spatial/core/functions/common.cpp.o.d -o extension/spatial/CMakeFiles/spatial_extension.dir/spatial/src/spatial/core/functions/common.cpp.o -c /Volumes/Seagate/duckdb_spatial/spatial/src/spatial/core/functions/common.cpp
In file included from /Volumes/Seagate/duckdb_spatial/spatial/src/spatial/core/functions/common.cpp:2:
/Volumes/Seagate/duckdb_spatial/spatial/include/spatial/core/functions/common.hpp:17:49: error: unknown type name 'CastLocalStateParameters'
static unique_ptr<FunctionLocalState> InitCast(CastLocalStateParameters &context);
^
/Volumes/Seagate/duckdb_spatial/spatial/src/spatial/core/functions/common.cpp:14:9: error: use of undeclared identifier 'make_uniq'; did you mean 'make_unique'?
return make_uniq<GeometryFunctionLocalState>(state.GetContext());
^~~~~~~~~
make_unique
/Volumes/Seagate/duckdb_spatial/duckdb/src/include/duckdb/common/helper.hpp:40:15: note: 'make_unique' declared here
unique_ptr<T> make_unique(Args &&... args) {
^
/Volumes/Seagate/duckdb_spatial/spatial/src/spatial/core/functions/common.cpp:14:9: warning: use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension [-Wc++20-extensions]
return make_uniq<GeometryFunctionLocalState>(state.GetContext());
^
/Volumes/Seagate/duckdb_spatial/spatial/src/spatial/core/functions/common.cpp:17:69: error: unknown type name 'CastLocalStateParameters'
unique_ptr<FunctionLocalState> GeometryFunctionLocalState::InitCast(CastLocalStateParameters ¶meters) {
^
/Volumes/Seagate/duckdb_spatial/spatial/src/spatial/core/functions/common.cpp:18:9: warning: use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension [-Wc++20-extensions]
return make_uniq<GeometryFunctionLocalState>(*parameters.context.get());
^
2 warnings and 3 errors generated.
[16/193] Building CXX object tools/sqlite3_api_wrapper/CMake..._sqlite3_api_wrapper.dir/test/test_sqlite3_api_wrapper.cpp.
ninja: build stopped: subcommand failed.
make: *** [release] Error 1
We now track the DuckDB master branch, so if you've cloned the repo previously you probably need to do a make pull
to pull the latest duckdb submodule.
I got the latest version to compile and I can confirm it's working now. Thank you for your help.
D SELECT
> ST_POINT(longitude::DOUBLE, latitude::DOUBLE) AS geom,
> ST_DISTANCE(geom, ST_POINT(-8.6, 41.1331))
> FROM read_csv('pt_ghcnd_stations.csv',
> auto_detect=True,
> header=False,
> columns={'station_id': 'VARCHAR',
> 'latitude': 'VARCHAR',
> 'longitude': 'VARCHAR',
> 'elevation': 'VARCHAR',
> 'station_name': 'VARCHAR',
> 'gsn': 'VARCHAR',
> 'wmo_id': 'VARCHAR'});
┌──────────────────────────┬────────────────────────────────────────────┐
│ geom │ st_distance(geom, st_point(-8.6, 41.1331)) │
│ geometry │ double │
├──────────────────────────┼────────────────────────────────────────────┤
│ POINT (-7.65 37.1167) │ 4.1272229113533445 │
│ POINT (-28.63 38.52) │ 20.199732463822386 │
│ POINT (-16.8997 32.63) │ 11.882244304002503 │
│ POINT (-9.15 38.7167) │ 2.478202768136615 │
│ POINT (-8.6 41.1331) │ 0.0 │
│ POINT (-8.4167 40.2) │ 0.9509334887361957 │
│ POINT (-7.8667 38.0167) │ 3.2015118069437123 │
│ POINT (-6.7331 41.8) │ 1.982440722947346 │
│ POINT (-8.47 41.96) │ 0.8370565154157771 │
│ POINT (-8.59 41.77) │ 0.6369785004221142 │
│ POINT (-8.6197 41.53) │ 0.397388600742399 │
│ POINT (-8.07 41.27) │ 0.547395295924253 │
│ POINT (-8.22 40.68) │ 0.5913540479272958 │
│ POINT (-7.54 40.81) │ 1.1081487309923688 │
│ POINT (-7.13 40.6) │ 1.5636801495190749 │
│ POINT (-8.7164 40.62) │ 0.5261374060072156 │
│ POINT (-31.131 39.455) │ 22.59340568860746 │
│ POINT (-25.698 37.741) │ 17.43123479303747 │
│ POINT (-25.171 36.971) │ 17.0856992075244 │
│ POINT (-16.767 32.683) │ 11.751769186382107 │
│ POINT (-16.35 33.073) │ 11.181579137581597 │
│ POINT (-8.467 40.15) │ 0.9920557494415323 │
│ POINT (-7.966 37.014) │ 4.167606124623579 │
│ POINT (-7.9 38.533) │ 2.692678965268602 │
│ POINT (-7.483 39.833) │ 1.7140446347747194 │
│ POINT (-27.3217 38.7303) │ 18.87526155394939 │
├──────────────────────────┴────────────────────────────────────────────┤
│ 26 rows 2 columns │
└───────────────────────────────────────────────────────────────────────┘
Any idea why I keep getting 1.0 for the distance calculation?