[QGIS-Developer] Coordinates of a pixel

Charles Dixon-Paver charles at kartoza.com
Mon Aug 31 15:01:47 PDT 2020


Someone can correct me if I'm wrong, but I think there's a misunderstanding
here of how this raster data is handled in a GIS. From my understanding of
the question, I don't know that what you're asking for is available "in the
code" the way you expect.

The coordinates are showing the position of the cursor relative to the
origin of the assigned coordinate reference system. The raster data is
"projected" onto that reference system, which assigns positions to some
points on the image and stretches, rotates or distorts the image in
accordance with the images affine parameters that ensure all the different
parts of the image remain spatially correct. How the GIS knows where to get
these parameters varies between data types and file formats.

Playing around with the georeferencer tool in QGIS should give you a pretty
clear understanding of how this "projection" works.

There are ways to get the coordinates of a position or pixel within an
image programmatically, the easiest of which that I can think of is using
values from a world file [1] with an xy position (in pixels) of the pixel
of interest. The code required for achieving this, however, is probably
going to be dependant on a wide variety of factors (not least of all the
CRS units and pixel size). Alternatively, you could likely grab the
coordinate position of a pixel from within a QGIS project, but that doesn't
seem to be what you're after. Perhaps a developer familiar with the GDAL or
QGIS code bases can point you in the direction of some wizardry that will
achieve what it is you are looking for without a clearer understanding of
your use case though.

[1] https://en.wikipedia.org/wiki/World_file

On Mon, 31 Aug 2020 at 19:57, Miguel-Ángel Fas-Millán <fas.millan at gmail.com>
wrote:

> Hi all,
> New around here and as a QGIS user. I need to find something in the
> code, I hope you can help me.
> When you open a DSM and place the mouse on any pixel, you can see the
> coordinates of that point. Could someone tell me where in the code is made
> the calculation of those coordinates?
>
> Regards,
>
> Angel
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200901/2fb0477a/attachment.html>


More information about the QGIS-Developer mailing list