[gdal-dev] clip raster to one cell at coordinates

Michael Sumner mdsumner at gmail.com
Fri Jan 27 00:01:24 PST 2023


Hi Karsten,

An option is to run gdallocationinfo, get the col (P) and row (L) value and
then feed that into

gdal_translate -srcwin P L col -outsize 1 1  in.tif out.tif ##I think
that's right

You otherwise have to do the "grid logic", which (while easy ...) I'd
rather like to see exposed explicitly in GDAL as functionality and I'm
exploring this in various ways atm.  (I think you can't use -projwin as it
seems to need at least a half pixel width and height to count as non zero
so it's still a bit tricky to get the right values).

Cheers, Mike


On Fri, Jan 27, 2023 at 5:01 PM karsten <karsten at terragis.net> wrote:

> Hi All,
>
> in an application I have a user click on a map and I need to
> programmatically clip a raster layer
> to the one raster cell for those coordinates at the click location.
> I was looking e.g. at https://gdal.org/programs/gdal_rasterize.html to
> run as a command
> line tool, but so far could not figure out if I can some can "feed" that a
> vector point to the tool as an input
> without first writing a shape file with the point onto disk.
>
> Does somebody have any pointers to a command line tool (or a python
> example) I could use to achieve this ?
>
> Thanks
> Karsten
>
> Karsten Vennemann
> Principal
>
> Terra GIS LTD
> 2119 Boyer Ave E
> Seattle, WA  98112
> USA
> www.terragis.net
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>


-- 
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsumner at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230127/ce82ef1c/attachment-0001.htm>


More information about the gdal-dev mailing list