2

I have approximate coordinates of a box I need to work with the data, but I want the integer window in order to use the exact edge pixels. Using gdal_translate I get the box using projwin but I want to know the computed srcwin and use that instead.

How can I get it?

gdal_translate -projwin -3073414.9453 1649666.7710 -1749065.1524 2345626.7903 ../data/goes16.abi-2021.0206.1601-CMI-C03_1km.tif goes16.abi-2021.0206.1601-CMI-C03_1km.tif
Input file size is 5000, 3000
ERROR 1: buildCS: missing UNIT
0...10...20...30...40...50...60...70...80...90...100 - done.

The data info is

$ gdalinfo ../data/goes16.abi-2021.0206.1601-CMI-C03_1km.tif 
Driver: GTiff/GeoTIFF
Files: ../data/goes16.abi-2021.0206.1601-CMI-C03_1km.tif
Size is 5000, 3000
ERROR 1: buildCS: missing UNIT
Origin = (-3627271.328111211769283,1583173.512170388596132)
Pixel Size = (1002.008657743770527,1002.008657743770527)
Corner Coordinates:
Upper Left  (-3627271.328, 1583173.512) 
Lower Left  (-3627271.328, 4589199.485) 
Upper Right ( 1382771.961, 1583173.512) 
Lower Right ( 1382771.961, 4589199.485) 
Center      (-1122249.684, 3086186.499) 
Band 1 Block=5000x1 Type=Float32, ColorInterp=Gray
  NoData Value=-1
  Metadata:
    add_offset=0
    ancillary_variables=DQF
    cell_methods=t: point area: point
    coordinates=band_id band_wavelength t y x
    grid_mapping=goes_imager_projection
    long_name=ABI L2+ Cloud and Moisture Imagery reflectance factor
    NETCDF_VARNAME=CMI
    resolution=y: 0.000028 rad x: 0.000028 rad
    scale_factor=0.00031746001
    sensor_band_bit_depth=10

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
  • Try to run the command with --debug on. With some drivers the srcwindow is shown in the debug messages. – user30184 Feb 15 '21 at 21:31

1 Answers1

3

You can calculate your srcwin from the Origin coordinates and Pixel Size in the gdalinfo output using the formula

x_pixel = floor((x_coord - x_origin) / x_size)
y_pixel = floor((y_coord - y_origin) / y_size)

So for an x, y coordinate of one corner of your projwin (for example -3073414.9453 1649666.7710)

x_pixel = floor((-3073414.9453 - -3627271.328111211769283) / 1002.008657743770527)
y_pixel = floor((1649666.7710 - 1583173.512170388596132) / 1002.008657743770527)
x_pixel = 552
y_pixel = 66

And can be put into an Excel/LibreOffice Calc formula:

enter image description here

user2856
  • 65,736
  • 6
  • 115
  • 196