Closed DahnJ closed 1 month ago
https://gdal.org/en/latest/user/raster_data_model.html
AREA_OR_POINT: May be either "Area" (the default) or "Point". Indicates whether a pixel value should be assumed to represent a sampling over the region of the pixel or a point sample at the center of the pixel. This is not intended to influence interpretation of georeferencing which remains area oriented.
Thanks for the quick answer @snowman2 !
I interpret your answer as saying: coordinates should stay the same in the in-memory xarray dataset both cases. The only difference is how they are then intepreted. It's up to the user to make the right choice. Am I interpreting it correctly?
To me, this makes the docstring for open_rasterio quite confusing, specifically:
The x and y coordinates are generated automatically from the file's geoinformation, shifted to the center of each pixel
I read that as: in-memory representation's coordinates always represent the center of the pixel. That seems to me in direct contradiction with the above, where in the PixelIsArea
case, the coordinates (without any shifting) would refer to the top-left corner of the pixel.
More relevant links for future visitors:
@DahnJ
The x and y coordinates are generated automatically from the file's geoinformation, shifted to the center of each pixel
That refers to coordinate values stored in the x,y
coordinate arrays. Here "pixel coordinate" refers to the physical location in the world of the center of the pixel. Image coordinate of 0.0,0.0
always refers to the top left corner of the top left pixel, and Affine matrix maps from pixel image coordinates to world coordinates. Point a.x[i], a.y[j]
is always world location of the pixel center for pixel a[j, i]
, regardless of the underlying format of the input file.
But I agree "shifted" is probably not the best word to use to describe it.
Thank you @Kirill888 for the answer.
We've seen that, for both Point
and Area
gdalinfo
does not changerioxarray
do not changeYou also mention
0.0,0.0
always refers to the top left corner of the top left pixela.x[i], a.y[j]
is always world location of the pixel center for pixel a[j, i]
Then what does change? I'm failing to see any difference between files with Area
and Point
.
The difference is in what transform is stored in the geotiff tags inside the file. By the time rasterio library sees the transform it has been normalised by gdal to be equivalent to “area mode”. It’s really just a quirk of geotiff spec.
I see. And it's something that even gdalinfo
doesn't surface, since it already transforms the geotransform during reading the file to produce the info?
If that's the case, then I think that the line
The x and y coordinates are generated automatically from the file's geoinformation, shifted to the center of each pixel (see
"PixelIsArea" Raster Space <http://web.archive.org/web/20160326194152/http://remotesensing.org/geotiff/spec/geotiff2.5.html#2.5.2>
_ for more information). (source)
is likely to lead people astray rather then help. It has done that for me and a handful of other people I've asked and the area/point distinction seems to even have managed to confuse the author of the GDAL code. If this transformation is truly an implementation detail that GDAL takes care of then I'd say rioxarray does not need to refer to it.
I can see value in saying something like
The x and y coordinates are generated from the file's geoinformation and refer to the center of the pixel.
This clarifies the meaning of the coordinates without sending them into a rabbit hole that ultimately doesn't help them.
What do you think @snowman2? Happy to open a PR.
Yes, a PR with clarification is welcome.
@snowman2 great, thanks. Made the change here https://github.com/corteva/rioxarray/pull/811
Code Sample & Problem description
I have two sample file that only differ on their
AREA_OR_POINT
specification (sample_tifs.zip)when I read them, I would expect the coordinates of one of those to be shifted, as mentioned in the docstring for open_rasterio (link):
However, I don't observe this behaviour
How were the files created: I have taken a sample of SRTM data and have altered the metadata property using
gdal_edit
Am I doing something wrong here, or have I misunderstood the
AREA_OR_POINT
property?Expected Output
I expected the coordinates to be shifted for one of the options and thus differ between them.
Perhaps that expectation is wrong and the coordinates are simply always shited to the same location with rioxarray. But then it would suggest to me that for
PixelIsPoint
(Raster Space docs), the coordinates, as read by rioxarray, are actually half a pixel away from where the point was sampled, which would be surprising to me.I may have also potentially created the files in the wrong way.
Environment Information
Installation method
Conda
Conda environment information (if you installed with conda):
Environment (
conda list
):keywords for easy search in the future:
Raster Space
,GTRasterTypeGeoKey
,PIXEL_OR_AREA
,PixelIsArea
,PixelIsPoint
,pixelCenter