I was trying to rasterize the vector file in python.
I used this code:
gdal.Grid("trial2.tif","merged2018-19.gpkg",zfield="h_li",algorithm="nearest")
(the crs of vector data is in EPSG: 4326 )
- On plotting the vector file in jupyter it showed the coordinates X axis: 74 to 78 (longitude value) Y axis: 35 to 38 (latitude value)
After rasterizing using this code X Axis: 0 to 250 Y Axis: 250 to 0
ie its crs value is lost (I guess)
- it created a raster file but with pixel resolution (0.015625 degree, 0.01171875 degree) which is quite large enough.
How can I regulate the pixel size here.
You can use the
outBoundsandwidth/heightkeywords to control the output resolution. For example, if you want the output resolution to be 0.005 degrees, you can define these as:You get the width/height in pixels by dividing the width/height in degrees by the resolution.
You can consider also adding
outputSRS="EPSG:4326"if the output CRS is not set correctly.Btw, the term "rasterize" is normally used for converting vector features to a raster representation ("pixelized"). This is done with
gdal.Rasterize. Usinggdal.Gridwould be interpolating the data (also create output values in between the features).