I have a raster (geotiff) I am trying to clip to the bounding box of the visible leaflet map on my webpage. To get the visible bounding box I am using map.getBounds(); in javascript then passing it over to python. I am then attempting to clip my raster in rasterio using rasterio.windows.from_bounds
However the coordinates from leaflet dont return the correct area of the raster. Anyone know why this is and how I can get the correct coordinates?
GDALinfo on the original raster shows the following:
Driver: GTiff/GeoTIFF
Files: ./tmp/632c4d504889a4ee9146e774.tiff
Size is 1249, 1016
Coordinate System is:
PROJCRS["WGS 84 / Pseudo-Mercator",
BASEGEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]],
CONVERSION["Popular Visualisation Pseudo-Mercator",
METHOD["Popular Visualisation Pseudo Mercator",
ID["EPSG",1024]],
PARAMETER["Latitude of natural origin",0,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",0,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["False easting",0,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",0,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["easting (X)",east,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["northing (Y)",north,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Web mapping and visualisation."],
AREA["World between 85.06°S and 85.06°N."],
BBOX[-85.06,-180,85.06,180]],
ID["EPSG",3857]]
Data axis to CRS axis mapping: 1,2
Origin = (-20037481.165179185569286,16294357.006246965378523)
Pixel Size = (32074.291350723233336,-32074.291350723233336)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left (-20037481.165,16294357.006) (179d59'59.12"W, 81d 6'45.00"N)
Lower Left (-20037481.165,-16293123.006) (179d59'59.12"W, 81d 6'38.83"S)
Upper Right (20023308.732,16294357.006) (179d52'20.79"E, 81d 6'45.00"N)
Lower Right (20023308.732,-16293123.006) (179d52'20.79"E, 81d 6'38.83"S)
Center ( -7086.217, 617.000) ( 0d 3'49.16"W, 0d 0'19.95"N)