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 )
After rasterizing using this code X Axis: 0 to 250 Y Axis: 250 to 0
ie its crs value is lost (I guess)
How can I regulate the pixel size here.
You can use the outBounds
and width/height
keywords to control the output resolution. For example, if you want the output resolution to be 0.005 degrees, you can define these as:
gdal.Grid(
"trial2.tif","merged2018-19.gpkg", zfield="h_li",algorithm="nearest",
width=600, # --- width of the output raster in pixel
height=800, # --- height of the output raster in pixel
outputBounds=[74, 38, 78, 35], # --- assigned output bounds: [ulx, uly, lrx, lry]
)
You get the width/height in pixels by dividing the width/height in degrees by the resolution.
600 = 3/0.005
800 = 4/0.005
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
. Using gdal.Grid
would be interpolating the data (also create output values in between the features).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.