<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Wonderful, thank you Thomas, that has indeed resolve the issue</p>
<p>Best,</p>
<p>Conor<br>
</p>
<div class="moz-cite-prefix">On 12/01/2021 12:02, thomas bonfort
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAOM3y2hGktoryY+G3i3QL5p6VUJem-YMRN942jk8K3nKX2j-nA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">Conor,
<div>I suspect that you should add an </div>
<div>extern "C" {</div>
<div>void GDALRegisterMe();<br>
</div>
<div>}</div>
<div>line at the beginning of your cpp file.</div>
<div><br>
</div>
<div>--</div>
<div>Thomas</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Jan 12, 2021 at 12:56
PM Conor McIndoe <<a href="mailto:conormcindoe1@gmail.com"
moz-do-not-send="true">conormcindoe1@gmail.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello
developers,<br>
<br>
I am just learning the ropes with GDAL so apologies if some of
this is <br>
quite far off. Also apologies in advance for the essay :)<br>
<br>
I am trying to register a pixel function, written in C++, in
order to <br>
produce a VRT and eventually a TIF from some input TIFs. I am
trying to <br>
follow an thread from this mailing list <br>
(<a
href="https://lists.osgeo.org/pipermail/gdal-dev/2011-May/028742.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/pipermail/gdal-dev/2011-May/028742.html</a>)
to <br>
make GDAL aware of a shared library which contains and
registers the <br>
pixel function. Hopefully there is some clear error here which
one of <br>
you can spot?<br>
<br>
I have adapted the example found at the VRT reference page <br>
(<a href="https://gdal.org/drivers/raster/vrt.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://gdal.org/drivers/raster/vrt.html</a>)
to produce a function which <br>
sets every pixel equal to 1 (just to test the workflow):<br>
<br>
// src/gdalPixelFunctions.cpp<br>
<br>
#include "gdal.h"<br>
#include "cpl_conv.h"<br>
#include "gdal_priv.h"<br>
<br>
#include <iostream><br>
<br>
CPLErr OneFunction(<br>
void **papoSources, int nSources, void *pData,<br>
int nXSize, int nYSize, GDALDataType eSrcType,<br>
GDALDataType eBufType, int nPixelSpace, int nLineSpace<br>
)<br>
{<br>
int ii, iLine, iCol;<br>
double pix_val;<br>
double x0, x3, x4, x8;<br>
<br>
if(nSources != 4) return CE_Failure;<br>
<br>
for(iLine = 0; iLine < nYSize; iLine++)<br>
{<br>
for(iCol = 0; iCol < nXSize; iCol++)<br>
{<br>
ii = iLine * nXSize + iCol;<br>
<br>
/* Source raster pixels may be obtained with
SRCVAL macro */<br>
x0 = SRCVAL(papoSources[0], eSrcType, ii);<br>
x3 = SRCVAL(papoSources[1], eSrcType, ii);<br>
x4 = SRCVAL(papoSources[2], eSrcType, ii);<br>
x8 = SRCVAL(papoSources[3], eSrcType, ii);<br>
<br>
pix_val = 1;<br>
<br>
GDALCopyWords(<br>
&pix_val,<br>
GDT_Float64,<br>
0,<br>
((GByte *)pData) + nLineSpace * iLine + iCol
* nPixelSpace,<br>
eBufType,<br>
nPixelSpace,<br>
1<br>
);<br>
}<br>
}<br>
<br>
return CE_None;<br>
}<br>
<br>
void GDALRegisterMe()<br>
{<br>
std::cout << "Inside GDALRegisterME()" <<
std::endl;<br>
GDALAddDerivedBandPixelFunc("OneFunction", OneFunction);<br>
}<br>
<br>
<br>
Compilation:<br>
<br>
g++ -std=c++20 -fPIC -lgdal -c src/gdalPixelFunctions.cpp -o <br>
build/gdal_pixelFunctions.o<br>
<br>
g++ -lgdal -shared build/gdal_pixelFunctions.o -o <br>
build/gdal_pixelFunctions.so<br>
<br>
export GDAL_DRIVER_PATH="/path/to/build"<br>
<br>
<br>
Attempting to call:<br>
<br>
gdal_translate testVrt.vrt testVrt.tif<br>
<br>
(where testVrt.vrt references the OneFunction pixel function)
results in <br>
the following error messages:<br>
<br>
ERROR 1: /path/to/build/gdal_pixelFunctions.so: undefined
symbol: <br>
GDALRegisterMe<br>
ERROR 1: /path/to/build/gdal_pixelFunctions.so: undefined
symbol: <br>
GDALRegister_pixelFunctions<br>
<br>
I have also tried registering by defining a void <br>
GDALRegister_pixelFunctions() but with the same issue. I
assume this <br>
error means that GDAL is looking in the shared library for
these two <br>
register functions and failing to find them?<br>
<br>
Thank you for your help and sorry for the long post!<br>
<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank"
moz-do-not-send="true">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote>
</div>
</blockquote>
</body>
</html>