-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can one convert a DataFrames into a raster without knowing the resolution and extent? #572
Comments
Looks like you want The easiest way to do it is to combine your Something like this should work: df.geometry = collect(zip(df.Longitude, df.Latitude)))
rasterize(sum, df; res=your_res, crs=your_crs) Its not so well documented but you could also just do: rasterize(sum, df; res=your_res, crs=your_crs, geomcolumn=(:Longitude, :Latitude)) You can also specify |
Hi, Thank you very much for your reply. However, I don't have the resolution and size of the data in this case. How can I perform the above code without this information? |
Maybe you can write an algorithm to guess a resolution from the spacing of the points? Is it originally coming from a square raster or just a scatter? I have not idea what this data is. (to me it doesn't make sense to do this autmatically in Rasters.jl. The failure mode from guessing pixels too small is to use all of your RAM, and there are so many ways people could disagree with any guess Rasters makes - so its better to let people specify what they want. The main way to do this is use another known raster as the |
The data comes from a square raster with a 300-meter resolution. This data was generated from the Sentinel-3 Water (Full Resolution) dataset. |
I need a MWE to be able to investivage this: code I can run that reproduces your example completely, including generating the data. |
I am providing a minimal example dataset and accompanying code for your review. This should help in investigating the issue at hand. Additionally, the dataset (gt_dt.arrow) is available via the provided link . Here is a snippet of the code with error: arrow_table = Arrow.Table("gt_dt.arrow") |
First, I'm wondering if you have an old version of Rasters.jl? thats not the error I get (try an What is actually missing is the using Rasters, Arrow, ArchGDAL, DataFrames
arrow_table = Arrow.Table("/home/raf/Downloads/gt_dt.arrow")
reordered_df = DataFrame(arrow_table)
reordered_df.geometry = collect(zip(reordered_df.lon, reordered_df.lat))
dt_ras = Rasters.rasterize(sum, reordered_df; res=0.1000005, crs=EPSG(4326), fill=:value) You can plot with Makie to verify: using GLMakie
p = plot(dt_ras) |
And make sure that |
Could you please update this for the newer version of Rasters? I am unable to access or install the older version of Rasters. Does this line dt_ras = Rasters.rasterize(sum, reordered_df; res=0.1000005, crs=EPSG(4326), fill=:value) generate a 255-band raster stack data? |
This is for the newer version! I'm saying I think you don't have the newest version |
This worked for me both in What is the output of |
On an older version Rasters did not automatically generate the axes using |
That's an incredibly old version of Rasters.jl - its at 0.9 now and soon 0.10. You must have some other old packages in your system that are holding it back. Try to make a new clean environment in a new folder using You can also try doing |
Did you restart julia? |
After restarting, I still encountered the same error. |
Did you activate the environment again? (immediately after restart - if you already loaded rasters it is too late, start again) I made the plot on Rasters 0.9 with the exact code I pasted above so it almost certainly works. |
Thank you! Now it is working following your suggestion, but it generates a single-band raster. It should be a raster stack with 255 bands, and each band name should be a date. In this context, could you please tell me how to generate the raster stack data using my given data? |
You will need to manually group your data using DataFrames.jl by date, and rasterize each group and make a vector of all of them. I can't teach you how to do this. Then, concatenate all the rasters together on a |
Thank you very much. Your suggestion is working for the RasterStack data. |
Could you please advise me on how to set band names for a RasterStack in my concat_rasters dataset to correspond with dates? I've tried using #setdimnames!(concat_rasters, Band, band_names), but this line isn't working. Unfortunately, I haven't found relevant documentation on this matter. Any assistance would be greatly appreciated. |
You cant just try random commands ;) When you make the Band dimension in |
Thank you very much for your reply. How can I set the names of the bands in a stacked .tif file? This means setting the name for g. |
|
Thank you very much! |
Sorry for my last question. How can raster and rasterstack files be converted into dataframes? |
|
The code provided above only generates values for rows*columns. My question is whether the DataFrame will create columns for x, y, band names, and values, akin to the terra package's as.data.frame(s, xy=TRUE) function in R? |
Thats what it does tho. Each dimension is also a column |
Yes, that is exactly what it outputs? |
Again you must have ancient versions of something to get that result. Please check you are using new packages |
Your suggestion is working. Thanks for this discussion. I hope this will be helpful for many people, including myself and those who love Julia's performance in comparison to R and Python. |
Could someone please assist in converting the attached data into a raster format, given that the resolution and extent are unknown?
The text was updated successfully, but these errors were encountered: