@@ -45,11 +45,18 @@ pub struct PointZM {
45
45
pub srid : Option < i32 > ,
46
46
}
47
47
48
+ #[ derive( PartialEq , Clone , Debug ) ]
49
+ pub enum PointType {
50
+ Point ,
51
+ PointZ ,
52
+ PointM ,
53
+ PointZM
54
+ }
48
55
49
56
// --- Traits
50
57
51
58
pub trait EwkbRead : fmt:: Debug + Sized {
52
- fn point_type ( ) -> postgis :: PointType ;
59
+ fn point_type ( ) -> PointType ;
53
60
54
61
fn set_srid ( & mut self , _srid : Option < i32 > ) {
55
62
}
@@ -69,22 +76,23 @@ pub trait EwkbRead: fmt::Debug + Sized {
69
76
fn read_ewkb_body < R : Read > ( raw : & mut R , is_be : bool , srid : Option < i32 > ) -> Result < Self , Error > ;
70
77
}
71
78
79
+
72
80
pub trait EwkbWrite : fmt:: Debug + Sized {
73
81
fn opt_srid ( & self ) -> Option < i32 > {
74
82
None
75
83
}
76
84
77
- fn wkb_type_id ( point_type : & postgis :: PointType , srid : Option < i32 > ) -> u32 {
85
+ fn wkb_type_id ( point_type : & PointType , srid : Option < i32 > ) -> u32 {
78
86
let mut type_ = 0 ;
79
87
if srid. is_some ( ) {
80
88
type_ |= 0x20000000 ;
81
89
}
82
- if * point_type == postgis :: PointType :: PointZ ||
83
- * point_type == postgis :: PointType :: PointZM {
90
+ if * point_type == PointType :: PointZ ||
91
+ * point_type == PointType :: PointZM {
84
92
type_ |= 0x80000000 ;
85
93
}
86
- if * point_type == postgis :: PointType :: PointM ||
87
- * point_type == postgis :: PointType :: PointZM {
94
+ if * point_type == PointType :: PointM ||
95
+ * point_type == PointType :: PointZM {
88
96
type_ |= 0x40000000 ;
89
97
}
90
98
type_
@@ -227,8 +235,8 @@ impl postgis::Point for PointZM {
227
235
macro_rules! impl_point_read_traits {
228
236
( $ptype: ident) => (
229
237
impl EwkbRead for $ptype {
230
- fn point_type( ) -> postgis :: PointType {
231
- postgis :: PointType :: $ptype
238
+ fn point_type( ) -> PointType {
239
+ PointType :: $ptype
232
240
}
233
241
fn set_srid( & mut self , srid: Option <i32 >) {
234
242
self . srid = srid;
@@ -252,7 +260,7 @@ macro_rules! impl_point_read_traits {
252
260
253
261
impl <' a> AsEwkbPoint <' a> for $ptype {
254
262
fn as_ewkb( & ' a self ) -> EwkbPoint <' a> {
255
- EwkbPoint { geom: self , srid: self . srid, point_type: postgis :: PointType :: $ptype }
263
+ EwkbPoint { geom: self , srid: self . srid, point_type: PointType :: $ptype }
256
264
}
257
265
}
258
266
)
@@ -267,7 +275,7 @@ impl_point_read_traits!(PointZM);
267
275
pub struct EwkbPoint < ' a > {
268
276
pub geom : & ' a postgis:: Point ,
269
277
pub srid : Option < i32 > ,
270
- pub point_type : postgis :: PointType ,
278
+ pub point_type : PointType ,
271
279
}
272
280
273
281
pub trait AsEwkbPoint < ' a > {
@@ -314,7 +322,7 @@ impl EwkbWrite for Point {
314
322
315
323
316
324
macro_rules! point_container_type {
317
- // points container
325
+ // geometries containing points
318
326
( $geotypetrait: ident for $geotype: ident) => (
319
327
320
328
#[ derive( PartialEq , Clone , Debug ) ]
@@ -358,7 +366,7 @@ macro_rules! point_container_type {
358
366
}
359
367
360
368
macro_rules! geometry_container_type {
361
- // line and polygon containers
369
+ // geometries containing lines and polygons
362
370
( $geotypetrait: ident for $geotype: ident contains $itemtype: ident named $itemname: ident) => (
363
371
#[ derive( PartialEq , Clone , Debug ) ]
364
372
pub struct $geotype<P : postgis:: Point + EwkbRead > {
@@ -408,7 +416,7 @@ macro_rules! impl_read_for_point_container_type {
408
416
impl <P > EwkbRead for $geotype<P >
409
417
where P : postgis:: Point + EwkbRead
410
418
{
411
- fn point_type( ) -> postgis :: PointType {
419
+ fn point_type( ) -> PointType {
412
420
P :: point_type( )
413
421
}
414
422
fn set_srid( & mut self , srid: Option <i32 >) {
@@ -429,7 +437,7 @@ macro_rules! impl_read_for_point_container_type {
429
437
impl <P > EwkbRead for $geotype<P >
430
438
where P : postgis:: Point + EwkbRead
431
439
{
432
- fn point_type( ) -> postgis :: PointType {
440
+ fn point_type( ) -> PointType {
433
441
P :: point_type( )
434
442
}
435
443
fn set_srid( & mut self , srid: Option <i32 >) {
@@ -452,7 +460,7 @@ macro_rules! impl_read_for_geometry_container_type {
452
460
impl <P > EwkbRead for $geotype<P >
453
461
where P : postgis:: Point + EwkbRead
454
462
{
455
- fn point_type( ) -> postgis :: PointType {
463
+ fn point_type( ) -> PointType {
456
464
P :: point_type( )
457
465
}
458
466
fn set_srid( & mut self , srid: Option <i32 >) {
@@ -472,7 +480,7 @@ macro_rules! impl_read_for_geometry_container_type {
472
480
impl <P > EwkbRead for $geotype<P >
473
481
where P : postgis:: Point + EwkbRead
474
482
{
475
- fn point_type( ) -> postgis :: PointType {
483
+ fn point_type( ) -> PointType {
476
484
P :: point_type( )
477
485
}
478
486
fn set_srid( & mut self , srid: Option <i32 >) {
@@ -499,7 +507,7 @@ macro_rules! point_container_write {
499
507
{
500
508
pub geom: & ' a postgis:: $geotypetrait<' a, ItemType =P , Iter =I >,
501
509
pub srid: Option <i32 >,
502
- pub point_type: postgis :: PointType ,
510
+ pub point_type: PointType ,
503
511
}
504
512
505
513
pub trait $asewkbtype<' a> {
@@ -563,7 +571,7 @@ macro_rules! geometry_container_write {
563
571
{
564
572
pub geom: & ' a postgis:: $geotypetrait<' a, ItemType =T , Iter =J >,
565
573
pub srid: Option <i32 >,
566
- pub point_type: postgis :: PointType ,
574
+ pub point_type: PointType ,
567
575
}
568
576
569
577
pub trait $asewkbtype<' a> {
@@ -633,7 +641,7 @@ macro_rules! geometry_container_write {
633
641
{
634
642
pub geom: & ' a postgis:: $geotypetrait<' a, ItemType =T , Iter =J >,
635
643
pub srid: Option <i32 >,
636
- pub point_type: postgis :: PointType ,
644
+ pub point_type: PointType ,
637
645
}
638
646
639
647
pub trait $asewkbtype<' a> {
@@ -855,7 +863,7 @@ fn test_multipolygon_write() {
855
863
#[ test]
856
864
fn test_ewkb_adapters ( ) {
857
865
let point = Point { x : 10.0 , y : -20.0 , srid : Some ( 4326 ) } ;
858
- let ewkb = EwkbPoint { geom : & point, srid : Some ( 4326 ) , point_type : postgis :: PointType :: Point } ;
866
+ let ewkb = EwkbPoint { geom : & point, srid : Some ( 4326 ) , point_type : PointType :: Point } ;
859
867
assert_eq ! ( ewkb. to_hex_ewkb( ) , "0101000020E6100000000000000000244000000000000034C0" ) ;
860
868
assert_eq ! ( point. as_ewkb( ) . to_hex_ewkb( ) , "0101000020E6100000000000000000244000000000000034C0" ) ;
861
869
}
0 commit comments