Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reproject geo info #277

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions mapreader/load/geo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,37 @@ def reproject_geo_info(image_path, target_crs="EPSG:4326", calc_size_in_m=False)
height, width, _ = tiff_shape

# Calculate the size of image in meters
if calc_size_in_m in ["geodesic", "gd"]:
bottom = geodesic((ymin, xmin), (ymin, xmax)).meters
right = geodesic((ymin, xmax), (ymax, xmax)).meters
top = geodesic((ymax, xmax), (ymax, xmin)).meters
left = geodesic((ymax, xmin), (ymin, xmin)).meters

elif calc_size_in_m in ["gc", "great-circle", "great_circle"]:
bottom = great_circle((ymin, xmin), (ymin, xmax)).meters
right = great_circle((ymin, xmax), (ymax, xmax)).meters
top = great_circle((ymax, xmax), (ymax, xmin)).meters
left = great_circle((ymax, xmin), (ymin, xmin)).meters

elif not calc_size_in_m:
size_in_m = False

else:
raise NotImplementedError(
f'[ERROR] ``calc_size_in_m`` must be one of "great-circle", "great_circle", "gc", "geodesic" or "gd", not: {calc_size_in_m}'
if calc_size_in_m:
if calc_size_in_m in ["geodesic", "gd"]:
bottom = geodesic((ymin, xmin), (ymin, xmax)).meters
right = geodesic((ymin, xmax), (ymax, xmax)).meters
top = geodesic((ymax, xmax), (ymax, xmin)).meters
left = geodesic((ymax, xmin), (ymin, xmin)).meters

elif calc_size_in_m in ["gc", "great-circle", "great_circle"]:
bottom = great_circle((ymin, xmin), (ymin, xmax)).meters
right = great_circle((ymin, xmax), (ymax, xmax)).meters
top = great_circle((ymax, xmax), (ymax, xmin)).meters
left = great_circle((ymax, xmin), (ymin, xmin)).meters

else:
raise NotImplementedError(
f'[ERROR] ``calc_size_in_m`` must be one of "great-circle", "great_circle", "gc", "geodesic" or "gd", not: {calc_size_in_m}'
)

size_in_m = (left, bottom, right, top) # anticlockwise order

mean_pixel_height = np.mean([right / height, left / height])
mean_pixel_width = np.mean([bottom / width, top / width])

print(
f"[INFO] Size in meters of left/bottom/right/top: {left:.2f}/{bottom:.2f}/{right:.2f}/{top:.2f}"
)
print(
f"Each pixel is ~{mean_pixel_height:.3f} X {mean_pixel_width:.3f} meters (height x width)."
) # noqa

size_in_m = (left, bottom, right, top) # anticlockwise order

mean_pixel_height = np.mean([right / height, left / height])
mean_pixel_width = np.mean([bottom / width, top / width])

print(
f"[INFO] Size in meters of left/bottom/right/top: {left:.2f}/{bottom:.2f}/{right:.2f}/{top:.2f}"
)
print(
f"Each pixel is ~{mean_pixel_height:.3f} X {mean_pixel_width:.3f} meters (height x width)."
) # noqa
else:
size_in_m = None

return tiff_shape, tiff_proj, target_crs, coord, size_in_m
Loading