Rasters.jl
Rasters.jl copied to clipboard
Intersect between SpatialLines and `AbstractRaster`
Dear @rafaqz
Any idea how to calculate the intersection between SpatialLines and AbstractRaster?
It is valuable for cross section analysis, e.g., https://unidata.github.io/MetPy/latest/examples/cross_section.html.
Regards.
Can you explain a little more what you mean? Its not something I've done. Give me an example of the data you have and what the result should be.
Taking geopotential height as example:
The Input:
Raster: with the dim of[nlon, nlat, ntime, nlev]SpatialLine: a SpatialLine object
The expected Output:
cliped_data: with the dim of[npixel, ntime, nlev]; npixel is the overlaped pixels betweenSpatialLineandRaster.xdim: , the dimension ofnpixel, the distance from the overlaped pixel to the origin ofSpatialLine.
Do you have any suggestion how to implement this function, and which package or which function should be used? Thank u!
Im just working on line clipping and distance from a line literally right now. So Rasters.jl should be able to do that in a few weeks... If you want to write the distance from a line algorithm that would be a huge help. I already have a PR mostly done for pixels that overlap a line.
GeoInterface.jl for lines, and maybe NearestNeighbors.jl ?
To further clarify, is your line 2d or 3d?
It is a really good news.
It is 2d SpatialLine in my case.
I'd like to involve in. Could you tell me where is the function working in process?
Great! Be good to have some help.
Its a work in progress, on my my methods_cleanup branch where I'm reorganizing raster/polygon methods, and trying to make all the polygon operations better and more consistent. Sorry it has too many changes in one PR, its just everything I need to be working for my own work right now so I cant separate it out.
There is a basic but fast 2d line drawing algorithm here, like a graphics method where we just take the angle of the line and bump x/y int counters along it to burn the line into the raster:
https://github.com/rafaqz/Rasters.jl/blob/methods_cleanup/src/polygon_ops.jl#L156-L208
That's what will be used to mask and rasterize lines. When it's a BitArray with some subset of dimensions like x/y, we can just broadcast it over all the other dimensions like elev/time to mask or rasterize it into them. If you just need the points extracted we could also make it return points.
dear @rafaqz and @kongdd, we are doing something similar in the coding exercise you'll find here: https://github.com/DavideFavaro/Tirocinio/blob/master/Porting/Porting%20Envifate/Envifate/src/Tools/Noise.jl (it is our personal basic viewshed algorithm for multiple lines intersecting a raster from an origin, dtm in our case). it's valid for both directions (e.i. start-end && end-start) best regards
Hey thanks! but there's a lot of code in that file... could you link the specific lines?
not simple with my old phone now..., i'll be back tomorrow, bye
after some commits (@davidefavaro) I found the function bouncing from noise pollution to light pollution here: https://github.com/DavideFavaro/Tirocinio/blob/be1c5c2fd79fe9bc15f28cfa363389d7860cf645/Porting/Porting%20Envifate/Envifate/src/Tools/do_light.jl#L403, but the profiles and distances sections start here (we deliberately neglected to rasterize the segments, because in our case study we intend to use this also for the comparison between segments and vectors, for example to verify the attenuation of the sound intensity with respect to different land uses): https://github.com/DavideFavaro/Tirocinio/blob/be1c5c2fd79fe9bc15f28cfa363389d7860cf645/Porting/Porting%20Envifate/Envifate/src/Tools/Noise.jl#L751 I think (@davidefavaro) we can achieve some more compact and readable code in few days..
This works now in extract, you can just extract any kind of geometry from a Raster/RasterStack and get a table (vector of NamedTuple) back
Thanks for your hard work.