Skip to content

Commit 1bf6101

Browse files
add crs support for arr_to_latlng (#1871)
add crs support for arr_to_latlng Made in [Fused Workbench](https://www.fused.io/workbench) --------- Co-authored-by: sina@fused.io <sina@fused.io> Co-authored-by: Sina Kashuk <sina@nyu.edu>
1 parent fdebe93 commit 1bf6101

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

public/common/common.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,16 +3159,16 @@ def get_chunk_slices_from_shape(array_shape, x_chunks, y_chunks, i):
31593159

31603160
return x_slice, y_slice
31613161

3162-
def arr_to_latlng(arr, bounds):
3162+
def arr_to_latlng(arr, bounds, crs="EPSG:4326"):
31633163
import numpy as np
31643164
import pandas as pd
3165+
import pyproj
31653166
from rasterio.transform import from_bounds
3166-
transform = from_bounds(*bounds, arr.shape[-1], arr.shape[-2])
3167-
x_list, y_list = shape_transform_to_xycoor(arr.shape[-2:], transform)
3167+
x_list, y_list = shape_transform_to_xycoor(arr.shape[-2:], from_bounds(*bounds, arr.shape[-1], arr.shape[-2]))
31683168
X, Y = np.meshgrid(x_list, y_list)
3169-
df = pd.DataFrame(X.flatten(), columns=["lng"])
3170-
df["lat"] = Y.flatten()
3171-
df["data"] = arr.flatten()
3169+
df = pd.DataFrame({"lng": X.flatten(), "lat": Y.flatten(), "data": arr.flatten()})
3170+
if crs != "EPSG:4326":
3171+
df["lng"], df["lat"] = pyproj.Transformer.from_crs(crs, "EPSG:4326", always_xy=True).transform(df["lng"].values, df["lat"].values)
31723172
return df
31733173

31743174
# @fused.cache

public/common/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@
103103
],
104104
"metadata": null
105105
}
106-
}
106+
}

0 commit comments

Comments
 (0)