0

I tried several ways and still haven't managed to do it:

Using gdal_rasterize:

import ogr,gdal 
output_raster = 'C:\new_raster.tif'
input_shp = ogr.Open('C:\input_vector.shp')
shp_layer = input_shp.GetLayer()

pixel_size = 0.1
xmin, xmax, ymin, ymax = shp_layer.GetExtent()

ds = gdal.Rasterize(output_raster, input_shp, xRes=pixel_size, yRes=pixel_size, 
                    burnValues=0, outputBounds=[xmin, ymin, xmax, ymax], 
                    outputType=gdal.GDT_Byte)
ds = None

I get the error: TypeError: in method 'wrapper_GDALRasterizeDestName', argument 2 of type 'GDALDatasetShadow *'

Using geocube library:

from geocube.api.core import make_geocube
import geopandas as gpd

file = gpd.read_file('C:\salzburg_shape.shp')
cube = make_geocube(
    file,
 #   measurements=["geometry"],
    resolution=(1, -1),
)

file.rio.to_raster('C:\salzburg_shape.tif')

I get the error ValueError: at least one array or dtype is required. For more background when opened with geopands, my file looks like this: enter image description here

And this is other information about the file: {'driver': 'GTiff', 'dtype': 'uint8', 'height': 38.0, 'width': 39.0, 'count': 1, 'crs': Name: MGI / Austria GK Central Axis Info [cartesian]:

  • X[north]: Northing (metre)
  • Y[east]: Easting (metre) Area of Use:
  • name: Austria - 11°50'E to 14°50'E
  • bounds: (11.83, 46.4, 14.84, 48.79) Coordinate Operation:
  • name: Austria Gauss-Kruger Central
  • method: Transverse Mercator Datum: Militar-Geographische Institut
  • Ellipsoid: Bessel 1841
  • Prime Meridian: Greenwich , 'transform': Affine(100.09328205128296, 0.0, -16426.428000000014, 0.0, -102.44973684210517, 221959.16), 'compress': 'lzw'}
SNunes
  • 11
  • 2

0 Answers0