Skip to content

Instantly share code, notes, and snippets.

@prl900
Last active April 12, 2019 06:03
Show Gist options
  • Save prl900/7c203861aef1460a85ba1f23fb148190 to your computer and use it in GitHub Desktop.
Save prl900/7c203861aef1460a85ba1f23fb148190 to your computer and use it in GitHub Desktop.
from pyproj import Proj, transform
import math
xExtentModis = 1111950.519666
yExtentModis = 1111950.519667
sinu_proj = "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs "
wgs84_proj = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs "
def xy2tile(x, y):
return int(math.floor(x/xExtentModis)) + 18, -1*int(math.ceil(y/yExtentModis)) + 9
if __name__ == "__main__":
inProj = Proj(wgs84_proj)
outProj = Proj(sinu_proj)
# Canberra (Australia)
lat = -35.28
lon = 149.13
x, y = transform(inProj,outProj,lon,lat)
print(x, y)
print(xy2tile(x, y))
# Pamplona (Spain)
lat = 42.81
lon = -1.64
x, y = transform(inProj,outProj,lon,lat)
print(x, y)
print(xy2tile(x, y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment