def latlon_jp2_to_pixel(lat,lon,ImageDate,MGRS): import rasterio import pyproj import numpy as np newDate = ImageDate[:4] + '-' newDate = newDate + ImageDate[4:6] newDate = newDate+'-' newDate= newDate + ImageDate[6:] try: filepath = 'AwsData/' + MGRS + ',' + newDate + ',0' + '/TCI.jp2' #filepath = 'Tile_TCI.jp2' with rasterio.open(filepath) as src: utm = pyproj.Proj(src.crs) lonlat = pyproj.Proj(init='epsg:4326') east,north = pyproj.transform(lonlat,utm,lon,lat) row,col =src.index(east,north) print(row) print(col) return row,col except: filepath = 'AwsData/' + MGRS + ',' + newDate + ',1' + '/TCI.jp2' #filepath = 'Tile_TCI.jp2' with rasterio.open(filepath) as src: utm = pyproj.Proj(src.crs) lonlat = pyproj.Proj(init='epsg:4326') east,north = pyproj.transform(lonlat,utm,lon,lat) row,col =src.index(east,north) print(row) print(col) return row,col