MultiLineString.cpp
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
8 
9 namespace f2c::types {
10 
12  data_ = std::shared_ptr<OGRMultiLineString>(static_cast<OGRMultiLineString*>(
13  OGRGeometryFactory::createGeometry(wkbMultiLineString)),
14  [](OGRMultiLineString* f) {OGRGeometryFactory::destroyGeometry(f);});
15 }
16 
17 MultiLineString::MultiLineString(const OGRGeometry* geom) {
18  this->append(geom);
19 }
20 
22  this->addGeometry(line);
23 }
24 
25 MultiLineString::MultiLineString(const std::initializer_list<LineString>& ls) {
26  for (auto&& line : ls) {
27  this->addGeometry(line);
28  }
29 }
30 
31 size_t MultiLineString::size() const {
32  return isEmpty() ? 0 : data_->getNumGeometries();
33 }
34 
35 double MultiLineString::length() const {
36  return this->data_->get_Length();
37 }
38 
40  for (auto&& r : *this) {
41  r *= b;
42  }
43 }
44 
45 void MultiLineString::append(const OGRGeometry* geom) {
46  if (wkbFlatten(geom->getGeometryType()) ==
47  OGRwkbGeometryType::wkbLineString) {
48  if (!geom->IsEmpty()) {
49  data_->addGeometry(geom);
50  }
51  } else if (wkbFlatten(geom->getGeometryType()) ==
52  OGRwkbGeometryType::wkbMultiLineString) {
53  for (auto&& line : *geom->toMultiLineString()) {
54  data_->addGeometry(line);
55  }
56  } else if (wkbFlatten(geom->getGeometryType()) ==
57  OGRwkbGeometryType::wkbPolygon) {
58  for (auto&& ring : *geom->toPolygon()) {
59  data_->addGeometry(ring);
60  }
61  } else if (wkbFlatten(geom->getGeometryType()) ==
62  OGRwkbGeometryType::wkbMultiPolygon) {
63  for (auto&& poly : *geom->toMultiPolygon()) {
64  for (auto&& ring : poly) {
65  data_->addGeometry(ring);
66  }
67  }
68  }
69 }
70 
72  if (i >= this->size()) {
73  throw std::out_of_range(
74  "Geometry does not contain point " + std::to_string(i));
75  }
76  line = LineString(this->data_->getGeometryRef(i), EmptyDestructor());
77 }
78 
79 void MultiLineString::getGeometry(size_t i, LineString& line) const {
80  if (i >= this->size()) {
81  throw std::out_of_range(
82  "Geometry does not contain point " + std::to_string(i));
83  }
84  line = LineString(this->data_->getGeometryRef(i), EmptyDestructor());
85 }
86 
88  if (i >= this->size()) {
89  throw std::out_of_range(
90  "Geometry does not contain point " + std::to_string(i));
91  }
92  return LineString(this->data_->getGeometryRef(i));
93 }
94 
96  if (i >= this->size()) {
97  throw std::out_of_range(
98  "Geometry does not contain point " + std::to_string(i));
99  }
100  return LineString(this->data_->getGeometryRef(i));
101 }
102 
103 void MultiLineString::setGeometry(size_t i, const LineString& line) {
104  auto n = this->size();
105  if (i < n) {
107  for (size_t j = 0; j < n; ++j) {
108  lines.addGeometry((i == j) ? line : this->getGeometry(j));
109  }
110  *this = lines;
111  return;
112  } else if (i != n) {
113  for (size_t j = n; j < i; ++j) {
114  this->addGeometry(LineString());
115  }
116  }
117  this->addGeometry(line);
118 }
119 
121  this->data_->addGeometry(line.get());
122 }
123 
125  for (auto&& line : lines) {
126  addGeometry(line);
127  }
128 }
129 
131  MultiLineString res;
132  for (size_t i = 0; i < line.size()-1; ++i) {
133  res.addGeometry(LineString({line.getGeometry(i), line.getGeometry(i+1)}));
134  }
135  return res;
136 }
137 
139  return getLineSegments(LineString(line));
140 }
141 
142 } // namespace f2c::types
143 
f2c::types::MultiLineString::append
void append(const OGRGeometry *geom)
Definition: MultiLineString.cpp:45
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::LineString::getGeometry
void getGeometry(size_t i, Point &point)
Definition: LineString.cpp:54
f2c::types::MultiLineString
Definition: MultiLineString.h:18
f2c::types::LinearRing
Definition: LinearRing.h:18
f2c::types::MultiLineString::getLineSegments
static MultiLineString getLineSegments(const LineString &line)
Definition: MultiLineString.cpp:130
f2c::types::Geometry< OGRMultiLineString, R >::isEmpty
bool isEmpty() const
Definition: Geometry_impl.hpp:222
1_basic_types.ring
ring
Definition: 1_basic_types.py:68
f2c::types::Geometry::get
T * get()
Definition: Geometry_impl.hpp:71
f2c::types::LineString
Definition: LineString.h:19
f2c::types::MultiLineString::size
size_t size() const
Definition: MultiLineString.cpp:31
f2c::types::MultiLineString::getGeometry
void getGeometry(size_t i, LineString &line)
Definition: MultiLineString.cpp:71
MultiLineString.h
f2c::types::MultiLineString::operator*=
void operator*=(double b)
Definition: MultiLineString.cpp:39
f2c::types::MultiLineString::MultiLineString
MultiLineString()
Definition: MultiLineString.cpp:11
f2c::types::MultiLineString::setGeometry
void setGeometry(size_t i, const LineString &line)
Definition: MultiLineString.cpp:103
f2c::types::LineString::size
size_t size() const
Definition: LineString.cpp:49
f2c::types::Geometry< OGRMultiLineString, R >::data_
std::shared_ptr< OGRMultiLineString > data_
Definition: Geometry.h:129
f2c::types::EmptyDestructor
Definition: Geometry.h:23
1_basic_types.lines
lines
Definition: 1_basic_types.py:73
f2c::types::MultiLineString::length
double length() const
Definition: MultiLineString.cpp:35
f2c::types::MultiLineString::addGeometry
void addGeometry(const LineString &line)
Definition: MultiLineString.cpp:120
f2c::types::to_string
std::string to_string(double d, const int precision=6)
Definition: Path.cpp:274


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31