Skip to content

Commit

Permalink
Merge pull request #14 from danforthcenter/fix_tranform_points
Browse files Browse the repository at this point in the history
Fix transform points, update transformation metadata stored during `read_geotif` when `cropto` is applied.
  • Loading branch information
HaleySchuhl authored Sep 20, 2024
2 parents 155fc39 + 9503653 commit bc7a157
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ See [this page](https://plantcv.readthedocs.io/en/latest/pr_review_process/) for
- [ ] All tests pass
- [ ] Test coverage remains 100%
- [ ] Documentation tested
- [ ] New documentation pages added to `plantcv/mkdocs.yml`
- [ ] Changes to function input/output signatures added to `updating.md`
- [ ] New documentation pages added to `plantcv-geospatial/mkdocs.yml`
- [ ] Changes to function input/output signatures added to `changelog.md`
- [ ] Code reviewed
- [ ] PR approved
3 changes: 2 additions & 1 deletion plantcv/geospatial/read_geotif.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ def _read_geotif_and_shapefile(filename, cropto):
shapes = [mapping(convex_hull)]
# rasterio does the cropping within open
with rasterio.open(filename, 'r') as src:
img_data, _ = mask(src, shapes, crop=True)
img_data, trans_metadata = mask(src, shapes, crop=True)
metadata = src.meta.copy()
metadata.update({"transform": trans_metadata})
d_type = src.dtypes[0]

else:
Expand Down
10 changes: 5 additions & 5 deletions plantcv/geospatial/transform_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def transform_points(img, geojson):

coord = []
with fiona.open(geojson, 'r') as shapefile:
for i, _ in enumerate(shapefile):
if type((shapefile[i].geometry["coordinates"])) is list:
pixel_point = ~(geo_transform) * (shapefile[i].geometry["coordinates"][0])
if type((shapefile[i].geometry["coordinates"])) is tuple:
pixel_point = ~(geo_transform) * (shapefile[i].geometry["coordinates"])
for row in shapefile:
if type((row.geometry["coordinates"])) is list:
pixel_point = ~(geo_transform) * (row.geometry["coordinates"][0])
if type((row.geometry["coordinates"])) is tuple:
pixel_point = ~(geo_transform) * (row.geometry["coordinates"])
rounded = (int(pixel_point[0]), int(pixel_point[1]))
coord.append(rounded)

Expand Down

0 comments on commit bc7a157

Please sign in to comment.