Rasters.jl icon indicating copy to clipboard operation
Rasters.jl copied to clipboard

Intersect between SpatialLines and `AbstractRaster`

Open kongdd opened this issue 3 years ago • 10 comments

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.

kongdd avatar Nov 26 '21 04:11 kongdd

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.

rafaqz avatar Nov 26 '21 08:11 rafaqz

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 between SpatialLine and Raster.
  • xdim: , the dimension of npixel, the distance from the overlaped pixel to the origin of SpatialLine.

Do you have any suggestion how to implement this function, and which package or which function should be used? Thank u!

kongdd avatar Nov 26 '21 08:11 kongdd

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 ?

rafaqz avatar Nov 26 '21 09:11 rafaqz

To further clarify, is your line 2d or 3d?

rafaqz avatar Nov 26 '21 09:11 rafaqz

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?

kongdd avatar Nov 26 '21 09:11 kongdd

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.

rafaqz avatar Nov 26 '21 10:11 rafaqz

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

gianluca-salogni avatar Dec 01 '21 15:12 gianluca-salogni

Hey thanks! but there's a lot of code in that file... could you link the specific lines?

rafaqz avatar Dec 01 '21 15:12 rafaqz

not simple with my old phone now..., i'll be back tomorrow, bye

gianluca-salogni avatar Dec 01 '21 15:12 gianluca-salogni

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..

gianluca-salogni avatar Dec 02 '21 07:12 gianluca-salogni

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

rafaqz avatar Jul 14 '24 00:07 rafaqz

Thanks for your hard work.

kongdd avatar Jul 15 '24 02:07 kongdd