# How to rasterize a geopackage (Corine Land Cover)?

**URL:** <https://discourse.julialang.org/t/how-to-rasterize-a-geopackage-corine-land-cover/115316>\
**Category:** Geo\
**Created:** [June 7, 2024, 9:43am UTC](https://discourse.julialang.org/t/how-to-rasterize-a-geopackage-corine-land-cover/115316 "2024-06-07T09:43:26Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [June 7, 2024, 12:55pm UTC](https://discourse.julialang.org/t/how-to-rasterize-a-geopackage-corine-land-cover/115316/21 "2024-06-07T12:55:41Z")

</div>

You may be able to use `Rasters.coverage` for each land use separately and then combine them with `maximum`?

I guess we could build that into `rasterize`…

Is there another GIS function somewhere that does this we could copy?

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 7, 2024, 1:13pm UTC](https://discourse.julialang.org/t/how-to-rasterize-a-geopackage-corine-land-cover/115316/22 "2024-06-07T13:13:44Z")

</div>

Yes, geometries are not squares, so I may have a destination raster pixel which is “covered” by 40% forest (id=1), 30% agriculture (id=2) and 30% artificial area (id=3), and in that case the pixel should have the value 1.

I’ll try the `Rasters.coverage`…

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 7, 2024, 3:08pm UTC](https://discourse.julialang.org/t/how-to-rasterize-a-geopackage-corine-land-cover/115316/23 "2024-06-07T15:08:33Z")

</div>

Thank you, this seems to achieve what I was looking for:

```julia
clc2018df = GeoDataFrames.read(clc2018_path)
DataFrames.rename!(clc2018df,"Shape" => "geometry")
clc_311 = clc2018df[clc2018df.Code_18 .== "311",:]
clc_312 = clc2018df[clc2018df.Code_18 .== "312",:]
clc_313 = clc2018df[clc2018df.Code_18 .== "313",:]
clc_311_share = Rasters.coverage(clc_311; to=mask) # `mask` is my raster grid mask
clc_312_share = Rasters.coverage(clc_312; to=mask)
clc_313_share = Rasters.coverage(clc_313; to=mask)

```

Just a nuisance, the coverage command took forever because lots of info were printed :

```julia
[ Info: A geometry was ignored at Extents.Extent{(:X, :Y), Tuple{Tuple{Float64, Float64}, Tuple{Float64, Float64}}}((X = (3.4718729800000004e6, 3.47309808e6), Y = (1.991912e6, 1.9929848200000003e6))) as it was outside of the supplied extent Extents.Extent{(:X, :Y), Tuple{Tuple{Float64, Float64}, Tuple{Float64, Float64}}}((X = (2.984e6, 4.322e6), Y = (1.993e6, 3.211e6)))

```

In my case this is ok, as the vector is way larger than the area under study. I think the info message should be printed only if `verbose` is set to true.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [June 8, 2024, 7:21pm UTC](https://discourse.julialang.org/t/how-to-rasterize-a-geopackage-corine-land-cover/115316/24 "2024-06-08T19:21:26Z")

</div>

~~You can use `verbose=false` to turn off the info printing (check the docs for all these keywords)~~ Oh you mean that still doesn’t stop it. Yes we should fix that: [Dont print coverage info with `verbose=true` · Issue #680 · rafaqz/Rasters.jl · GitHub](https://github.com/rafaqz/Rasters.jl/issues/680)

`coverage` will always be kinda slow compared to `rasterize` because it actually has to rasterize 100 points for each pixel. But still its very likely that `Rasters.coverage` is the fastest coverage function available in any language.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [June 8, 2024, 7:24pm UTC](https://discourse.julialang.org/t/how-to-rasterize-a-geopackage-corine-land-cover/115316/25 "2024-06-08T19:24:42Z")

</div>

It would be good to somehow put your code into a single function in Rasters.jl, like `rasterize(last, geoms; by_coverage=maximum, kw...)` could do it?

(I think we need both `last` and `maximum` in case there are multiple with the same coverage)

> <https://github.com/rafaqz/Rasters.jl/issues/681>
>
> It would be good to be able to select one of multiple values not by last/sum etc…, but by the amount of coverage each had.
> 
> Likely we still need \`last\` as multiple values will often have the same coverage (e.g. \`1.0\`).
> 
> https://discourse.julialang.org/t/how-to-rasterize-a-geopackage-corine-land-cover/115316/23?u=raf

[Previous page](https://discourse.julialang.org/t/how-to-rasterize-a-geopackage-corine-land-cover/115316.md?page=1)
