-
-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy pathgeom-functions.cpp
More file actions
866 lines (720 loc) · 25 KB
/
geom-functions.cpp
File metadata and controls
866 lines (720 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2026 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include "geom-functions.hpp"
#include "geom-boost-adaptor.hpp"
#include "overloaded.hpp"
#include "projection.hpp"
#include <algorithm>
#include <cmath>
#include <iterator>
#include <numeric>
#include <tuple>
#include <utility>
namespace geom {
double distance(point_t p1, point_t p2) noexcept
{
double const dx = p1.x() - p2.x();
double const dy = p1.y() - p2.y();
return std::sqrt(dx * dx + dy * dy);
}
point_t interpolate(point_t p1, point_t p2, double frac) noexcept
{
return point_t{frac * (p1.x() - p2.x()) + p2.x(),
frac * (p1.y() - p2.y()) + p2.y()};
}
/****************************************************************************/
std::string_view geometry_type(geometry_t const &geom)
{
using namespace std::literals::string_view_literals;
return geom.visit(overloaded{
[](geom::nullgeom_t const & /*input*/) { return "NULL"sv; },
[](geom::point_t const & /*input*/) { return "POINT"sv; },
[](geom::linestring_t const & /*input*/) { return "LINESTRING"sv; },
[](geom::polygon_t const & /*input*/) { return "POLYGON"sv; },
[](geom::multipoint_t const & /*input*/) { return "MULTIPOINT"sv; },
[](geom::multilinestring_t const & /*input*/) {
return "MULTILINESTRING"sv;
},
[](geom::multipolygon_t const & /*input*/) { return "MULTIPOLYGON"sv; },
[](geom::collection_t const & /*input*/) {
return "GEOMETRYCOLLECTION"sv;
}});
}
/****************************************************************************/
std::size_t num_geometries(geometry_t const &geom)
{
return geom.visit(
[](auto const &input) { return input.num_geometries(); });
}
/****************************************************************************/
namespace {
class geometry_n_visitor_t
{
public:
geometry_n_visitor_t(geometry_t *output, std::size_t n)
: m_output(output), m_n(n)
{}
void operator()(geom::collection_t const &input) const
{
*m_output = input[m_n];
}
template <typename T>
void operator()(geom::multigeometry_t<T> const &input) const
{
m_output->set<T>() = input[m_n];
}
template <typename T>
void operator()(T const &input) const
{
m_output->set<T>() = input;
}
private:
geometry_t *m_output;
std::size_t m_n;
}; // class geometry_n_visitor_t
} // anonymous namespace
void geometry_n(geometry_t *output, geometry_t const &input, std::size_t n)
{
auto const max = num_geometries(input);
if (n < 1 || n > max) {
output->reset();
return;
}
input.visit(geometry_n_visitor_t{output, n - 1});
output->set_srid(input.srid());
}
geometry_t geometry_n(geometry_t const &input, std::size_t n)
{
geom::geometry_t output{};
geometry_n(&output, input, n);
return output;
}
/****************************************************************************/
namespace {
void set_to_same_type(geometry_t *output, geometry_t const &input)
{
// NOLINTNEXTLINE(performance-unnecessary-value-param)
input.visit([&](auto in) { output->set<decltype(in)>(); });
}
class transform_visitor_t
{
public:
explicit transform_visitor_t(geometry_t *output,
reprojection_t const *reprojection)
: m_output(output), m_reprojection(reprojection)
{}
void operator()(nullgeom_t const & /*input*/) const {}
void operator()(point_t const &input) const
{
m_output->get<point_t>() = project(input);
}
void operator()(linestring_t const &input) const
{
transform_points(&m_output->get<linestring_t>(), input);
}
void operator()(polygon_t const &input) const
{
transform_polygon(&m_output->get<polygon_t>(), input);
}
void operator()(multipoint_t const &input) const
{
auto &mgeom = m_output->get<multipoint_t>();
mgeom.reserve(input.num_geometries());
for (auto const point : input) {
mgeom.add_geometry(project(point));
}
}
void operator()(multilinestring_t const &input) const
{
auto &mgeom = m_output->set<multilinestring_t>();
mgeom.reserve(input.num_geometries());
for (auto const &line : input) {
transform_points(&mgeom.add_geometry(), line);
}
}
void operator()(multipolygon_t const &input) const
{
auto &mgeom = m_output->set<multipolygon_t>();
mgeom.reserve(input.num_geometries());
for (auto const &polygon : input) {
transform_polygon(&mgeom.add_geometry(), polygon);
}
}
void operator()(collection_t const &input) const
{
auto &mgeom = m_output->get<collection_t>();
mgeom.reserve(input.num_geometries());
for (auto const &geom : input) {
auto &new_geom = mgeom.add_geometry();
set_to_same_type(&new_geom, geom);
new_geom.set_srid(0);
geom.visit(transform_visitor_t{&new_geom, m_reprojection});
}
}
private:
point_t project(point_t point) const
{
return m_reprojection->reproject(point);
}
void transform_points(point_list_t *output, point_list_t const &input) const
{
output->reserve(input.size());
for (auto const &point : input) {
output->push_back(project(point));
}
}
void transform_polygon(polygon_t *output, polygon_t const &input) const
{
transform_points(&output->outer(), input.outer());
output->inners().reserve(input.inners().size());
for (auto const &inner : input.inners()) {
auto &oring = output->inners().emplace_back();
transform_points(&oring, inner);
}
}
geometry_t *m_output;
reprojection_t const *m_reprojection;
}; // class transform_visitor_t
} // anonymous namespace
void transform(geometry_t *output, geometry_t const &input,
reprojection_t const &reprojection)
{
assert(input.srid() == PROJ_LATLONG);
set_to_same_type(output, input);
output->set_srid(reprojection.target_srs());
input.visit(transform_visitor_t{output, &reprojection});
}
geometry_t transform(geometry_t const &input,
reprojection_t const &reprojection)
{
geometry_t output;
transform(&output, input, reprojection);
return output;
}
/****************************************************************************/
namespace {
/**
* Helper class for iterating over all points except the first one in a point
* list.
*/
class without_first_t
{
public:
explicit without_first_t(point_list_t const &list) : m_list(&list) {}
point_list_t::const_iterator begin()
{
assert(m_list->cbegin() != m_list->cend());
return std::next(m_list->cbegin());
}
point_list_t::const_iterator end() { return m_list->end(); }
private:
point_list_t const *m_list;
}; // class without_first_t
void split_linestring(linestring_t const &line, double split_at,
multilinestring_t *output)
{
double dist = 0;
point_t prev_pt{line.front()};
linestring_t *out = &output->add_geometry();
out->push_back(prev_pt);
for (auto const &this_pt : without_first_t(line)) {
double const delta = distance(prev_pt, this_pt);
// figure out if the addition of this point would take the total
// length of the line in `segment` over the `split_at` distance.
if (dist + delta > split_at) {
auto const splits = (size_t)std::floor((dist + delta) / split_at);
// use the splitting distance to split the current segment up
// into as many parts as necessary to keep each part below
// the `split_at` distance.
point_t ipoint;
for (size_t j = 0; j < splits; ++j) {
double const frac = ((double)(j + 1) * split_at - dist) / delta;
ipoint = interpolate(this_pt, prev_pt, frac);
if (frac != 0.0) {
out->emplace_back(ipoint);
}
// start a new segment
out = &output->add_geometry();
out->emplace_back(ipoint);
}
// reset the distance based on the final splitting point for
// the next iteration.
if (this_pt == ipoint) {
dist = 0;
prev_pt = this_pt;
continue;
}
dist = distance(this_pt, ipoint);
} else {
dist += delta;
}
out->push_back(this_pt);
prev_pt = this_pt;
}
if (out->size() <= 1) {
output->remove_last();
}
}
} // anonymous namespace
void segmentize(geometry_t *output, geometry_t const &input,
double max_segment_length)
{
output->set_srid(input.srid());
auto *multilinestring = &output->set<multilinestring_t>();
if (input.is_linestring()) {
split_linestring(input.get<linestring_t>(), max_segment_length,
multilinestring);
} else if (input.is_multilinestring()) {
for (auto const &line : input.get<multilinestring_t>()) {
split_linestring(line, max_segment_length, multilinestring);
}
} else {
output->reset();
}
}
geometry_t segmentize(geometry_t const &input, double max_segment_length)
{
geometry_t output;
segmentize(&output, input, max_segment_length);
return output;
}
/****************************************************************************/
double area(geometry_t const &geom)
{
return std::abs(geom.visit(
overloaded{[](geom::nullgeom_t const & /*input*/) { return 0.0; },
[](geom::collection_t const &input) {
return std::accumulate(input.cbegin(), input.cend(), 0.0,
[](double sum, auto const &geom) {
return sum + area(geom);
});
},
[](auto const &input) {
return static_cast<double>(boost::geometry::area(input));
}}));
}
/****************************************************************************/
namespace {
double spherical_area(polygon_t const &geom)
{
boost::geometry::strategy::area::spherical<> const spherical_earth{
6371008.8};
using sph_point = boost::geometry::model::point<
double, 2,
boost::geometry::cs::spherical_equatorial<boost::geometry::degree>>;
boost::geometry::model::polygon<sph_point> sph_geom;
boost::geometry::convert(geom, sph_geom);
return boost::geometry::area(sph_geom, spherical_earth);
}
} // anonymous namespace
double spherical_area(geometry_t const &geom)
{
assert(geom.srid() == PROJ_LATLONG);
return std::abs(geom.visit(overloaded{
[](geom::nullgeom_t const & /*input*/) { return 0.0; },
[](geom::collection_t const &input) {
return std::accumulate(input.cbegin(), input.cend(), 0.0,
[](double sum, auto const &geom) {
return sum + spherical_area(geom);
});
},
[](geom::polygon_t const &input) { return spherical_area(input); },
[](geom::multipolygon_t const &input) {
return std::accumulate(input.cbegin(), input.cend(), 0.0,
[](double sum, auto const &geom) {
return sum + spherical_area(geom);
});
},
[](auto const & /*input*/) { return 0.0; }}));
}
/****************************************************************************/
double length(geometry_t const &geom)
{
return geom.visit(overloaded{
[](geom::nullgeom_t const & /*input*/) { return 0.0; },
[](geom::collection_t const &input) {
double total = 0.0;
for (auto const &item : input) {
total += length(item);
}
return total;
},
[](auto const &input) {
return static_cast<double>(boost::geometry::length(input));
}});
}
/****************************************************************************/
namespace {
class split_visitor_t
{
public:
split_visitor_t(std::vector<geometry_t> *output, int srid) noexcept
: m_output(output), m_srid(srid)
{}
template <typename T>
void operator()(T const &) const
{}
// false positive https://github.com/llvm/llvm-project/issues/74738
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
void operator()(geom::collection_t &&geom) const
{
for (auto &&sgeom : geom) {
m_output->push_back(std::move(sgeom));
}
}
template <typename T>
// false positive https://github.com/llvm/llvm-project/issues/74738
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
void operator()(geom::multigeometry_t<T> &&geom) const
{
for (auto &&sgeom : geom) {
m_output->emplace_back(std::move(sgeom), m_srid);
}
}
private:
std::vector<geometry_t> *m_output;
int m_srid;
}; // class split_visitor_t
} // anonymous namespace
std::vector<geometry_t> split_multi(geometry_t &&geom, bool split_multi)
{
std::vector<geometry_t> output;
if (split_multi && geom.is_multi()) {
visit(split_visitor_t{&output, geom.srid()}, std::move(geom));
} else if (!geom.is_null()) {
output.push_back(std::move(geom));
}
return output;
}
/****************************************************************************/
namespace {
void reverse(geom::nullgeom_t * /*output*/,
geom::nullgeom_t const & /*input*/) noexcept
{}
void reverse(geom::point_t *output, geom::point_t const &input) noexcept
{
*output = input;
}
void reverse(point_list_t *output, point_list_t const &input)
{
output->reserve(input.size());
std::reverse_copy(input.cbegin(), input.cend(),
std::back_inserter(*output));
}
void reverse(geom::polygon_t *output, geom::polygon_t const &input)
{
reverse(&output->outer(), input.outer());
for (auto const &g : input.inners()) {
reverse(&output->inners().emplace_back(), g);
}
}
template <typename T>
void reverse(geom::multigeometry_t<T> *output,
geom::multigeometry_t<T> const &input)
{
output->reserve(input.num_geometries());
for (auto const &g : input) {
reverse(&output->add_geometry(), g);
}
}
} // anonymous namespace
void reverse(geometry_t *output, geometry_t const &input)
{
output->set_srid(input.srid());
input.visit([&](auto const &geom) {
using inner_type =
std::remove_const_t<std::remove_reference_t<decltype(geom)>>;
return reverse(&output->set<inner_type>(), geom);
});
}
geometry_t reverse(geometry_t const &input)
{
geometry_t output;
reverse(&output, input);
return output;
}
/****************************************************************************/
namespace {
/**
* Add points specified by iterators to the linestring. If linestring is not
* empty, do not add the first point returned by *it.
*/
template <typename ITERATOR>
void add_nodes_to_linestring(
linestring_t *linestring, ITERATOR it,
ITERATOR end) // NOLINT(performance-unnecessary-value-param)
{
if (!linestring->empty()) {
assert(it != end);
++it;
}
while (it != end) {
linestring->push_back(*it);
++it;
}
}
} // anonymous namespace
void line_merge(geometry_t *output, geometry_t const &input)
{
if (input.is_linestring()) {
*output = input;
return;
}
if (!input.is_multilinestring()) {
output->reset();
return;
}
output->set_srid(input.srid());
auto &linestrings = output->set<multilinestring_t>();
// Make a list of all endpoints...
struct endpoint_t
{
point_t c;
std::size_t n;
bool is_front;
endpoint_t(point_t coords, std::size_t size, bool front) noexcept
: c(coords), n(size), is_front(front)
{}
bool operator==(endpoint_t const &rhs) const noexcept
{
return c == rhs.c;
}
bool operator<(endpoint_t const &rhs) const noexcept
{
return std::tuple<double, double, std::size_t, bool>{c.x(), c.y(),
n, is_front} <
std::tuple<double, double, std::size_t, bool>{
rhs.c.x(), rhs.c.y(), rhs.n, rhs.is_front};
}
};
std::vector<endpoint_t> endpoints;
// ...and a list of connections.
constexpr std::size_t NOCONN = std::numeric_limits<std::size_t>::max();
struct connection_t
{
std::size_t left = NOCONN;
linestring_t const *linestring;
std::size_t right = NOCONN;
explicit connection_t(linestring_t const *l) noexcept : linestring(l) {}
};
std::vector<connection_t> conns;
// Initialize the two lists.
for (auto const &line : input.get<multilinestring_t>()) {
endpoints.emplace_back(line.front(), conns.size(), true);
endpoints.emplace_back(line.back(), conns.size(), false);
conns.emplace_back(&line);
}
std::sort(endpoints.begin(), endpoints.end());
// Now fill the connection list based on the sorted enpoints list.
for (auto it = std::adjacent_find(endpoints.cbegin(), endpoints.cend());
it != endpoints.cend();
it = std::adjacent_find(it + 2, endpoints.cend())) {
auto const previd = it->n;
auto const ptid = std::next(it)->n;
if (it->is_front) {
conns[previd].left = ptid;
} else {
conns[previd].right = ptid;
}
if (std::next(it)->is_front) {
conns[ptid].left = previd;
} else {
conns[ptid].right = previd;
}
}
// First find all open ends and use them as starting points to assemble
// linestrings. Mark ways as "done" as we go.
std::size_t done_ways = 0;
std::size_t const todo_ways = conns.size();
for (std::size_t i = 0; i < todo_ways; ++i) {
if (!conns[i].linestring ||
(conns[i].left != NOCONN && conns[i].right != NOCONN)) {
continue; // way already done or not the beginning of a segment
}
linestring_t linestring;
{
std::size_t prev = NOCONN;
std::size_t cur = i;
do {
auto &conn = conns[cur];
assert(conn.linestring);
auto const &nl = *conn.linestring;
bool const forward = conn.left == prev;
prev = cur;
// add line
if (forward) {
add_nodes_to_linestring(&linestring, nl.cbegin(),
nl.cend());
cur = conn.right;
} else {
add_nodes_to_linestring(&linestring, nl.crbegin(),
nl.crend());
cur = conn.left;
}
// mark line as done
conns[prev].linestring = nullptr;
++done_ways;
} while (cur != NOCONN);
}
// found a line end
linestrings.add_geometry(std::move(linestring));
}
// If all ways have been "done", i.e. are part of a linestring now, we
// are finished.
if (done_ways < todo_ways) {
// oh dear, there must be circular ways without an end
// need to do the same shebang again
for (std::size_t i = 0; i < todo_ways; ++i) {
if (!conns[i].linestring) {
continue; // way already done
}
linestring_t linestring;
{
std::size_t prev = conns[i].left;
std::size_t cur = i;
do {
auto &conn = conns[cur];
assert(conn.linestring);
auto const &nl = *conn.linestring;
bool const forward =
(conn.left == prev &&
(!conns[conn.left].linestring ||
conns[conn.left].linestring->back() == nl.front()));
prev = cur;
if (forward) {
// add line forwards
add_nodes_to_linestring(&linestring, nl.cbegin(),
nl.cend());
cur = conn.right;
} else {
// add line backwards
add_nodes_to_linestring(&linestring, nl.crbegin(),
nl.crend());
cur = conn.left;
}
// mark line as done
conns[prev].linestring = nullptr;
} while (cur != i);
}
// found a line end
linestrings.add_geometry(std::move(linestring));
}
}
if (linestrings.num_geometries() == 0) {
output->reset();
}
}
geometry_t line_merge(geometry_t const &input)
{
geometry_t output;
line_merge(&output, input);
return output;
}
/****************************************************************************/
namespace {
/**
* This helper function is used to calculate centroids of geometry collections.
* It first creates a multi geometry that only contains the geometries of
* dimension N from the input collection. This is done by copying the geometry,
* which isn't very efficient, but hopefully the centroid of a geometry
* collection isn't used very often. This can be optimized if needed.
*
* Then the centroid of this new collection is calculated.
*
* Nested geometry collections are not allowed.
*/
template <std::size_t N, typename T>
void filtered_centroid(collection_t const &collection, point_t *center)
{
multigeometry_t<T> multi;
for (auto const &geom : collection) {
assert(!geom.is_collection());
if (!geom.is_null() && dimension(geom) == N) {
if (geom.is_multi()) {
for (auto const &sgeom : geom.get<multigeometry_t<T>>()) {
multi.add_geometry() = sgeom;
}
} else {
multi.add_geometry() = geom.get<T>();
}
}
}
boost::geometry::centroid(multi, *center);
}
} // anonymous namespace
geometry_t centroid(geometry_t const &geom)
{
geom::geometry_t output{point_t{}, geom.srid()};
auto ¢er = output.get<point_t>();
geom.visit(overloaded{
[&](geom::nullgeom_t const & /*input*/) { output.reset(); },
[&](geom::collection_t const &input) {
switch (dimension(input)) {
case 0:
filtered_centroid<0, point_t>(input, ¢er);
break;
case 1:
filtered_centroid<1, linestring_t>(input, ¢er);
break;
default: // 2
filtered_centroid<2, polygon_t>(input, ¢er);
break;
}
},
[&](auto const &input) { boost::geometry::centroid(input, center); }});
return output;
}
/****************************************************************************/
namespace {
bool simplify(linestring_t *output, linestring_t const &input, double tolerance)
{
boost::geometry::simplify(input, *output, tolerance);
// Linestrings with less then 2 points are invalid. Older boost::geometry
// versions will generate a "line" with two identical points. We are
// paranoid here and remove all duplicate points and then check that we
// have at least 2 points.
output->remove_duplicates();
return output->size() > 1;
}
bool simplify(multilinestring_t *output, multilinestring_t const &input,
double tolerance)
{
for (auto const &linestring : input) {
linestring_t simplified_ls;
if (simplify(&simplified_ls, linestring, tolerance)) {
output->add_geometry(std::move(simplified_ls));
}
}
return output->num_geometries() > 0;
}
template <typename T>
bool simplify(T * /*output*/, T const & /*input*/, double /*tolerance*/)
{
return false;
}
} // anonymous namespace
void simplify(geometry_t *output, geometry_t const &input, double tolerance)
{
output->set_srid(input.srid());
input.visit([&](auto const &input) {
using inner_type =
std::remove_const_t<std::remove_reference_t<decltype(input)>>;
auto &out = output->set<inner_type>();
if (!simplify(&out, input, tolerance)) {
output->reset();
}
});
}
geometry_t simplify(geometry_t const &input, double tolerance)
{
geom::geometry_t output{linestring_t{}, input.srid()};
simplify(&output, input, tolerance);
return output;
}
} // namespace geom