Skip to content

load_map_tiles: Allow a new parameter to control the projection of the returned DataArray #3484

Closed

Description

@seisman

Originally proposed in #2125 (comment)

Perhaps we should convert the returned image to longitude/latitude because it's more commonly used than the Spherical Mercator coordinate system, following https://contextily.readthedocs.io/en/latest/warping_guide.html.

Most tiles are originally served as Web Mercator (EPSG:3857), and reprojecting to latlon (EPSG:4326) would result in distortion. I'd prefer the reprojection to be a user controlled step (e.g. using rioxarray's .rio.to_crs), because if latlon isn't what the user wants, there would be double reprojection (EPSG:3857 ->EPSG:4326 ->EPSG:????) which is less accurate than single reprojection (EPSG:3857 ->EPSG:????).

I'd prefer the reprojection to be a user controlled step (e.g. using rioxarray's .rio.to_crs)

What about having an option so that users can decide on the desired projection and don't have to learn the syntax of the rioxarray package?

I think we can add a new parameter like crs to control the projection. crs should be default to EPSG:3857. If a different CRS is given, then we can use contextily.warp_tiles to reproject the tiles.

With this new parameter, the following lines in Figure.tilemap can be simplified:

pygmt/pygmt/src/tilemap.py

Lines 141 to 145 in 68a17a0

# Reproject raster from Spherical Mercator (EPSG:3857) to lonlat (OGC:CRS84) if
# bounding box region was provided in lonlat
if lonlat and raster.rio.crs == "EPSG:3857":
raster = raster.rio.reproject(dst_crs="OGC:CRS84")
raster.gmt.gtype = 1 # set to geographic type

Activity

  1. added
    enhancement
    on Oct 4, 2024
  2. added this to the 0.14.0 milestone on Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions