How can I rasterize the polygons of a Shapefile in Julia?

Thank you very much, all three of you! By peeking at your examples I easily managed to rasterize my Argentina demo shapefile at a country level. This works brilliantly in both GDAL and ArchGDAL. (GMT looks very promising too but I had some install problems, see the separate post.)

However, I completely hit the wall when trying to rasterize the subregions of Argentina. It took three hours before I had a working solution. The problem was that the demo shapefile lacked an attribute that contained a numerical index that I could use to burn into the raster. The index field GID_1 contained strings of the format "ARG.24_1". So I needed to brush up on some long forgotten SQL knowledge to finally get this working on the command line:

gdal_rasterize.exe -a GID_1 -ot Byte -ts 3000 5000 -dialect SQLite -sql "SELECT CAST(substr(GID_1,5) AS INTEGER)*10+15 AS GID_1,* FROM gadm36_ARG_1" gadm36_ARG_1.shp arg.tif

But then when I tried to transfer those options to GDAL.jl, I got this:

ERROR: LoadError: GDALError (CE_Failure, code 6):
        The SQLite driver needs to be compiled to support the SQLite SQL dialect

So I had to use ogrinfo to add a numerical index FID to the SQL table of the shapefile, and after that it was easy to burn that into the raster using the -a FID option.

Would it be possible to compile the SQLite driver into GDAL.jl? Another thing that would be useful would be if there were a simple way to access the command line versions of gdal_rasterize, ogrinfo, ogr2ogr, etc. I had to copy a bunch of lib*.dll files into my $HOME\.julia\packages\GDAL\vec6Y\deps\usr\bin folder to get those commands working.

Again, this would all have been easy were it not for the fact that my demo shapefile happened to lack that index that most other shapefiles have. Bad luck I guess, but I learned a lot in the process.

1 Like