19#include <cuspatial/cuda_utils.hpp>
20#include <cuspatial/detail/range/enumerate_range.cuh>
23#include <cuspatial/traits.hpp>
26#include <rmm/cuda_stream_view.hpp>
28#include <cuda/std/optional>
29#include <thrust/pair.h>
59template <
typename GeometryIterator,
typename PartIterator,
typename VecIterator>
60class multilinestring_range {
62 using geometry_it_t = GeometryIterator;
63 using part_it_t = PartIterator;
64 using point_it_t = VecIterator;
65 using point_t = iterator_value_type<VecIterator>;
66 using element_t = iterator_vec_base_type<VecIterator>;
68 CUSPATIAL_HOST_DEVICE multilinestring_range(GeometryIterator geometry_begin,
69 GeometryIterator geometry_end,
70 PartIterator part_begin,
71 PartIterator part_end,
72 VecIterator points_begin,
73 VecIterator points_end);
103 CUSPATIAL_HOST_DEVICE
auto point_end() {
return _point_end; }
118 template <
typename IndexType>
123 template <
typename IndexType>
124 CUSPATIAL_HOST_DEVICE
125 cuda::std::optional<typename thrust::iterator_traits<PartIterator>::difference_type>
130 template <
typename IndexType>
135 template <
typename IndexType>
139 template <
typename IndexType>
140 CUSPATIAL_HOST_DEVICE
auto intra_part_idx(IndexType global_part_idx);
143 template <
typename IndexType>
144 CUSPATIAL_HOST_DEVICE
auto intra_point_idx(IndexType global_point_idx);
149 template <
typename IndexType1,
typename IndexType2>
153 template <
typename IndexType>
154 CUSPATIAL_HOST_DEVICE
auto segment(IndexType segment_idx);
171 auto _segments(rmm::cuda_stream_view);
174 template <
typename IndexType>
175 CUSPATIAL_HOST_DEVICE
auto operator[](IndexType multilinestring_idx);
185 GeometryIterator _geometry_begin;
186 GeometryIterator _geometry_end;
187 PartIterator _part_begin;
188 PartIterator _part_end;
189 VecIterator _point_begin;
190 VecIterator _point_end;
195 template <
typename IndexType>
196 CUSPATIAL_HOST_DEVICE
auto _part_iter_from_point_idx(IndexType point_idx);
199 template <
typename IndexType>
200 CUSPATIAL_HOST_DEVICE
auto _geometry_iter_from_part_idx(IndexType part_idx);
230template <
typename GeometryIteratorDiffType,
231 typename PartIteratorDiffType,
232 typename VecIteratorDiffType,
233 typename GeometryIterator,
234 typename PartIterator,
235 typename VecIterator>
237 GeometryIterator geometry_begin,
238 PartIteratorDiffType num_linestrings,
239 PartIterator part_begin,
240 VecIteratorDiffType num_points,
241 VecIterator point_begin)
244 geometry_begin + num_multilinestrings + 1,
246 part_begin + num_linestrings + 1,
248 point_begin + num_points};
263template <
typename IntegerRange1,
typename IntegerRange2,
typename Po
intRange>
265 IntegerRange2 part_offsets,
269 geometry_offsets.end(),
270 part_offsets.begin(),
282template <collection_type_id Type,
285 typename GeometryColumnView,
286 CUSPATIAL_ENABLE_IF(Type == collection_type_id::SINGLE)>
289 CUSPATIAL_EXPECTS(linestrings_column.geometry_type() == geometry_type_id::LINESTRING,
290 "Must be Linestring geometry type.");
291 auto geometry_iter = thrust::make_counting_iterator(0);
292 auto const& part_offsets = linestrings_column.offsets();
293 auto const& points_xy = linestrings_column.child().child(1);
298 geometry_iter + part_offsets.size(),
299 part_offsets.template begin<IndexType>(),
300 part_offsets.template end<IndexType>(),
302 points_it + points_xy.size() / 2);
311template <collection_type_id Type,
314 CUSPATIAL_ENABLE_IF(Type == collection_type_id::MULTI),
315 typename GeometryColumnView>
316auto make_multilinestring_range(GeometryColumnView
const& linestrings_column)
318 CUSPATIAL_EXPECTS(linestrings_column.geometry_type() == geometry_type_id::LINESTRING,
319 "Must be Linestring geometry type.");
320 auto const& geometry_offsets = linestrings_column.offsets();
321 auto const& parts = linestrings_column.child();
322 auto const& part_offsets = parts.child(0);
323 auto const& points_xy = parts.child(1).child(1);
327 return multilinestring_range(geometry_offsets.template begin<IndexType>(),
328 geometry_offsets.template end<IndexType>(),
329 part_offsets.template begin<IndexType>(),
330 part_offsets.template end<IndexType>(),
332 points_it + points_xy.size() / 2);
341#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 cuda::std::optional< typename thrust::iterator_traits< PartIterator >::difference_type > part_idx_from_segment_idx(IndexType point_idx)
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 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.
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.