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

**URL:** https://discourse.julialang.org/t/how-can-i-rasterize-the-polygons-of-a-shapefile-in-julia/15089
**Category:** Geo
**Tags:** gmt
**Created:** [September 17, 2018, 7:50pm UTC](https://discourse.julialang.org/t/how-can-i-rasterize-the-polygons-of-a-shapefile-in-julia/15089 "2018-09-17T19:50:29Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![yeesian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yeesian/32/652_2.png) [@yeesian](https://discourse.julialang.org/u/yeesian)
#### Post date: [September 18, 2018, 12:51am UTC](https://discourse.julialang.org/t/how-can-i-rasterize-the-polygons-of-a-shapefile-in-julia/15089/4 "2018-09-18T00:51:50Z")

</div>

To follow-up from @visr’s example, the following should work if you have GDAL.jl and ArchGDAL.jl installed:

```julia
import GDAL
using ArchGDAL; const AG = ArchGDAL

AG.registerdrivers() do
    AG.read("/vsizip/gadm36_ARG_shp.zip/gadm36_ARG_1.shp") do source_ds
        GDAL.close(GDAL.rasterize(
            "gadm36_ARG_1.tif",
            Ptr{GDAL.GDALDatasetH}(C_NULL),
            source_ds.ptr,
            GDAL.rasterizeoptionsnew([
                # "-of", "GTiff", # The format/driver. Inferred from filename here.
                # "-l", "gadm36_ARG_1", # The layer(s) used for input features.
                "-ts", "250", "250", # target size: "-ts xsize ysize". Set it to whatever you want.
                "-ot", "Byte"
            ], C_NULL), C_NULL))
    end
end

```

I have left some of the optional arguments as comments in the example above. Feel free to explore [the other options](https://www.gdal.org/gdal_rasterize.html) that you can pass to `GDAL.rasterizeoptionsnew()` in the format above.

I have also [opened an issue](https://github.com/yeesian/ArchGDAL.jl/issues/55) to provide better support (and eventually documentation) for it in ArchGDAL.jl.

---

_[View the full topic](https://discourse.julialang.org/t/how-can-i-rasterize-the-polygons-of-a-shapefile-in-julia/15089)._
