-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathgeometry.rs
596 lines (520 loc) · 20.5 KB
/
geometry.rs
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
use std::cell::RefCell;
use std::ffi::CString;
use std::fmt::{self, Debug, Formatter};
use std::marker::PhantomData;
use std::ops::Deref;
use std::ptr::null_mut;
use libc::{c_char, c_double, c_int, c_void};
use gdal_sys::{self, OGRErr, OGRGeometryH, OGRwkbGeometryType};
use crate::errors::*;
use crate::spatial_ref::{CoordTransform, SpatialRef};
use crate::utils::{_last_null_pointer_err, _string};
/// OGR Geometry
pub struct Geometry {
c_geometry_ref: RefCell<Option<OGRGeometryH>>,
owned: bool,
}
impl Geometry {
/// Create a new Geometry without a C pointer
///
/// # Safety
/// This method returns a Geometry without wrapped pointer
pub unsafe fn lazy_feature_geometry() -> Geometry {
// Geometry objects created with this method map to a Feature's
// geometry whose memory is managed by the GDAL feature.
// This object has a tricky lifecycle:
//
// * Initially it's created with a null c_geometry
// * The first time `Feature::geometry` is called, it gets
// c_geometry from GDAL and calls `set_c_geometry` with it.
// * When the Feature is destroyed, this object is also destroyed,
// which is good, because that's when c_geometry (which is managed
// by the GDAL feature) becomes invalid. Because `self.owned` is
// `true`, we don't call `OGR_G_DestroyGeometry`.
Geometry {
c_geometry_ref: RefCell::new(None),
owned: false,
}
}
pub fn has_gdal_ptr(&self) -> bool {
self.c_geometry_ref.borrow().is_some()
}
/// Set the wrapped C pointer
///
/// # Safety
/// This method operates on a raw C pointer
pub unsafe fn set_c_geometry(&self, c_geometry: OGRGeometryH) {
assert!(!self.has_gdal_ptr());
assert!(!self.owned);
*(self.c_geometry_ref.borrow_mut()) = Some(c_geometry);
}
pub(crate) unsafe fn with_c_geometry(c_geom: OGRGeometryH, owned: bool) -> Geometry {
Geometry {
c_geometry_ref: RefCell::new(Some(c_geom)),
owned,
}
}
pub fn empty(wkb_type: OGRwkbGeometryType::Type) -> Result<Geometry> {
let c_geom = unsafe { gdal_sys::OGR_G_CreateGeometry(wkb_type) };
if c_geom.is_null() {
return Err(_last_null_pointer_err("OGR_G_CreateGeometry"));
};
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
}
pub fn is_empty(&self) -> bool {
unsafe { gdal_sys::OGR_G_IsEmpty(self.c_geometry()) == 1 }
}
/// Create a geometry by parsing a
/// [WKT](https://en.wikipedia.org/wiki/Well-known_text) string.
pub fn from_wkt(wkt: &str) -> Result<Geometry> {
let c_wkt = CString::new(wkt)?;
// OGR_G_CreateFromWkt does not write to the pointed-to memory, but this is not reflected
// in its signature (`char**` instead of `char const**`), so we need a scary looking cast.
let mut c_wkt_ptr = c_wkt.as_ptr() as *mut c_char;
let mut c_geom = null_mut();
let rv = unsafe { gdal_sys::OGR_G_CreateFromWkt(&mut c_wkt_ptr, null_mut(), &mut c_geom) };
if rv != OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
method_name: "OGR_G_CreateFromWkt",
});
}
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
}
/// Creates a geometry by parsing a slice of bytes in
/// [WKB](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary)
/// (Well-Known Binary) format.
pub fn from_wkb(wkb: &[u8]) -> Result<Geometry> {
let mut c_geom = null_mut();
let rv = unsafe {
gdal_sys::OGR_G_CreateFromWkb(
wkb.as_ptr() as *const std::ffi::c_void,
null_mut(),
&mut c_geom,
wkb.len() as i32,
)
};
if rv != gdal_sys::OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
method_name: "OGR_G_CreateFromWkb",
});
}
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
}
/// Create a rectangular geometry from West, South, East and North values.
pub fn bbox(w: f64, s: f64, e: f64, n: f64) -> Result<Geometry> {
Geometry::from_wkt(&format!(
"POLYGON (({} {}, {} {}, {} {}, {} {}, {} {}))",
w, n, e, n, e, s, w, s, w, n,
))
}
/// Serialize the geometry as JSON.
pub fn json(&self) -> Result<String> {
let c_json = unsafe { gdal_sys::OGR_G_ExportToJson(self.c_geometry()) };
if c_json.is_null() {
return Err(_last_null_pointer_err("OGR_G_ExportToJson"));
};
let rv = _string(c_json);
unsafe { gdal_sys::VSIFree(c_json as *mut c_void) };
Ok(rv)
}
/// Serialize the geometry as WKT.
pub fn wkt(&self) -> Result<String> {
let mut c_wkt = null_mut();
let rv = unsafe { gdal_sys::OGR_G_ExportToWkt(self.c_geometry(), &mut c_wkt) };
if rv != OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
method_name: "OGR_G_ExportToWkt",
});
}
let wkt = _string(c_wkt);
unsafe { gdal_sys::OGRFree(c_wkt as *mut c_void) };
Ok(wkt)
}
/// Serializes the geometry to
/// [WKB](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary)
/// (Well-Known Binary) format.
pub fn wkb(&self) -> Result<Vec<u8>> {
let wkb_size = unsafe { gdal_sys::OGR_G_WkbSize(self.c_geometry()) as usize };
// We default to little-endian for now. A WKB string explicitly indicates the byte
// order, so this is not a problem for interoperability.
let byte_order = gdal_sys::OGRwkbByteOrder::wkbNDR;
let mut wkb = vec![0; wkb_size];
let rv =
unsafe { gdal_sys::OGR_G_ExportToWkb(self.c_geometry(), byte_order, wkb.as_mut_ptr()) };
if rv != gdal_sys::OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
method_name: "OGR_G_ExportToWkb",
});
}
Ok(wkb)
}
/// Returns a C pointer to the wrapped Geometry
///
/// # Safety
/// This method returns a raw C pointer
pub unsafe fn c_geometry(&self) -> OGRGeometryH {
self.c_geometry_ref.borrow().unwrap()
}
/// Returns the C pointer of a Geometry
///
/// # Safety
/// This method returns a raw C pointer
pub unsafe fn into_c_geometry(mut self) -> OGRGeometryH {
assert!(self.owned);
self.owned = false;
self.c_geometry()
}
pub fn set_point(&mut self, i: usize, point: (f64, f64, f64)) {
let (x, y, z) = point;
unsafe {
gdal_sys::OGR_G_SetPoint(
self.c_geometry(),
i as c_int,
x as c_double,
y as c_double,
z as c_double,
);
};
}
pub fn set_point_2d(&mut self, i: usize, p: (f64, f64)) {
let (x, y) = p;
unsafe {
gdal_sys::OGR_G_SetPoint_2D(self.c_geometry(), i as c_int, x as c_double, y as c_double)
};
}
pub fn add_point(&mut self, p: (f64, f64, f64)) {
let (x, y, z) = p;
unsafe {
gdal_sys::OGR_G_AddPoint(
self.c_geometry(),
x as c_double,
y as c_double,
z as c_double,
)
};
}
pub fn add_point_2d(&mut self, p: (f64, f64)) {
let (x, y) = p;
unsafe { gdal_sys::OGR_G_AddPoint_2D(self.c_geometry(), x as c_double, y as c_double) };
}
pub fn get_point(&self, i: i32) -> (f64, f64, f64) {
let mut x: c_double = 0.;
let mut y: c_double = 0.;
let mut z: c_double = 0.;
unsafe { gdal_sys::OGR_G_GetPoint(self.c_geometry(), i, &mut x, &mut y, &mut z) };
(x as f64, y as f64, z as f64)
}
pub fn get_point_vec(&self) -> Vec<(f64, f64, f64)> {
let length = unsafe { gdal_sys::OGR_G_GetPointCount(self.c_geometry()) };
(0..length).map(|i| self.get_point(i)).collect()
}
/// Compute the convex hull of this geometry.
pub fn convex_hull(&self) -> Result<Geometry> {
let c_geom = unsafe { gdal_sys::OGR_G_ConvexHull(self.c_geometry()) };
if c_geom.is_null() {
return Err(_last_null_pointer_err("OGR_G_ConvexHull"));
};
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
}
#[cfg(any(all(major_is_2, minor_ge_1), major_ge_3))]
pub fn delaunay_triangulation(&self, tolerance: Option<f64>) -> Result<Self> {
let c_geom = unsafe {
gdal_sys::OGR_G_DelaunayTriangulation(self.c_geometry(), tolerance.unwrap_or(0.0), 0)
};
if c_geom.is_null() {
return Err(_last_null_pointer_err("OGR_G_DelaunayTriangulation"));
};
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
}
pub fn simplify(&self, tolerance: f64) -> Result<Self> {
let c_geom = unsafe { gdal_sys::OGR_G_Simplify(self.c_geometry(), tolerance) };
if c_geom.is_null() {
return Err(_last_null_pointer_err("OGR_G_Simplify"));
};
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
}
/// Compute buffer of geometry
///
/// The `distance` parameter the buffer distance to be applied. Should be expressed into
/// the same unit as the coordinates of the geometry. `n_quad_segs` specifies the number
/// of segments used to approximate a 90 degree (quadrant) of curvature.
pub fn buffer(&self, distance: f64, n_quad_segs: u32) -> Result<Self> {
let c_geom =
unsafe { gdal_sys::OGR_G_Buffer(self.c_geometry(), distance, n_quad_segs as i32) };
if c_geom.is_null() {
return Err(_last_null_pointer_err("OGR_G_Buffer"));
};
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
}
pub fn simplify_preserve_topology(&self, tolerance: f64) -> Result<Self> {
let c_geom =
unsafe { gdal_sys::OGR_G_SimplifyPreserveTopology(self.c_geometry(), tolerance) };
if c_geom.is_null() {
return Err(_last_null_pointer_err("OGR_G_SimplifyPreserveTopology"));
};
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
}
pub fn geometry_type(&self) -> OGRwkbGeometryType::Type {
unsafe { gdal_sys::OGR_G_GetGeometryType(self.c_geometry()) }
}
pub fn geometry_count(&self) -> usize {
let cnt = unsafe { gdal_sys::OGR_G_GetGeometryCount(self.c_geometry()) };
cnt as usize
}
/// Returns the n-th sub-geometry as a non-owned Geometry.
///
/// # Safety
/// Don't keep this object for long.
pub unsafe fn get_unowned_geometry(&self, n: usize) -> Geometry {
// get the n-th sub-geometry as a non-owned Geometry; don't keep this
// object for long.
let c_geom = gdal_sys::OGR_G_GetGeometryRef(self.c_geometry(), n as c_int);
Geometry::with_c_geometry(c_geom, false)
}
/// Get a reference to the geometry at given `index`
pub fn get_geometry(&self, index: usize) -> GeometryRef {
let geom = unsafe { self.get_unowned_geometry(index) };
GeometryRef {
geom,
_lifetime: PhantomData::default(),
}
}
pub fn add_geometry(&mut self, mut sub: Geometry) -> Result<()> {
assert!(sub.owned);
sub.owned = false;
let rv =
unsafe { gdal_sys::OGR_G_AddGeometryDirectly(self.c_geometry(), sub.c_geometry()) };
if rv != OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
method_name: "OGR_G_AddGeometryDirectly",
});
}
Ok(())
}
// Transform the geometry inplace (when we own the Geometry)
pub fn transform_inplace(&mut self, htransform: &CoordTransform) -> Result<()> {
let rv = unsafe { gdal_sys::OGR_G_Transform(self.c_geometry(), htransform.to_c_hct()) };
if rv != OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
method_name: "OGR_G_Transform",
});
}
Ok(())
}
// Return a new transformed geometry (when the Geometry is owned by a Feature)
pub fn transform(&self, htransform: &CoordTransform) -> Result<Geometry> {
let new_c_geom = unsafe { gdal_sys::OGR_G_Clone(self.c_geometry()) };
let rv = unsafe { gdal_sys::OGR_G_Transform(new_c_geom, htransform.to_c_hct()) };
if rv != OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
method_name: "OGR_G_Transform",
});
}
Ok(unsafe { Geometry::with_c_geometry(new_c_geom, true) })
}
pub fn transform_to_inplace(&mut self, spatial_ref: &SpatialRef) -> Result<()> {
let rv = unsafe { gdal_sys::OGR_G_TransformTo(self.c_geometry(), spatial_ref.to_c_hsrs()) };
if rv != OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
method_name: "OGR_G_TransformTo",
});
}
Ok(())
}
/// Transforms a geometrys coordinates into another SpatialRef
pub fn transform_to(&self, spatial_ref: &SpatialRef) -> Result<Geometry> {
let new_c_geom = unsafe { gdal_sys::OGR_G_Clone(self.c_geometry()) };
let rv = unsafe { gdal_sys::OGR_G_TransformTo(new_c_geom, spatial_ref.to_c_hsrs()) };
if rv != OGRErr::OGRERR_NONE {
return Err(GdalError::OgrError {
err: rv,
method_name: "OGR_G_TransformTo",
});
}
Ok(unsafe { Geometry::with_c_geometry(new_c_geom, true) })
}
pub fn area(&self) -> f64 {
unsafe { gdal_sys::OGR_G_Area(self.c_geometry()) }
}
/// May or may not contain a reference to a SpatialRef: if not, it returns
/// an `Ok(None)`; if it does, it tries to build a SpatialRef. If that
/// succeeds, it returns an Ok(Some(SpatialRef)), otherwise, you get the
/// Err.
///
pub fn spatial_ref(&self) -> Option<SpatialRef> {
let c_spatial_ref = unsafe { gdal_sys::OGR_G_GetSpatialReference(self.c_geometry()) };
if c_spatial_ref.is_null() {
None
} else {
match unsafe { SpatialRef::from_c_obj(c_spatial_ref) } {
Ok(sr) => Some(sr),
Err(_) => None,
}
}
}
pub fn set_spatial_ref(&mut self, spatial_ref: SpatialRef) {
unsafe {
gdal_sys::OGR_G_AssignSpatialReference(self.c_geometry(), spatial_ref.to_c_hsrs())
};
}
/// Create a copy of self as a `geo-types` geometry.
pub fn to_geo(&self) -> Result<geo_types::Geometry<f64>> {
self.try_into()
}
}
impl Drop for Geometry {
fn drop(&mut self) {
if self.owned {
let c_geometry = self.c_geometry_ref.borrow();
unsafe { gdal_sys::OGR_G_DestroyGeometry(c_geometry.unwrap()) };
}
}
}
impl Clone for Geometry {
fn clone(&self) -> Geometry {
// assert!(self.has_gdal_ptr());
let c_geometry = self.c_geometry_ref.borrow();
let new_c_geom = unsafe { gdal_sys::OGR_G_Clone(c_geometry.unwrap()) };
unsafe { Geometry::with_c_geometry(new_c_geom, true) }
}
}
impl Debug for Geometry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.wkt() {
Ok(wkt) => f.write_str(wkt.as_str()),
Err(_) => Err(fmt::Error),
}
}
}
impl PartialEq for Geometry {
fn eq(&self, other: &Self) -> bool {
unsafe { gdal_sys::OGR_G_Equal(self.c_geometry(), other.c_geometry()) != 0 }
}
}
impl Eq for Geometry {}
pub fn geometry_type_to_name(ty: OGRwkbGeometryType::Type) -> String {
let rv = unsafe { gdal_sys::OGRGeometryTypeToName(ty) };
// If the type is invalid, OGRGeometryTypeToName returns a valid string anyway.
assert!(!rv.is_null());
_string(rv)
}
/// Reference to owned geometry
pub struct GeometryRef<'a> {
geom: Geometry,
_lifetime: PhantomData<&'a ()>,
}
impl Deref for GeometryRef<'_> {
type Target = Geometry;
fn deref(&self) -> &Self::Target {
&self.geom
}
}
impl Debug for GeometryRef<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Debug::fmt(&self.geom, f)
}
}
#[cfg(test)]
mod tests {
use crate::spatial_ref::SpatialRef;
use super::{geometry_type_to_name, Geometry};
#[test]
#[allow(clippy::float_cmp)]
pub fn test_area() {
let geom = Geometry::empty(::gdal_sys::OGRwkbGeometryType::wkbMultiPolygon).unwrap();
assert_eq!(geom.area(), 0.0);
let geom = Geometry::from_wkt("POINT(0 0)").unwrap();
assert_eq!(geom.area(), 0.0);
let wkt = "POLYGON ((45.0 45.0, 45.0 50.0, 50.0 50.0, 50.0 45.0, 45.0 45.0))";
let geom = Geometry::from_wkt(wkt).unwrap();
assert_eq!(geom.area().floor(), 25.0);
}
#[test]
pub fn test_is_empty() {
let geom = Geometry::empty(::gdal_sys::OGRwkbGeometryType::wkbMultiPolygon).unwrap();
assert!(geom.is_empty());
let geom = Geometry::from_wkt("POINT(0 0)").unwrap();
assert!(!geom.is_empty());
let wkt = "POLYGON ((45.0 45.0, 45.0 50.0, 50.0 50.0, 50.0 45.0, 45.0 45.0))";
let geom = Geometry::from_wkt(wkt).unwrap();
assert!(!geom.is_empty());
}
#[test]
pub fn test_create_multipoint_2d() {
let mut geom = Geometry::empty(::gdal_sys::OGRwkbGeometryType::wkbMultiPoint).unwrap();
let mut point = Geometry::empty(::gdal_sys::OGRwkbGeometryType::wkbPoint).unwrap();
point.add_point_2d((1.0, 2.0));
geom.add_geometry(point).unwrap();
let mut point = Geometry::empty(::gdal_sys::OGRwkbGeometryType::wkbPoint).unwrap();
point.add_point_2d((2.0, 3.0));
assert!(!point.is_empty());
point.set_point_2d(0, (2.0, 4.0));
geom.add_geometry(point).unwrap();
assert!(!geom.is_empty());
let expected = Geometry::from_wkt("MULTIPOINT((1.0 2.0), (2.0 4.0))").unwrap();
assert_eq!(geom, expected);
}
#[test]
pub fn test_create_multipoint_3d() {
let mut geom = Geometry::empty(::gdal_sys::OGRwkbGeometryType::wkbMultiPoint).unwrap();
let mut point = Geometry::empty(::gdal_sys::OGRwkbGeometryType::wkbPoint).unwrap();
point.add_point((1.0, 2.0, 3.0));
geom.add_geometry(point).unwrap();
let mut point = Geometry::empty(::gdal_sys::OGRwkbGeometryType::wkbPoint).unwrap();
point.add_point((3.0, 2.0, 1.0));
assert!(!point.is_empty());
point.set_point(0, (4.0, 2.0, 1.0));
geom.add_geometry(point).unwrap();
assert!(!geom.is_empty());
let expected = Geometry::from_wkt("MULTIPOINT((1.0 2.0 3.0), (4.0 2.0 1.0))").unwrap();
assert_eq!(geom, expected);
}
#[test]
pub fn test_spatial_ref() {
let geom = Geometry::empty(::gdal_sys::OGRwkbGeometryType::wkbMultiPolygon).unwrap();
assert!(geom.spatial_ref().is_none());
let geom = Geometry::from_wkt("POINT(0 0)").unwrap();
assert!(geom.spatial_ref().is_none());
let wkt = "POLYGON ((45.0 45.0, 45.0 50.0, 50.0 50.0, 50.0 45.0, 45.0 45.0))";
let mut geom = Geometry::from_wkt(wkt).unwrap();
assert!(geom.spatial_ref().is_none());
let srs = SpatialRef::from_epsg(4326).unwrap();
geom.set_spatial_ref(srs);
assert!(geom.spatial_ref().is_some());
}
#[test]
pub fn test_wkb() {
let wkt = "POLYGON ((45.0 45.0, 45.0 50.0, 50.0 50.0, 50.0 45.0, 45.0 45.0))";
let orig_geom = Geometry::from_wkt(wkt).unwrap();
let wkb = orig_geom.wkb().unwrap();
let new_geom = Geometry::from_wkb(&wkb).unwrap();
assert_eq!(new_geom, orig_geom);
}
#[test]
pub fn test_buffer() {
let geom = Geometry::from_wkt("POINT(0 0)").unwrap();
let buffered = geom.buffer(10.0, 2).unwrap();
assert_eq!(
buffered.geometry_type(),
::gdal_sys::OGRwkbGeometryType::wkbPolygon
);
assert!(buffered.area() > 10.0);
}
#[test]
pub fn test_geometry_type_to_name() {
assert_eq!(
geometry_type_to_name(::gdal_sys::OGRwkbGeometryType::wkbLineString),
"Line String"
);
// We don't care what it returns when passed an invalid value, just that it doesn't crash.
geometry_type_to_name(4372521);
}
}