Last active
December 21, 2022 21:30
-
-
Save Kodiologist/5b8b8eabe5a7043056a41992fdfa4921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# UPDATE: Instead of using this script, you should probably | |
# use http://web.archive.org/web/2021id_/https://modis.ornl.gov/files/modis_sin.kmz | |
#!/usr/bin/env python3 | |
""" | |
Draw the shapes of tiles used by Moderate Resolution Imaging | |
Spectroradiometer (MODIS) satellite products. The output is a TSV file | |
with the shapes as well-known text (WKT) that can be read into QGIS. | |
""" | |
# Adjust these for visibility. | |
lon_limits = [-175, -40] | |
lat_limits = [-90, 90] | |
from pathlib import Path | |
# From: https://web.archive.org/web/2021id_/https://modis-land.gsfc.nasa.gov/pdf/sn_gring_10deg.txt | |
# linked from: https://modis-land.gsfc.nasa.gov/MODLAND_grid.html | |
inp = Path("/tmp/sn_gring_10deg.txt").read_text() | |
out = [] | |
for line in inp.splitlines(): | |
if not (line and line.lstrip()[0].isdigit()): | |
continue | |
v, h, *coords = line.split() | |
points = [ | |
(float(coords[i]), float(coords[i + 1])) | |
for i in list(range(0, len(coords), 2)) + [0]] | |
if any(lon == -999 or lat == -99 for lon, lat in points): | |
continue | |
if any( | |
not (lon_limits[0] <= lon <= lon_limits[1] and | |
lat_limits[0] <= lat <= lat_limits[1]) | |
for lon, lat in points): | |
continue | |
out.append(dict(h = h, v = v, geom = | |
'LINESTRING ({})'.format(', '.join( | |
' '.join(map(str, p)) for p in points)))) | |
out.sort(key = lambda d: (d['h'], d['v'])) | |
print('\t'.join(out[0].keys())) | |
for o in out: | |
print('\t'.join(o.values())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment