Which circle does a point fall into?

I have a “how do you do something” kind of question.

Given: a scattered set of n-number of circles (i.e., each circle consists of lon, lat, radius). And given a set of m-number locations.

Find: for each m location, the circle(s) each point is within? Might be none. Might be more than one.

gmtselect allows the passage of locations that fall within a set of circles, but it doesn’t tell you which circle it fell inside of. Can this be done with GMT? If so, how?

If you were willing to leave the Jurassic …


Thanks, Joaquim. Interesting info, but it seems aimed for polygons. These are circles. Would it be necessary to convert lon, lat and radius into closed polygons for julia to run its magic? This kind of function would be useful within GMT, directly; just like replacing Fortran binary programs with a single line grdconvert command. My brontosaurus brain is too small!

I’d investigate a workaround with mask maybe? But you probably won’t escape a for loop to iterate through your circles (which are very fine polygons)

Yes, those circles have to be polygons because under the hood gmtselect is the one who does the hard work.

I’m afraid those GMT.jl solutions are not going to be backported to GMT.C. It’s just to much work with a and things take > 10 x longer to implement. Maybe a pterodactylus flight will start to reveal that GMT.jl is actually much simpler to use than GMT CLI.

Actually, mapproject may be the command of choice.

Have mapproject compute the distance between each point and each circle’s center coordinate, then test against the given radius of the circle. If the distance is less than the circle’s radius, then the point is inside.

Should be pretty quick if the -G option is used for the location of a point. Just feed the circle center coordinates as the input table.

Sometimes it takes the tail of a stegosaurus to tear things apart.

Yes, being an analytical problem with circles the solution is simple, but it won’t save you to do a double for loop with if conditions and that requires using some programing language.