Loading...
Searching...
No Matches
multilinestring_range.cuh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022-2023, NVIDIA CORPORATION.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <cuspatial/cuda_utils.hpp>
20#include <cuspatial/detail/range/enumerate_range.cuh>
23#include <cuspatial/traits.hpp>
24#include <cuspatial/types.hpp>
25
26#include <rmm/cuda_stream_view.hpp>
27
28#include <thrust/pair.h>
29
30namespace cuspatial {
31
58template <typename GeometryIterator, typename PartIterator, typename VecIterator>
60 public:
61 using geometry_it_t = GeometryIterator;
62 using part_it_t = PartIterator;
63 using point_it_t = VecIterator;
64 using point_t = iterator_value_type<VecIterator>;
65 using element_t = iterator_vec_base_type<VecIterator>;
66
67 CUSPATIAL_HOST_DEVICE multilinestring_range(GeometryIterator geometry_begin,
68 GeometryIterator geometry_end,
69 PartIterator part_begin,
70 PartIterator part_end,
71 VecIterator points_begin,
72 VecIterator points_end);
73
75 CUSPATIAL_HOST_DEVICE auto size() { return num_multilinestrings(); }
76
78 CUSPATIAL_HOST_DEVICE auto num_multilinestrings();
79
81 CUSPATIAL_HOST_DEVICE auto num_linestrings();
82
84 CUSPATIAL_HOST_DEVICE auto num_points();
85
87 CUSPATIAL_HOST_DEVICE auto multilinestring_begin();
88
90 CUSPATIAL_HOST_DEVICE auto multilinestring_end();
91
93 CUSPATIAL_HOST_DEVICE auto begin() { return multilinestring_begin(); }
94
96 CUSPATIAL_HOST_DEVICE auto end() { return multilinestring_end(); }
97
99 CUSPATIAL_HOST_DEVICE auto point_begin() { return _point_begin; }
100
102 CUSPATIAL_HOST_DEVICE auto point_end() { return _point_end; }
103
105 CUSPATIAL_HOST_DEVICE auto geometry_offset_begin() { return _geometry_begin; }
106
108 CUSPATIAL_HOST_DEVICE auto geometry_offset_end() { return _geometry_end; }
109
111 CUSPATIAL_HOST_DEVICE auto part_offset_begin() { return _part_begin; }
112
114 CUSPATIAL_HOST_DEVICE auto part_offset_end() { return _part_end; }
115
117 template <typename IndexType>
118 CUSPATIAL_HOST_DEVICE auto part_idx_from_point_idx(IndexType point_idx);
119
122 template <typename IndexType>
123 CUSPATIAL_HOST_DEVICE
124 thrust::optional<typename thrust::iterator_traits<PartIterator>::difference_type>
125 part_idx_from_segment_idx(IndexType point_idx);
126
129 template <typename IndexType>
130 CUSPATIAL_HOST_DEVICE auto geometry_idx_from_part_idx(IndexType part_idx);
131
134 template <typename IndexType>
135 CUSPATIAL_HOST_DEVICE auto geometry_idx_from_point_idx(IndexType point_idx);
136
137 // Given index to a linestring, return the index of the linestring inside its multilinestring.
138 template <typename IndexType>
139 CUSPATIAL_HOST_DEVICE auto intra_part_idx(IndexType global_part_idx);
140
141 // Given index to a point, return the index of the point inside its linestring.
142 template <typename IndexType>
143 CUSPATIAL_HOST_DEVICE auto intra_point_idx(IndexType global_point_idx);
144
148 template <typename IndexType1, typename IndexType2>
149 CUSPATIAL_HOST_DEVICE bool is_valid_segment_id(IndexType1 segment_idx, IndexType2 part_idx);
150
152 template <typename IndexType>
153 CUSPATIAL_HOST_DEVICE auto segment(IndexType segment_idx);
154
156 CUSPATIAL_HOST_DEVICE auto multilinestring_point_count_begin();
157
159 CUSPATIAL_HOST_DEVICE auto multilinestring_point_count_end();
160
162 CUSPATIAL_HOST_DEVICE auto multilinestring_linestring_count_begin();
163
165 CUSPATIAL_HOST_DEVICE auto multilinestring_linestring_count_end();
166
170 auto _segments(rmm::cuda_stream_view);
171
173 template <typename IndexType>
174 CUSPATIAL_HOST_DEVICE auto operator[](IndexType multilinestring_idx);
175
177
181 CUSPATIAL_HOST_DEVICE auto as_multipoint_range();
182
183 protected:
184 GeometryIterator _geometry_begin;
185 GeometryIterator _geometry_end;
186 PartIterator _part_begin;
187 PartIterator _part_end;
188 VecIterator _point_begin;
189 VecIterator _point_end;
190
191 private:
194 template <typename IndexType>
195 CUSPATIAL_HOST_DEVICE auto _part_iter_from_point_idx(IndexType point_idx);
198 template <typename IndexType>
199 CUSPATIAL_HOST_DEVICE auto _geometry_iter_from_part_idx(IndexType part_idx);
200};
201
229template <typename GeometryIteratorDiffType,
230 typename PartIteratorDiffType,
231 typename VecIteratorDiffType,
232 typename GeometryIterator,
233 typename PartIterator,
234 typename VecIterator>
235auto make_multilinestring_range(GeometryIteratorDiffType num_multilinestrings,
236 GeometryIterator geometry_begin,
237 PartIteratorDiffType num_linestrings,
238 PartIterator part_begin,
239 VecIteratorDiffType num_points,
240 VecIterator point_begin)
241{
242 return multilinestring_range{geometry_begin,
243 geometry_begin + num_multilinestrings + 1,
244 part_begin,
245 part_begin + num_linestrings + 1,
246 point_begin,
247 point_begin + num_points};
248}
249
262template <typename IntegerRange1, typename IntegerRange2, typename PointRange>
263auto make_multilinestring_range(IntegerRange1 geometry_offsets,
264 IntegerRange2 part_offsets,
265 PointRange points)
266{
267 return multilinestring_range(geometry_offsets.begin(),
268 geometry_offsets.end(),
269 part_offsets.begin(),
270 part_offsets.end(),
271 points.begin(),
272 points.end());
273}
274
281template <collection_type_id Type,
282 typename T,
283 typename IndexType,
284 typename GeometryColumnView,
285 CUSPATIAL_ENABLE_IF(Type == collection_type_id::SINGLE)>
286auto make_multilinestring_range(GeometryColumnView const& linestrings_column)
287{
288 CUSPATIAL_EXPECTS(linestrings_column.geometry_type() == geometry_type_id::LINESTRING,
289 "Must be Linestring geometry type.");
290 auto geometry_iter = thrust::make_counting_iterator(0);
291 auto const& part_offsets = linestrings_column.offsets();
292 auto const& points_xy = linestrings_column.child().child(1); // Ignores x-y offset {0, 2, 4...}
293
294 auto points_it = make_vec_2d_iterator(points_xy.template begin<T>());
295
296 return multilinestring_range(geometry_iter,
297 geometry_iter + part_offsets.size(),
298 part_offsets.template begin<IndexType>(),
299 part_offsets.template end<IndexType>(),
300 points_it,
301 points_it + points_xy.size() / 2);
302}
303
310template <collection_type_id Type,
311 typename T,
312 typename IndexType,
313 CUSPATIAL_ENABLE_IF(Type == collection_type_id::MULTI),
314 typename GeometryColumnView>
315auto make_multilinestring_range(GeometryColumnView const& linestrings_column)
316{
317 CUSPATIAL_EXPECTS(linestrings_column.geometry_type() == geometry_type_id::LINESTRING,
318 "Must be Linestring geometry type.");
319 auto const& geometry_offsets = linestrings_column.offsets();
320 auto const& parts = linestrings_column.child();
321 auto const& part_offsets = parts.child(0);
322 auto const& points_xy = parts.child(1).child(1); // Ignores x-y offset {0, 2, 4...}
323
324 auto points_it = make_vec_2d_iterator(points_xy.template begin<T>());
325
326 return multilinestring_range(geometry_offsets.template begin<IndexType>(),
327 geometry_offsets.template end<IndexType>(),
328 part_offsets.template begin<IndexType>(),
329 part_offsets.template end<IndexType>(),
330 points_it,
331 points_it + points_xy.size() / 2);
332};
333
338} // namespace cuspatial
339
340#include <cuspatial/detail/range/multilinestring_range.cuh>
Non-owning range-based interface to multilinestring data.
CUSPATIAL_HOST_DEVICE auto multilinestring_point_count_begin()
Returns an iterator to the counts of points per multilinestring.
CUSPATIAL_HOST_DEVICE auto end()
Return the iterator to the one past the last multilinestring in the range.
CUSPATIAL_HOST_DEVICE auto multilinestring_linestring_count_end()
Returns an iterator to the counts of points per multilinestring.
CUSPATIAL_HOST_DEVICE auto size()
Return the number of multilinestrings in the array.
CUSPATIAL_HOST_DEVICE auto part_offset_end()
Return the iterator to the one past the last part offset in the range.
CUSPATIAL_HOST_DEVICE auto multilinestring_end()
Return the iterator to the one past the last multilinestring in the range.
CUSPATIAL_HOST_DEVICE auto geometry_idx_from_point_idx(IndexType point_idx)
CUSPATIAL_HOST_DEVICE auto part_idx_from_point_idx(IndexType point_idx)
Given the index of a point, return the part (linestring) index where the point locates.
CUSPATIAL_HOST_DEVICE bool is_valid_segment_id(IndexType1 segment_idx, IndexType2 part_idx)
CUSPATIAL_HOST_DEVICE auto geometry_offset_end()
Return the iterator to the one past the last geometry offset in the range.
CUSPATIAL_HOST_DEVICE auto multilinestring_linestring_count_begin()
Returns an iterator to the counts of points per multilinestring.
CUSPATIAL_HOST_DEVICE auto segment(IndexType segment_idx)
Returns the segment given a segment index.
CUSPATIAL_HOST_DEVICE thrust::optional< typename thrust::iterator_traits< PartIterator >::difference_type > part_idx_from_segment_idx(IndexType point_idx)
CUSPATIAL_HOST_DEVICE auto point_end()
Return the iterator to the one past the last point in the range.
CUSPATIAL_HOST_DEVICE auto num_multilinestrings()
Return the number of multilinestrings in the array.
CUSPATIAL_HOST_DEVICE auto multilinestring_point_count_end()
Returns an iterator to the counts of segments per multilinestring.
CUSPATIAL_HOST_DEVICE auto geometry_idx_from_part_idx(IndexType part_idx)
CUSPATIAL_HOST_DEVICE auto geometry_offset_begin()
Return the iterator to the first geometry offset in the range.
CUSPATIAL_HOST_DEVICE auto as_multipoint_range()
Range Casts.
CUSPATIAL_HOST_DEVICE auto point_begin()
Return the iterator to the first point in the range.
CUSPATIAL_HOST_DEVICE auto operator[](IndexType multilinestring_idx)
Returns the multilinestring_idxth multilinestring in the range.
CUSPATIAL_HOST_DEVICE auto num_points()
Return the total number of points in the array.
CUSPATIAL_HOST_DEVICE auto multilinestring_begin()
Return the iterator to the first multilinestring in the range.
CUSPATIAL_HOST_DEVICE auto num_linestrings()
Return the total number of linestrings in the array.
CUSPATIAL_HOST_DEVICE auto begin()
Return the iterator to the first multilinestring in the range.
CUSPATIAL_HOST_DEVICE auto part_offset_begin()
Return the iterator to the first part offset in the range.
#define CUSPATIAL_EXPECTS(cond, reason)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
Definition error.hpp:76
auto make_vec_2d_iterator(FirstIter first, SecondIter second)
Create an iterator to vec_2d data from two input iterators.
auto make_multilinestring_range(GeometryIteratorDiffType num_multilinestrings, GeometryIterator geometry_begin, PartIteratorDiffType num_linestrings, PartIterator part_begin, VecIteratorDiffType num_points, VecIterator point_begin)
Create a multilinestring_range object from size and start iterators.