[gdal-dev] Any trick to run SELECT gdal_get_pixel_value for lots of points?
Even Rouault
even.rouault at spatialys.com
Thu Jan 19 11:24:10 PST 2023
Hi Jukka,
Recursive Common Table Expressions (CTE) (cf "3.1. Recursive Query
Examples" of https://www.sqlite.org/lang_with.html) can help if you want
to sample along one or two axis
Below an example for x in [1,3] and y in [1,4]
$ ogr2ogr -of CSV /vsistdout/ :memory: -sql "WITH RECURSIVE list_x(x) AS
(VALUES(1) UNION ALL SELECT x+1 FROM list_x WHERE x<3), list_y(y) AS
(VALUES(1) UNION ALL SELECT y+1 FROM list_y WHERE y<4) SELECT x, y,
gdal_get_pixel_value('byte.tif', 1, 'pixel', x, y) as val FROM list_y,
list_x" --config OGR_SQLITE_ALLOW_EXTERNAL_ACCESS YES
x,y,val
"1","1","132"
"2","1","107"
"3","1","123"
"1","2","132"
"2","2","140"
"3","2","132"
"1","3","132"
"2","3","123"
"3","3","123"
"1","4","156"
"2","4","132"
"3","4","140"
Otherwise if you have a list of (x,y) values in a OGR readable format
(CSV, etc.), you could select the x, y values from it:
$ cat list_points.csv
x,y
1,2
3,4
5,6
$ ogr2ogr -of csv /vsistdout/ list_points.csv -sql "SELECT x, y,
gdal_get_pixel_value('byte.tif', 1, 'pixel', cast(l.x as real), cast(l.y
as real)) AS val FROM list_points l" -dialect SQLite --config
OGR_SQLITE_ALLOW_EXTERNAL_ACCESS YES
x,y,"val"
"1","2","132"
"3","4","140"
"5","6","132"
Even
--
http://www.spatialys.com
My software is free, but my time generally not.
More information about the gdal-dev
mailing list