Skip to content

Instantly share code, notes, and snippets.

@albert-decatur
Last active August 29, 2015 14:19
Show Gist options
  • Save albert-decatur/36ac02166007bd880aeb to your computer and use it in GitHub Desktop.
Save albert-decatur/36ac02166007bd880aeb to your computer and use it in GitHub Desktop.
landsat-api polar stereoscopic flip
select st_astext(st_transform(st_geomfromtext('POINT( 170.84215 -80.9338 )',4326),3031));
cat * |jq '.results[]|[.upperLeftCornerLongitude,.upperLeftCornerLatitude]|@csv' | sed "s:\"::g;s:,: :g;s:^:'POINT( :g;s:$: )',4326:g" | sed 's:^:ST_GeomFromText( :g;s:$: ):g;s:^:ST_Transform( :g;s:$:,3031 ):g;s:^:ST_AsText( :g;s:$: ):g;s:^:SELECT :g' | sed 's:^:COPY (:g;s:$: ) TO STDOUT;:g' | psql scratch
scene=LC80231222014362LGN00; curl -s "https://api.developmentseed.org/landsat?search=${scene}" |jq '.results[]|[.upperLeftCornerLongitude,.upperLeftCornerLatitude]|@csv' | sed 's:"::g;s:,: :g;s:^:POINT( :g;s:$: ):g'
outdir=out/; a="'";db=scratch; antarctic_scenes=$( echo "copy ( select path,row from wrs2_asc_desc where row >= 120 and row <= 122 ) to stdout with csv header;" | psql $db | sed '1d' ); echo "$antarctic_scenes" | parallel --gnu 'landsat search -p {} -l 1 2>/dev/null | grep sceneID | grep -oE "LC8.*$" | sed "s:\",\s*$::g" | xargs -I :: curl -s "https://api.developmentseed.org/landsat?search=::" | jq '$a'.results[]|[.lowerLeftCornerLongitude,.lowerLeftCornerLatitude,"",.lowerRightCornerLongitude,.lowerRightCornerLatitude,"",.upperRightCornerLongitude,.upperRightCornerLatitude,"",.upperLeftCornerLongitude,.upperLeftCornerLatitude,"",.lowerLeftCornerLongitude,.lowerLeftCornerLatitude]|@csv'$a' | sed '$a's:\\::g;s:"::g;s:\(,\{2\}\):|:g;s:,: :g;s:|:,:g;s:^:POLYGON((:g;s:$:)):g'$a' | wellknown > '$outdir'/$( echo {} | sed "s:,::g" ).geojson'
# get wkt points one per line
db=scratch; antarctic_scenes=$( echo "cop( select path,row from wrs2_asc_desc where row >= 120 and row <= 122 ) to stdout with csv header;" | psql $db | sed '1d' ); echo "$antarctic_scenes" | parallel --gnu 'landsat search -p {} -l 1 2>/dev/null | grep sceneID | grep -oE "LC8.*$" | sed "s:\",\s*$::g" | xargs -I :: curl -s "https://api.developmentseed.org/landsat?search=::" | grep -i browse | grep http | grep -oE "http.*\",$" | sed "s:\",$::g"'
# get wkt points as single multipoint
cat * |jq '.results[]|[.upperLeftCornerLongitude,.upperLeftCornerLatitude]|@csv' | sed "s:\"::g;s:,: :g;s:^:'POINT( :g;s:$: )',4326:g" | sed 's:^:ST_GeomFromText( :g;s:$: ):g;s:^:ST_Transform( :g;s:$:,3031 ):g;s:^:ST_AsText( :g;s:$: ):g;s:^:SELECT :g' | sed 's:^:COPY (:g;s:$: ) TO STDOUT;:g' | psql scratch | sed 's:^POINT::g' | tr '\n' ',' | sed 's:,$::g' | sed 's:^:MULTIPOINT (:g;s:$: ):g' | clipboard
@albert-decatur
Copy link
Author

great example scene with topographical features visible:
LC80231222014362LGN00

  • this scene is upside down out of landsat-util (has negative lat in epsg 3031)
  • MTL corners are image BBOX including nodata
  • landsat-api corners are image BBOX w/o nodata

landsat-api corners:

MTL corners:
CORNER_UL_LAT_PRODUCT = -83.13193
CORNER_UL_LON_PRODUCT = 171.66491
CORNER_UR_LAT_PRODUCT = -82.51633
CORNER_UR_LON_PRODUCT = 155.21012
CORNER_LL_LAT_PRODUCT = -80.99184
CORNER_LL_LON_PRODUCT = 173.65981
CORNER_LR_LAT_PRODUCT = -80.51567
CORNER_LR_LON_PRODUCT = 160.69660
CORNER_UL_PROJECTION_X_PRODUCT = 108300.000
CORNER_UL_PROJECTION_Y_PRODUCT = -739200.000
CORNER_UR_PROJECTION_X_PRODUCT = 341400.000
CORNER_UR_PROJECTION_Y_PRODUCT = -739200.000
CORNER_LL_PROJECTION_X_PRODUCT = 108300.000
CORNER_LL_PROJECTION_Y_PRODUCT = -974700.000
CORNER_LR_PROJECTION_X_PRODUCT = 341400.000
CORNER_LR_PROJECTION_Y_PRODUCT = -974700.000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment