[gdal-dev] Parallelizing Rasterization of Polygons

Jeremy Castagno jdcasta at umich.edu
Tue Dec 4 14:16:53 PST 2018


All,

This is the first time I have used a mailing list so I'm not sure how this
will work out. I was trying to parallelize the rasterization of polygons
with the method GDALRasterizeGeometries
<https://github.com/OSGeo/gdal/blob/master/gdal/alg/gdalrasterize.cpp#L630>.
I was using an in memory raster that pointed to a data buffer and sent this
to GDALRasterGeometries with all appropriate arguments. Everything worked
fine and as expected when running with only 1 thread.  However, when moving
to multiple threads I noticed that only 1 of the processors seemed to have
any affect on the rasterization (meaning only the top half of the image was
raterized and the rest was black.  Upon further inspection of the source
code I think I found the culprit here
<https://github.com/OSGeo/gdal/blob/master/gdal/alg/gdalrasterize.cpp#L772>.

The rasterization does not **directly** occur on the memory buffer from my
passed data set. A chunk of memory is allocated dynamically and
rasterizaton occurs on that memory. After rasterization this chunk of
memory is then written to memory dataset I passed in

So using GDALRasterizeGeometries
<https://github.com/OSGeo/gdal/blob/master/gdal/alg/gdalrasterize.cpp#L630>
will
not work. However upon further inspection I notice a really great *static*
void function that it uses: gv_rasterize_one_shape
<https://github.com/OSGeo/gdal/blob/master/gdal/alg/gdalrasterize.cpp#L806>.
Upon further inspection it looks like it truly does just operate on the raw
memory buffer for rasterization.  It of course calls alot of static
functions through the process.

So the hope is that I can just loop through my geometries myself and call
gv_rasterize_one_shape. Yes I understand that GDALRasterizeGeometries
<https://github.com/OSGeo/gdal/blob/master/gdal/alg/gdalrasterize.cpp#L630> is
doing an optimization of chunking and that I will have to do that myself
when looping through geometries. However.... I see no
gv_rasterize_one_shape function in ANY *header* files. I think it is
somehow private or maybe unexposed and I can't really access it.

I am not much of a c++ programmer but I tried to trick the compiler by
adding the function declaration in a header myself. However it complains
that the symbol can't be found when compiling. Pretty normal makefile that
does this: -L/usr/lib -lgdal

I ran the following shell commands:
objdump -t /usr/lib/libgdal.so ---- but no symbols were found
Its like the symbols have been stripped out of the shared library. Which
I'm really confused because I figured you need the symbnols for
linking...Like I said I'm no C++ expert.
 I tried /usr/lib/libgdal.a and the symbols are there but I dont think I
want to static link.

Anyways I guess I'm just wondering if there is any way for me to access
gv_rasterize_one_shape
<https://github.com/OSGeo/gdal/blob/master/gdal/alg/gdalrasterize.cpp#L806>.

Thanks for your help and this great library!

Jeremy Castagno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20181204/382755da/attachment.html>


More information about the gdal-dev mailing list