File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,17 @@ def __getitem__(self, item):
2929 elif item in (3 , 'm' ):
3030 return self .m
3131
32+ def __iter__ (self ):
33+ return iter (self .values ())
34+
35+ _keys = ['x' , 'y' , 'z' , 'm' ]
36+
37+ def keys (self ):
38+ return [k for k in self ._keys if self [k ] is not None ]
39+
40+ def values (self ):
41+ return tuple (self [k ] for k in self .keys ())
42+
3243 @property
3344 def has_z (self ):
3445 return self .z is not None
@@ -46,5 +57,4 @@ def wkt_coords(self):
4657
4758 @property
4859 def coords (self ):
49- return tuple (p for p in (self .x , self .y , self .z , self .m )
50- if p is not None )
60+ return self .values ()
Original file line number Diff line number Diff line change @@ -51,3 +51,35 @@ def test_can_create_point_with_z():
5151def test_point_geojson_with_z ():
5252 point = Point (1 , 2 , 3 )
5353 assert point .geojson == {"type" : "Point" , "coordinates" : (1 , 2 , 3 )}
54+
55+
56+ def test_point_can_be_unpacked ():
57+ point = Point (1 , 2 )
58+ x , y = point
59+ assert x == 1
60+ assert y == 2
61+
62+
63+ def test_point_can_be_unpacked_to_dict ():
64+ point = Point (1 , 2 )
65+ data = dict (point )
66+ assert data ['x' ] == 1
67+ assert data ['y' ] == 2
68+ assert len (data ) == 2
69+
70+
71+ def test_point_with_z_can_be_unpacked ():
72+ point = Point (1 , 2 , 3 )
73+ x , y , z = point
74+ assert x == 1
75+ assert y == 2
76+ assert z == 3
77+
78+
79+ def test_point_with_z_can_be_unpacked_to_dict ():
80+ point = Point (1 , 2 , 3 )
81+ data = dict (point )
82+ assert data ['x' ] == 1
83+ assert data ['y' ] == 2
84+ assert data ['z' ] == 3
85+ assert len (data ) == 3
You can’t perform that action at this time.
0 commit comments