-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C++ Column API and Python API for `pairwise_linestring_intersecti…
…on` (#862) This PR adds column/python API for `pairwise_linestring_intersection`. Closes #648 This PR is also the first attempt of #261 , establishing `geometry_column_view` that inherits `cudf::column` and adds additional information to identify the underlying nested levels. Note that it cannot directly inherit from `cudf::lists::list_column_view`, because a point array isn't a `List<T>` array. Also note that the type codes defined in libcuspatial and cuspatial-python may be different, so there is a type code mapping after computing the result from libcuspaital. Finally, since `List<Union>` is currently unsupported in libcudf, the python API returns the geometries in two parts: `offset + GeoColumn`. Authors: - Michael Wang (https://github.com/isVoid) Approvers: - H. Thomson Comer (https://github.com/thomcom) - Mark Harris (https://github.com/harrism) URL: #862
- Loading branch information
Showing
23 changed files
with
1,529 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cuspatial/experimental/ranges/range.cuh> | ||
#include <cuspatial/types.hpp> | ||
|
||
#include <cudf/lists/lists_column_view.hpp> | ||
#include <cudf/types.hpp> | ||
|
||
namespace cuspatial { | ||
|
||
/** | ||
* @ingroup cuspatial_types | ||
* @brief A non-owning, immutable view of a geometry column. | ||
* | ||
* A geometry column is GeoArrow compliant, except that the data type for | ||
* the coordinates is List<T>, instead of FixedSizeList<T>[n_dim]. This is | ||
* because libcudf does not support FixedSizeList type. Currently, an | ||
* even sequence (0, 2, 4, ...) is used for the offsets of the coordinate | ||
* column. | ||
*/ | ||
class geometry_column_view : private cudf::lists_column_view { | ||
public: | ||
geometry_column_view(cudf::column_view const& column, | ||
collection_type_id collection_type, | ||
geometry_type_id geometry_type); | ||
geometry_column_view(geometry_column_view&&) = default; | ||
geometry_column_view(const geometry_column_view&) = default; | ||
~geometry_column_view() = default; | ||
|
||
geometry_column_view& operator=(geometry_column_view const&) = default; | ||
|
||
geometry_column_view& operator=(geometry_column_view&&) = default; | ||
|
||
geometry_type_id geometry_type() const { return _geometry_type; } | ||
|
||
collection_type_id collection_type() const { return _collection_type; } | ||
|
||
cudf::data_type coordinate_type() const; | ||
|
||
using cudf::lists_column_view::child; | ||
using cudf::lists_column_view::offsets; | ||
using cudf::lists_column_view::size; | ||
|
||
protected: | ||
collection_type_id _collection_type; | ||
geometry_type_id _geometry_type; | ||
}; | ||
|
||
} // namespace cuspatial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cuspatial/column/geometry_column_view.hpp> | ||
|
||
#include <cudf/column/column.hpp> | ||
|
||
#include <rmm/mr/device/device_memory_resource.hpp> | ||
|
||
namespace cuspatial { | ||
/** | ||
* @brief Result of linestring intersections | ||
* | ||
* Owning object to hold the result of linestring intersections. | ||
* The results are modeled after arrow type List<Union<Point, LineString>>, | ||
* with additional information about the indices where the intersection locates. | ||
*/ | ||
struct linestring_intersection_column_result { | ||
/// List offsets to the union column | ||
std::unique_ptr<cudf::column> geometry_collection_offset; | ||
|
||
/// Union Column Results | ||
std::unique_ptr<cudf::column> types_buffer; | ||
std::unique_ptr<cudf::column> offset_buffer; | ||
|
||
/// Child 0: Point Results as List Type Column | ||
std::unique_ptr<cudf::column> points; | ||
|
||
/// Child 1: Segment Results as List Type Column | ||
std::unique_ptr<cudf::column> segments; | ||
|
||
/// Look-back Indices | ||
std::unique_ptr<cudf::column> lhs_linestring_id; | ||
std::unique_ptr<cudf::column> lhs_segment_id; | ||
std::unique_ptr<cudf::column> rhs_linestring_id; | ||
std::unique_ptr<cudf::column> rhs_segment_id; | ||
}; | ||
|
||
linestring_intersection_column_result pairwise_linestring_intersection( | ||
geometry_column_view const& multilinestrings_lhs, | ||
geometry_column_view const& multilinestrings_rhs, | ||
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); | ||
|
||
} // namespace cuspatial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace cuspatial { | ||
|
||
/** | ||
* @brief The underlying geometry type of a geometry_column_view. | ||
*/ | ||
enum class geometry_type_id : uint8_t { POINT, LINESTRING, POLYGON }; | ||
|
||
/** | ||
* @brief The underlying collection type of a geometry_column_view. | ||
*/ | ||
enum class collection_type_id : uint8_t { SINGLE, MULTI }; | ||
|
||
} // namespace cuspatial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <cuspatial/column/geometry_column_view.hpp> | ||
#include <cuspatial/error.hpp> | ||
#include <cuspatial/types.hpp> | ||
|
||
#include <cudf/column/column_view.hpp> | ||
#include <cudf/lists/lists_column_view.hpp> | ||
#include <cudf/types.hpp> | ||
|
||
namespace cuspatial { | ||
|
||
namespace { | ||
|
||
/** | ||
* @brief Retrieve the leaf column type of the LIST column. | ||
* @internal | ||
* | ||
* @param column The LIST column to retrieve leaf column type. | ||
* @return cudf type of the leaf column | ||
*/ | ||
cudf::data_type leaf_data_type(cudf::column_view const& column) | ||
{ | ||
if (column.type() != cudf::data_type{cudf::type_id::LIST}) return column.type(); | ||
return leaf_data_type(column.child(cudf::lists_column_view::child_column_index)); | ||
} | ||
|
||
} // namespace | ||
|
||
geometry_column_view::geometry_column_view(cudf::column_view const& column, | ||
collection_type_id collection_type, | ||
geometry_type_id geometry_type) | ||
: cudf::lists_column_view(column), | ||
_collection_type(collection_type), | ||
_geometry_type(geometry_type) | ||
{ | ||
} | ||
|
||
cudf::data_type geometry_column_view::coordinate_type() const { return leaf_data_type(child()); } | ||
} // namespace cuspatial |
Oops, something went wrong.