-
Notifications
You must be signed in to change notification settings - Fork 222
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
load_tile_map: Add the new parameter 'crs' to set the CRS of the returned dataarray #3554
base: main
Are you sure you want to change the base?
Conversation
c34a56f
to
d79af32
Compare
259b0dd
to
a48f9df
Compare
a48f9df
to
00e2605
Compare
""" | ||
kwargs = self._preprocess(**kwargs) | ||
|
||
if not _HAS_RIOXARRAY: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Figure.tilemap
method no longer requires rioxarray
explicitly. Instead, load_tile_map
will raise the error.
raster = load_tile_map( | ||
region=region, | ||
zoom=zoom, | ||
source=source, | ||
lonlat=lonlat, | ||
crs="OGC:CRS84" if lonlat is True else "EPSG:3857", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If lonlat=True
, set the CRS to let load_tile_map
do the raster reprojection for us.
from collections.abc import Sequence | ||
from typing import Literal | ||
|
||
from packaging.version import Version | ||
|
||
try: | ||
import contextily | ||
from rasterio.crs import CRS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These coverage annotations are incorrect. As shown below, these lines are covered.
https://app.codecov.io/gh/GenericMappingTools/pygmt/blob/load_tile_map%2Fcrs/pygmt%2Fdatasets%2Ftile_map.py
https://app.codecov.io/gh/GenericMappingTools/pygmt/blob/load_tile_map%2Fcrs/pygmt%2Fsrc%2Ftilemap.py
@@ -176,8 +196,12 @@ def load_tile_map( | |||
dims=("band", "y", "x"), | |||
) | |||
|
|||
# If rioxarray is installed, set the coordinate reference system | |||
# If rioxarray is installed, set the coordinate reference system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are also covered.
Description of proposed changes
This PR adds the
crs
parameter to theload_tile_map
function so that users can change the CRS of the returned raster image without needing to know the details.Address #2125 (comment).
Closes #3484.
Notes for maintainers:
As far as I know, there are multiple different ways to reproject raster images.
rasterio.vrt.WarpedVRT
rasterio.warp.reproject
rasterio.vrt.WarpedVRT
rasterio.warp.reproject
gdal.Warp
Options 3-5 are complicated and I don't think we want to call them directly. Ideally, we should use option 1, so reprojection doesn't rely on an extra dependency
rioxarray
. However, as shown below, the result fromcontextily.warp_tiles
doesn't work well withrio.to_raster
.Here are codes to compare the results with options 1 and 2:
The outputs are:
As you can see, the longitude range is (-180.55157789333614, 180.18036434850873) with
contextily.warp_tiles
, which will lead to GMT errors like:Two more notes:
rasterio.warp.reproject
instead ofrasterio.vrt.WarpedVRT
inwarp_tiles
(Explorerasterio.warp.reproject
to replaceMemoryFile
for warping geopandas/contextily#88). If it's done, then the result fromwarp_tiles
will be likely the same as the one fromrio.reproject
rio.to_raster
(pygmt/pygmt/helpers/tempfile.py
Line 204 in 988746b
Preview: https://pygmt-dev--3554.org.readthedocs.build/en/3554/api/generated/pygmt.datasets.load_tile_map.html
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash command is:
/format
: automatically format and lint the code