1

In the code below, I'm trying to rasterize "roads" and "cube" to 128x128 pixels with a 10m spatial resolution for each pixel. First, I want to rasterize roads separately to make them look better by using the option "all_touched"=True. And then I want to merge them to the same raster.

How do I use the option "all_touched=True"?

for idx,row in enumerate(clip.itertuples()):
    if row.code_2018 !=None:
        train_id[idx]=(class_dic[str(row.code_2018)]['train_id'])

clip = clip.assign(train_id=train_id) roads=clip.code_2018.isin(['12210','12220','12230']) roads = clip[roads] cube = make_geocube( vector_data=clip, measurements=['train_id'], resolution=(10,-10) ) roads = make_geocube( vector_data=roads, measurements=['train_id'], resolution=(10,-10) ) break

[![want to merge these][1]][1]
[1]: https://i.stack.imgur.com/hOUbu.png

Hornbydd
  • 43,380
  • 5
  • 41
  • 81
Oskar
  • 11
  • 2
  • Welcome to GIS SE. As a new user, please take the [Tour], which emphasizes the importance of asking One question per Question. Bullet lists of questions will result in closure votes. Please [Edit] the Question to focus on your most pressing issue. – Vince Apr 04 '22 at 11:16

1 Answers1

2

You want to follow the pattern demonstrated here: https://corteva.github.io/geocube/stable/examples/rasterize_point_data.html

from functools import partial
from geocube.rasterize import rasterize_image

roads = make_geocube( vector_data=roads, measurements=['train_id'], resolution=(10,-10), rasterize_function=partial(rasterize_image, all_touched=True), )

Also see: https://corteva.github.io/geocube/stable/geocube.html#geocube.rasterize.rasterize_image

snowman2
  • 7,321
  • 12
  • 29
  • 54