(buf: &mut Vec<u8>, geom: &Geometry)
| 54 | // ── Write helpers ── |
| 55 | |
| 56 | fn write_geometry(buf: &mut Vec<u8>, geom: &Geometry) { |
| 57 | match geom { |
| 58 | Geometry::Point { coordinates } => { |
| 59 | write_header(buf, WKB_POINT); |
| 60 | write_f64(buf, coordinates[0]); |
| 61 | write_f64(buf, coordinates[1]); |
| 62 | } |
| 63 | Geometry::LineString { coordinates } => { |
| 64 | write_header(buf, WKB_LINESTRING); |
| 65 | write_u32(buf, coordinates.len() as u32); |
| 66 | for c in coordinates { |
| 67 | write_f64(buf, c[0]); |
| 68 | write_f64(buf, c[1]); |
| 69 | } |
| 70 | } |
| 71 | Geometry::Polygon { coordinates } => { |
| 72 | write_header(buf, WKB_POLYGON); |
| 73 | write_u32(buf, coordinates.len() as u32); |
| 74 | for ring in coordinates { |
| 75 | write_u32(buf, ring.len() as u32); |
| 76 | for c in ring { |
| 77 | write_f64(buf, c[0]); |
| 78 | write_f64(buf, c[1]); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | Geometry::MultiPoint { coordinates } => { |
| 83 | write_header(buf, WKB_MULTIPOINT); |
| 84 | write_u32(buf, coordinates.len() as u32); |
| 85 | for c in coordinates { |
| 86 | // Each point is a full WKB Point. |
| 87 | write_header(buf, WKB_POINT); |
| 88 | write_f64(buf, c[0]); |
| 89 | write_f64(buf, c[1]); |
| 90 | } |
| 91 | } |
| 92 | Geometry::MultiLineString { coordinates } => { |
| 93 | write_header(buf, WKB_MULTILINESTRING); |
| 94 | write_u32(buf, coordinates.len() as u32); |
| 95 | for ls in coordinates { |
| 96 | write_geometry( |
| 97 | buf, |
| 98 | &Geometry::LineString { |
| 99 | coordinates: ls.clone(), |
| 100 | }, |
| 101 | ); |
| 102 | } |
| 103 | } |
| 104 | Geometry::MultiPolygon { coordinates } => { |
| 105 | write_header(buf, WKB_MULTIPOLYGON); |
| 106 | write_u32(buf, coordinates.len() as u32); |
| 107 | for poly in coordinates { |
| 108 | write_geometry( |
| 109 | buf, |
| 110 | &Geometry::Polygon { |
| 111 | coordinates: poly.clone(), |
| 112 | }, |
| 113 | ); |
no test coverage detected