Skip to content

Commit

Permalink
Merge pull request #52 from developmentseed/fix-coordinate-transform
Browse files Browse the repository at this point in the history
Update reader.py
  • Loading branch information
abarciauskas-bgse authored Mar 21, 2024
2 parents 756bdbd + 4b74955 commit 9dbebea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ dependencies = [
"pydantic-settings~=2.0",
"pandas==1.5.3",
"redis",
"fastapi>=0.100.0,<0.107.0",
"starlette<0.28",
]

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion titiler/xarray/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def map_viewer(
"request": request,
"tilejson_endpoint": tilejson_url,
"tms": tms,
"resolutions": [tms._resolution(matrix) for matrix in tms],
"resolutions": [matrix.cellSize for matrix in tms],
},
media_type="text/html",
)
Expand Down
10 changes: 5 additions & 5 deletions titiler/xarray/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ def get_variable(
da = da.sel({dim_to_drop: dim_val}).drop(dim_to_drop)
da = arrange_coordinates(da)

if (da.x > 180).any():
# Make sure we have a valid CRS
crs = da.rio.crs or "epsg:4326"
da.rio.write_crs(crs, inplace=True)

if crs == "epsg:4326" and (da.x > 180).any():
# Adjust the longitude coordinates to the -180 to 180 range
da = da.assign_coords(x=(da.x + 180) % 360 - 180)

# Sort the dataset by the updated longitude coordinates
da = da.sortby(da.x)

# Make sure we have a valid CRS
crs = da.rio.crs or "epsg:4326"
da.rio.write_crs(crs, inplace=True)

if "time" in da.dims:
if time_slice:
time_as_str = time_slice.split("T")[0]
Expand Down

0 comments on commit 9dbebea

Please sign in to comment.