I don't see anything in OTB that does exactly what you need.

The approach you propose seems the right one. I see two other ways :

  • Build a new filter using the Sampling framework. You may re-implement the ThreadedGenerateData() to use your thread pool. ImageSampleExtractorFilter is a good starting point.
  • Using existing OTB filters. Iterate over polygons, for each one :
    • copy it alone in a in-memory OGRDataSource
    • extract an ROI of the image over the polygon extent
    • rasterize the polygon in a binary mask over the input image ROI
    • with ManageNoData, apply the binary mask as a no-data on the input image ROI
    • use ComputeImagesStatistics with the background value corresponding to no-data
    • store the results in the current polygon.
My 2 cents,


On 08/03/2018 05:34 PM, Jordi Inglada wrote:

Given an image (raster) and a vector file containing polygons, I need to
compute a series of values for each polygon like the mean of a
particular band of the raster, etc. and then produce a new (or update
the) vector file with new fields. I think these are called zonal

It looks like the LSMSVectorization application does that, but it uses a
raster segmentation instead of an input vector file. Given that my
polygons cover only a small fraction of the input raster, I don't think
than rasterizing the vector file to use this application will be
efficient. An besides, I would have to link back the attributes to the
original polygons, which is an additional step.

Is there any other way to do that with existing OTB applications? Maybe
gdal command line tools can do that? I have been looking around and it
seems that this is usually done the way LSMSVectorization does it (burn
the vector to raster, then compute using rasters only).

Do you have any advice on how to proceed if I need to write my own
application for that? I guess I will have to if I want to be able to
compute other features than mean and variance of the raster bands.

By the way, my images and vector data are huge, so streaming and
multi-threading will be needed.

I was thinking about the following approach:

1. Read in a set of polygons until a total surface is reached (so that
   we can associate that with the RAM needed for the total number of raster
   pixels to keep in memory).
2. Project the polygons onto the raster geometry and read in the pixels
3. Parallel computation of the stats (either with an OpenMP loop or a
   simple thread pool [1])
4. Write the geometries and the stats to the output file
5. Release the memory and go back to 1

Any comments on that?



[1] https://jordiinglada.net/wp/2015/05/13/a-simple-thread-pool-to-run-parallel-prosail-simulations/

Guillaume PASERO
Responsable technique
Business Unit ESPACE & GeoInformation - Département Payload Data & Applications

CS Systèmes d'Information
Parc de la Grande Plaine - 5, Rue Brindejonc des Moulinais - BP 15872
31506 Toulouse Cedex 05 - FRANCE
+33 561 17 64 21 - guillaume.pas...@c-s.fr

Check the OTB FAQ at
You received this message because you are subscribed to the Google
Groups "otb-users" group.
To post to this group, send email to otb-users@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group at
You received this message because you are subscribed to the Google Groups "otb-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otb-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to