2

Some Sentinel-2B band images have slight spatial misalignments as I explained on the step forum. https://forum.step.esa.int/t/sentinel-2-tci-10m-level-2-images-slight-spatial-misregistrations/14235

Furthermore the gml/jp2 band image header goes uncorrected. I need to extract pixel values from these images as if they had been spatially aligned properly - e.g. by taking into account a 1 pixel vertical shift downwards.

Can I do this using command-line parameters to gdalwarp : https://www.gdal.org/gdalwarp.html - the program I use to extract polygons of pixels?

  • 1
    Depending on how the images are georeferences if might be enough to extract the bands into separate images and use gdal_edit gdal.org/gdal_edit.html for setting the upper-left and lower-right corners -a_ullr ulx uly lrx lry:Assign/override the georeferenced bounds of the dataset.. – user30184 Mar 10 at 16:25
  • That's good. While directly editing the gml in the header failed for me - using gdal_edit.py to do so works! thanks @user30184 – GavinBrelstaff Mar 10 at 17:59
  • Would you mind to write that as an answer with a full usage example about gdal_edit.py? – user30184 Mar 10 at 18:22
  • Okay @user30184 I've now added my answer. – GavinBrelstaff Mar 11 at 16:42
1

Here is a bit of bash script that takes an GML/JP2 image file from Sentinel-2B Level-2 10m resolution product and corrects its header. First it extracts the existing corner-coordinates using gdalinfo (twice); then it adds 10m to the two latitude values; then it writes the new corner coordinates back into the original image header using gdal_edit.py The image in the code is second one from the step forum post at https://forum.step.esa.int/t/sentinel-2-tci-10m-level-2-images-slight-spatial-misregistrations/14235

SUBIMG=T32SMJ_20180404T101019_TCI_10m.jp2

tmp=`gdalinfo  $SUBIMG | tr '.' ' ' | awk '/Upper Left/{ print $4" "$6}'`
uly=${tmp% *}         #first word
let ulx=10+${tmp##* } #second word plus 10

tmp=`gdalinfo  $SUBIMG | tr '.' ' ' | awk '/Lower Right/{print $4" "$6}'`
lry=${tmp% *}         #first word
let lrx=10+${tmp##* } #second word plus 10

gdal_edit.py -a_ullr $uly $ulx $lry $lrx  $SUBIMG

Of course the 10m change is only what I judged to be necessary by eye.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.