Skip to content

Commit

Permalink
Add test for bad file type error in points to geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
k034b363 committed Oct 11, 2024
1 parent 61e17bf commit 6a19d33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/points_to_geojson.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Using a Napari or PlantCV-annotate viewer object with clicked points, output a s
- **Parameters:**
- img - Spectral image object, likely read in with [`geo.read_geotif`](read_geotif.md)
- viewer - Napari viewer class object or plantcv-annotate Points class object.
- out_path - Path to save the geojson shapefile.
- out_path - Path to save the geojson shapefile. Must be ".geojson" file type.

- **Context:**
- Saved points can be used downstream for generating circular ROIs or circles for use with rasterstats.
Expand Down
2 changes: 1 addition & 1 deletion plantcv/geospatial/points_to_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def points_to_geojson(img, viewer, out_path):
viewer: Napari viewer class object or plantcv-annotate Points class object.
The viewer used to make the clicks.
out_path : str
Path to save to shapefile.
Path to save to shapefile. Must have "geojson" file extension
"""
# Napari output, points must be reversed
if hasattr(viewer, 'layers'):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_geospatial_points_to_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ def test_geospatial_points_to_geojson_badviewer(test_data, tmpdir):
filename = os.path.join(cache_dir, 'test_out.geojson')
with pytest.raises(RuntimeError):
points_to_geojson(img, viewer, out_path=filename)

def test_geospatial_points_to_geojson_badfilename(test_data, tmpdir):
"""Test for plantcv-geospatial."""
cache_dir = tmpdir.mkdir("cache")
img = read_geotif(filename=test_data.rgb_tif, bands="R,G,B")
viewer = FakePoints()
viewer.coords["default"] = []
filename = os.path.join(cache_dir, 'test_out.txt')
with pytest.raises(RuntimeError):
points_to_geojson(img, viewer, out_path=filename)

0 comments on commit 6a19d33

Please sign in to comment.