In this case the point to achieve speed is more the used algorithms than the language of choice. Drawing and filling poligons rasterized over a grid of pixel falls into the domain of image processing algorithms and for sure AggDraw is using algorithms from that field.
The idea is that if you evaluate for each points a function that considers the vectorial nature of the polygon you need to do a number of operations that is at least O(2*p*A)
where:
- A = image area
- p = average number of points in the perimeter of the polygons.
Conversely if you use image processing algorithms for each point you can consider to have a fixed and low number of operations. For example if you consider the FloodFill algorithm it is O(A) and I can say it is less than 30*A (about 30 operations per pixel).
So basically since the GADM polygons has many vertex is better to eliminate the vectorial nature of the problem as soon as possible and go with something like this:
- construct the pixel map of the boundary
- find one internal pixel
- use the Floodfill algorithm that will work without any need to know about polygons as vectorial entities
The same algorithms can for sure be implemented in Numpy but before going for a Numpy graphical lib I would suggest to do the following:
- measure the time spent in your code for the various steps:
- Numpy array to AggDraw lists/sequences conversion
- time taken by AggDraw
- try to decimate the vertex of the polygons removing the ones that stay in the same pixel based on the current Zoom level and see if an how the times will be reduced