rafaqz / Extents.jl

A shared Extent object for Julia spatial data, with DE-9IM spatial predicates
MIT License
4 stars 3 forks source link

Extents.extents ? #9

Closed alex-s-gardner closed 1 year ago

alex-s-gardner commented 1 year ago

What are peoples thoughts about adding

function extents(;X , Y) ex = Extents(X=extrema(X), Y = extrema(Y)) return ex end

rafaqz commented 1 year ago

What are X and Y? Arrays/ranges?

One problem is the extent is often not the start/end of a range, because the last step needs to be added for intervals.

alex-s-gardner commented 1 year ago

Can this be handled with multiple dispatch or are there too many edge cases?

rafaqz commented 1 year ago

How would you handle it with multiple dispatch? A Vector{Float64} can represent intervals or points, but have a different extent.

I dont really understand what you are proposing.

alex-s-gardner commented 1 year ago

OK, to me it seemed strait forward. If you have a dataset and you want to construct an Extent you could simply pass Extents.extents the coordinates or a range. I do this every time I create a new Tyler plot or want to check if two datasets have overlapping bounding boxes.

rafaqz commented 1 year ago

But what is the range

alex-s-gardner commented 1 year ago

For Extents.extents is would simply give the Extent of whatever is input.. it wouldn't attempt guess as to what the user intends by the input data. If a range was input then it would give the Extent of that range. If the user wanted something else then they would need to define their Extent manually. Extents.extents would only work if the inputs X and Y actually contain the extents. Does that make sense?

rafaqz commented 1 year ago

But what is your particular range from?

rafaqz commented 1 year ago

Im trying to tease out the problem that a range can represent two (even four) different extents, not one. And we dont know which.

We can use the start and end points as a point to point extent, of course. So (first(r), last(r)). But ranges have a step size, so we can also calculate the interval extent (first(r), last(r)+step(r)) if the values are for the starts of each pixel.

Its very common in raster or image data that the range of pixel point locations represent the start or center of intervals. When you pass a range of tick values to a heatmap in Makie, theyre the centers of intervals. So the extent is half a pizel larger on each side. So `(first(r) - step(r)/2, last(r)+step(r)/2).

And if you load a tif with Rasters.jl chances are thats what the lookup ranges mean. When you call extent on them this math is done for you because Rasters.jl tracks these things in the wrapper.

alex-s-gardner commented 1 year ago

OK, I follow but in my eyes this has already been defined extrema(Range)... if the user is using Range in a way in which the Extents are not defined by Range alone then they would need to explicitly define their Extent ... the function could be defined as:

    extents(; X, Y)
Returns the Extent based on the minimum and maximum values of inputs X and Y
alex-s-gardner commented 1 year ago

Pixel centers vs. pixel edges is an issue that has plagued raster data for decades... I wish we had only opted for a single convention

rafaqz commented 1 year ago

I think people can just call X=extrema(xs) themselves tho if they mean that?

I prefer that to the swathes of inevetably wrong Makie plots for the next decade that people will bug me about.

alex-s-gardner commented 1 year ago

Fair point.