Skip to content

Commit 4e4563f

Browse files
authored
fix: add documentation and simplify the tests (#456)
2 parents 7350180 + bd8ef91 commit 4e4563f

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

geetools/ee_feature_collection.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,30 @@ def mergeGeometries(self, maxError: float | int | ee.Number | None = None) -> ee
223223
return ee.Geometry(union).dissolve(maxError=maxError)
224224

225225
def columnNames(self) -> ee.List:
226-
"""Get the name of the columns (Feature's properties)."""
226+
"""Get the name of the columns (Feature's properties).
227+
228+
get a flatten list of all the columns names in the FeatureCollection including the ones that
229+
are not in all features.
230+
231+
Returns:
232+
A list of all the column names in the FeatureCollection.
233+
234+
Example:
235+
.. jupyter-execute::
236+
237+
import ee, geetools
238+
from geetools.utils import initialize_documentation
239+
240+
initialize_documentation()
241+
242+
fc = ee.FeatureCollection([
243+
ee.Feature(ee.Geometry.Point([0, 0]), {"name": "A", "value": 1}),
244+
ee.Feature(ee.Geometry.Point([1, 1]), {"name": "B", "value": 2, "extra": "extra_value"})
245+
])
246+
247+
column_names = fc.geetools.columnNames()
248+
column_names.getInfo()
249+
"""
227250
temp_property_name = "__geetools_properties__"
228251
fc = self._obj.map(lambda feat: feat.set(temp_property_name, feat.propertyNames()))
229252
return fc.aggregate_array(temp_property_name).flatten().distinct()

tests/test_FeatureCollection.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,15 @@ def test_column_names(self, fc_instance, ee_list_regression):
6868

6969
@pytest.fixture
7070
def fc_instance(self):
71-
geometry = ee.Geometry.Polygon(
72-
[
73-
[
74-
[-111.108203125, 38.72726135581648],
75-
[-111.108203125, 34.42385763998893],
76-
[-106.362109375, 34.42385763998893],
77-
[-106.362109375, 38.72726135581648],
78-
]
79-
]
80-
)
81-
image = ee.Image.random().clip(geometry)
71+
image = ee.Image.random().clip(ee.Geometry.Rectangle([-1, -1, 1, 1]))
72+
# Create a Feature
8273
fc = ee.FeatureCollection(
8374
[
84-
ee.Feature(ee.Geometry.Point([-101.1765625, 35.71859799956555]), {"system:index": "0"}),
85-
ee.Feature(ee.Geometry.Point([-106.186328125, 41.41694364515647]), {"system:index": "1"}),
86-
ee.Feature(ee.Geometry.Point([-108.471484375, 37.132906371577455]), {"system:index": "2"}),
75+
# outside the image
76+
ee.Feature(ee.Geometry.Point([2, 2]), {"system:index": "0"}),
77+
# inside the image
78+
ee.Feature(ee.Geometry.Point([0, 0.5]), {"system:index": "1"}),
79+
ee.Feature(ee.Geometry.Point([0.5, 0]), {"system:index": "2"}),
8780
]
8881
)
8982
return image.reduceRegions(collection=fc, reducer=ee.Reducer.first(), scale=1000)

tests/test_FeatureCollection/serialized_test_column_names.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ values:
3333
arguments:
3434
coordinates:
3535
constantValue:
36-
- -101.1765625
37-
- 35.71859799956555
36+
- 2
37+
- 2
3838
functionName: GeometryConstructors.Point
3939
metadata:
4040
constantValue:
@@ -47,8 +47,8 @@ values:
4747
arguments:
4848
coordinates:
4949
constantValue:
50-
- -106.186328125
51-
- 41.41694364515647
50+
- 0
51+
- 0.5
5252
functionName: GeometryConstructors.Point
5353
metadata:
5454
constantValue:
@@ -61,8 +61,8 @@ values:
6161
arguments:
6262
coordinates:
6363
constantValue:
64-
- -108.471484375
65-
- 37.132906371577455
64+
- 0.5
65+
- 0
6666
functionName: GeometryConstructors.Point
6767
metadata:
6868
constantValue:
@@ -77,14 +77,14 @@ values:
7777
arguments:
7878
coordinates:
7979
constantValue:
80-
- - - -111.108203125
81-
- 38.72726135581648
82-
- - -111.108203125
83-
- 34.42385763998893
84-
- - -106.362109375
85-
- 34.42385763998893
86-
- - -106.362109375
87-
- 38.72726135581648
80+
- - - -1
81+
- 1
82+
- - -1
83+
- -1
84+
- - 1
85+
- -1
86+
- - 1
87+
- 1
8888
evenOdd:
8989
constantValue: true
9090
functionName: GeometryConstructors.Polygon
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- system:index
2+
- first
3+

0 commit comments

Comments
 (0)