[gdal-dev] Coordinate space to pixel space with image rotation in python

Nicolas Cadieux njacadieux.gitlab at gmail.com
Fri Oct 16 08:51:17 PDT 2020


On 2020-10-16 11:49 a.m., Nicolas Cadieux wrote:
> Hi again! (a few months later...)
>
> What is the best practice for reading a single pixel in the raster?
>
> structval = raster_band.ReadRaster(column, row, 1, 1, 1, 1, 
> raster_band.DataType)
>
> or
>
> structval = raster_band.ReadRaster(int(column), int(row), 1, 1, 1, 1, 
> raster_band.DataType)
>
> Nicolas
>
> On 2020-01-28 12:30 p.m., Even Rouault wrote:
>> Nicolas,
>>
>>> It's easy to go from coordinate space to pixel space in python using
>>> something like.
>>>
>>> pixel_x  =  int(-124114.3  - geo_transform[0])/geo_transform[1])
>>>
>>> What is the trick when there is an image rotation?
>> Compute the inverse geotransform with
>> https://gdal.org/api/raster_c_api.html?highlight=invgeotransform#_CPPv419GDALInvGeoTransformPdPd 
>>
>>
>> (gdal.InvGeoTransform(gt) in Python )
>>
>> And then use the coordinates in coordinate space as the input for 
>> this inverse geotransform
>>
>> column = inv_gt[0] + X * inv_gt[1] + Y * inv_gt[2]
>> row    = inv_gt[3] + X * inv_gt[4] + Y * inv_gt[5]
>>
>>
>>> Also, as a second
>>> very beginner question, what is the difference between geo_transform[2]
>>> and geo_transform[4]?
>> There are defined by the relationships at
>> https://gdal.org/user/raster_data_model.html#affine-geotransform
>>
>> Even
>>


More information about the gdal-dev mailing list