Skip to content

Commit 4f2289f

Browse files
committed
update readme, add license, add st_makeline, st_flipcoordinates, fix nulls not being properly written in st_write
1 parent f9b1534 commit 4f2289f

File tree

10 files changed

+517
-16
lines changed

10 files changed

+517
-16
lines changed

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2018-2023 DuckDB Labs BV
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# DuckDB Spatial Extension
22

3+
🚧 WORK IN PROGRESS 🚧
4+
35
**Table of contents**
46
- [DuckDB Spatial Extension](#duckdb-spatial-extension)
57
- [What is this?](#what-is-this)
@@ -150,14 +152,14 @@ ON ST_Within(st_transform(dropoff_point, 'EPSG:4326', 'ESRI:102718'), end_zone.g
150152
</details>
151153

152154
We can export the joined table to a GeoJSONSeq file using the GDAL copy function, passing in a GDAL layer creation option.
153-
Since GeoJSON only supports a single geometry per feature, we need to use the `ST_Collect` function to combine the pickup and dropoff points into a single multi point geometry.
155+
Since GeoJSON only supports a single geometry per feature, we can use the `ST_MakeLine` function to combine the pickup and dropoff points into a single line geometry. The default coordinate reference system for GeoJSON is WGS84, but the coordinates are expected to be in longitude/latitude, so we need to flip the geometry using the `ST_FlipCoordinates` function.
154156

155157
```sql
156158
COPY (
157159
SELECT
158-
ST_AsWKB(ST_Collect([pickup_point, dropoff_point])) as wkb_geometry,
159-
start_zone,
160-
end_zone,
160+
ST_AsWKB(ST_FlipCoordinates(ST_MakeLine(pickup_point, dropoff_point))) as wkb_geometry,
161+
start_zone,
162+
end_zone,
161163
time::VARCHAR as trip_time
162164
FROM joined)
163165
TO 'joined.geojsonseq'
@@ -169,16 +171,16 @@ WITH (FORMAT GDAL, DRIVER 'GeoJSONSeq', LAYER_CREATION_OPTIONS 'WRITE_BBOX=YES')
169171
</summary>
170172

171173
```json
172-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:52:00" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.643515, -73.789923 ], [ 40.680395, -73.97608 ] ] } }
173-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:35:00" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.645422, -73.776445 ], [ 40.670782, -73.98427 ] ] } }
174-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:45:42" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.645065, -73.776878 ], [ 40.662571, -73.992153 ] ] } }
175-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:36:00" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.641508, -73.788028 ], [ 40.670927, -73.97584 ] ] } }
176-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:47:58" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.644749, -73.781855 ], [ 40.663663, -73.980129 ] ] } }
177-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:32:10" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.641559, -73.787494 ], [ 40.673479, -73.974694 ] ] } }
178-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:36:59" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.643342, -73.790138 ], [ 40.662379, -73.982721 ] ] } }
179-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:32:00" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.641248, -73.786952 ], [ 40.676237, -73.97421 ] ] } }
180-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:33:21" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.648514, -73.783892 ], [ 40.669721, -73.979283 ] ] } }
181-
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:35:45" }, "geometry": { "type": "MultiPoint", "coordinates": [ [ 40.645272, -73.776643 ], [ 40.66723, -73.978873 ] ] } }
174+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:52:00" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.789923, 40.643515 ], [ -73.97608, 40.680395 ] ] } }
175+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:35:00" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.776445, 40.645422 ], [ -73.98427, 40.670782 ] ] } }
176+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:45:42" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.776878, 40.645065 ], [ -73.992153, 40.662571 ] ] } }
177+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:36:00" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.788028, 40.641508 ], [ -73.97584, 40.670927 ] ] } }
178+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:47:58" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.781855, 40.644749 ], [ -73.980129, 40.663663 ] ] } }
179+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:32:10" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.787494, 40.641559 ], [ -73.974694, 40.673479 ] ] } }
180+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:36:59" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.790138, 40.643342 ], [ -73.982721, 40.662379 ] ] } }
181+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:32:00" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.786952, 40.641248 ], [ -73.97421, 40.676237 ] ] } }
182+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:33:21" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.783892, 40.648514 ], [ -73.979283, 40.669721 ] ] } }
183+
{ "type": "Feature", "properties": { "start_zone": "JFK Airport", "end_zone": "Park Slope", "trip_time": "00:35:45" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.776643, 40.645272 ], [ -73.978873, 40.66723 ] ] } }
182184
```
183185
</details>
184186

@@ -281,9 +283,11 @@ Again, please feel free to open an issue if there is a particular function you w
281283
| ST_DWithin | 🧭 | 🔄 | 🔄 | 🔄 | 🔄 (as POLYGON) |
282284
| ST_Envelope | 🧭 | 🔄 | 🔄 | 🔄 | 🔄 (as POLYGON) |
283285
| ST_Equals | 🧭 | 🔄 | 🔄 | 🔄 | 🔄 (as POLYGON) |
286+
| ST_FlipCoordinates | 🦆 | 🦆 | 🦆 | 🦆 | 🦆 |
284287
| ST_GeomFromText | 🧭 | 🔄 | 🔄 | 🔄 | 🔄 (as POLYGON) |
285288
| ST_GeomFromWKB | 🦆 | 🦆 | 🦆 | 🦆 | 🔄 (as POLYGON) |
286289
| ST_GeometryType | 🦆 | 🦆 | 🦆 | 🦆 | 🔄 (as POLYGON) |
290+
| ST_MakeLine | 🦆 | | 🦆 | | |
287291
| ST_Intersection | 🧭 | 🔄 | 🔄 | 🔄 | 🔄 (as POLYGON) |
288292
| ST_Intersects | 🧭 | 🔄 | 🔄 | 🔄 | 🔄 (as POLYGON) |
289293
| ST_IsClosed | 🧭 | 🔄 | 🔄 | 🔄 | 🔄 (as POLYGON) |

spatial/include/spatial/core/functions/scalar.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ struct CoreScalarFunctions {
1616
RegisterStCollect(context);
1717
RegisterStContains(context);
1818
RegisterStDistance(context);
19+
RegisterStFlipCoordinates(context);
1920
RegisterStGeometryType(context);
2021
RegisterStGeomFromWKB(context);
2122
RegisterStIsEmpty(context);
2223
RegisterStLength(context);
24+
RegisterStMakeLine(context);
2325
RegisterStPoint(context);
2426
RegisterStX(context);
2527
RegisterStY(context);
@@ -47,6 +49,9 @@ struct CoreScalarFunctions {
4749
// ST_Distance
4850
static void RegisterStDistance(ClientContext &context);
4951

52+
// ST_FlipCoordinates
53+
static void RegisterStFlipCoordinates(ClientContext &context);
54+
5055
// ST_GeometryType
5156
static void RegisterStGeometryType(ClientContext &context);
5257

@@ -59,6 +64,9 @@ struct CoreScalarFunctions {
5964
// ST_Length
6065
static void RegisterStLength(ClientContext &context);
6166

67+
// ST_MakeLine
68+
static void RegisterStMakeLine(ClientContext &context);
69+
6270
// ST_Point
6371
static void RegisterStPoint(ClientContext &context);
6472

spatial/src/spatial/core/functions/scalar/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ set(EXTENSION_SOURCES
77
${CMAKE_CURRENT_SOURCE_DIR}/st_collect.cpp
88
${CMAKE_CURRENT_SOURCE_DIR}/st_contains.cpp
99
${CMAKE_CURRENT_SOURCE_DIR}/st_distance.cpp
10+
${CMAKE_CURRENT_SOURCE_DIR}/st_flipcoordinates.cpp
1011
${CMAKE_CURRENT_SOURCE_DIR}/st_length.cpp
12+
${CMAKE_CURRENT_SOURCE_DIR}/st_makeline.cpp
1113
${CMAKE_CURRENT_SOURCE_DIR}/st_geometrytype.cpp
1214
${CMAKE_CURRENT_SOURCE_DIR}/st_geomfromwkb.cpp
1315
${CMAKE_CURRENT_SOURCE_DIR}/st_point.cpp

spatial/src/spatial/core/functions/scalar/st_collect.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ namespace spatial {
1212

1313
namespace core {
1414

15-
using namespace spatial::core;
16-
1715
static void CollectFunction(DataChunk &args, ExpressionState &state, Vector &result) {
1816
auto &lstate = GeometryFunctionLocalState::ResetAndGet(state);
1917
auto count = args.size();

0 commit comments

Comments
 (0)