Skip to content
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

Intersect between SpatialLines and AbstractRaster #233

Open
kongdd opened this issue Nov 26, 2021 · 10 comments
Open

Intersect between SpatialLines and AbstractRaster #233

kongdd opened this issue Nov 26, 2021 · 10 comments

Comments

@kongdd
Copy link
Contributor

kongdd commented Nov 26, 2021

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.

@rafaqz
Copy link
Owner

rafaqz commented Nov 26, 2021

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.

@kongdd
Copy link
Contributor Author

kongdd commented Nov 26, 2021

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!

@rafaqz
Copy link
Owner

rafaqz commented Nov 26, 2021

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
Copy link
Owner

rafaqz commented Nov 26, 2021

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

@kongdd
Copy link
Contributor Author

kongdd commented Nov 26, 2021

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?

@rafaqz
Copy link
Owner

rafaqz commented Nov 26, 2021

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.

@gianluca-salogni
Copy link

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

@rafaqz
Copy link
Owner

rafaqz commented Dec 1, 2021

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

@gianluca-salogni
Copy link

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

@gianluca-salogni
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants