MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / read_geometry

Function read_geometry

nodedb-spatial/src/wkb.rs:147–228  ·  view source on GitHub ↗
(data: &[u8], cursor: &mut usize)

Source from the content-addressed store, hash-verified

145// ── Read helpers ──
146
147fn read_geometry(data: &[u8], cursor: &mut usize) -> Option<Geometry> {
148 let byte_order = read_u8(data, cursor)?;
149 let is_le = byte_order == 1;
150 let wkb_type = read_u32(data, cursor, is_le)?;
151
152 match wkb_type {
153 WKB_POINT => {
154 let x = read_f64(data, cursor, is_le)?;
155 let y = read_f64(data, cursor, is_le)?;
156 Some(Geometry::Point {
157 coordinates: [x, y],
158 })
159 }
160 WKB_LINESTRING => {
161 let n = read_u32(data, cursor, is_le)? as usize;
162 let coords = read_coords(data, cursor, n, is_le)?;
163 Some(Geometry::LineString {
164 coordinates: coords,
165 })
166 }
167 WKB_POLYGON => {
168 let num_rings = read_u32(data, cursor, is_le)? as usize;
169 let mut rings = Vec::with_capacity(num_rings);
170 for _ in 0..num_rings {
171 let n = read_u32(data, cursor, is_le)? as usize;
172 let ring = read_coords(data, cursor, n, is_le)?;
173 rings.push(ring);
174 }
175 Some(Geometry::Polygon { coordinates: rings })
176 }
177 WKB_MULTIPOINT => {
178 let count = read_u32(data, cursor, is_le)? as usize;
179 let mut coords = Vec::with_capacity(count);
180 for _ in 0..count {
181 let inner = read_geometry(data, cursor)?;
182 if let Geometry::Point { coordinates } = inner {
183 coords.push(coordinates);
184 } else {
185 return None;
186 }
187 }
188 Some(Geometry::MultiPoint {
189 coordinates: coords,
190 })
191 }
192 WKB_MULTILINESTRING => {
193 let count = read_u32(data, cursor, is_le)? as usize;
194 let mut lines = Vec::with_capacity(count);
195 for _ in 0..count {
196 let inner = read_geometry(data, cursor)?;
197 if let Geometry::LineString { coordinates } = inner {
198 lines.push(coordinates);
199 } else {
200 return None;
201 }
202 }
203 Some(Geometry::MultiLineString { coordinates: lines })
204 }

Callers 1

geometry_from_wkbFunction · 0.85

Calls 5

read_u8Function · 0.85
read_u32Function · 0.85
read_coordsFunction · 0.85
read_f64Function · 0.70
pushMethod · 0.45

Tested by

no test coverage detected