GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
731 stars 213 forks source link

get lon,lat from image coordinates (using mapproject) #1986

Open espiritocz opened 2 years ago

espiritocz commented 2 years ago

hi guys, inspired by your egu materials (the trick with Panel), i thought about another interactive feature in ipynb. i want to run a function (show time series plot) upon clicking to the map.

for this, i can get x,y coordinates in generated image, as in: https://stackoverflow.com/questions/52235476/jupyter-notebook-register-mouse-position-clicks-moves-on-a-displayed-image-j

is there a way on how to get original geographic coordinates, i.e. back-projection from final image coordinates to lon, lat of the source?

thank you for any hints to push this forward

welcome[bot] commented 2 years ago

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.

weiji14 commented 2 years ago

Hi @espiritocz, glad to see someone checking out the EGU short course materials! From the sounds of what you're trying to do (click on a map to get lon/lat coordinates), you may want to check out https://geoviews.org/index.html instead. Unfortunately it'll be quite difficult to get PyGMT to respond to clicks on a map (since GMT isn't actually designed for interactivity).

Geoviews has a forum at https://discourse.holoviz.org/c/geoviews/7 which would be suited for these types of questions. Good luck!

espiritocz commented 2 years ago

thank you Wei Ji,

actually, the question is rather about function that would have input as x,y coordinates of an image (that contains map on canvas, generated by GMT) and in my opinion it should be fairly easy to just get lat,lon from there, as GMT should know where it places related pixels.

i can do the rest )

On Sat, 2 Jul 2022, 16:22 Wei Ji, @.***> wrote:

Hi @espiritocz https://github.com/espiritocz, glad to see someone checking out the EGU short course materials! From the sounds of what you're trying to do (click on a map to get lon/lat coordinates), you may want to check out https://geoviews.org/index.html instead. Unfortunately it'll be quite difficult to get PyGMT to respond to clicks on a map (since GMT isn't actually designed for interactivity).

Geoviews has a forum at https://discourse.holoviz.org/c/geoviews/7 which would be suited for these types of questions. Good luck!

— Reply to this email directly, view it on GitHub https://github.com/GenericMappingTools/pygmt/issues/1986#issuecomment-1172915393, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADYYKQXWWS2TKTAWDXWB4DVSBND5ANCNFSM52O4HMKQ . You are receiving this because you were mentioned.Message ID: @.***>

weiji14 commented 2 years ago

Ah ok, so if you just want to convert image x y coordinates to longitude and latitude, that can be done with an affine transform that encodes information about the top left corner's coordinates and the pixel size, e.g. following https://gis.stackexchange.com/questions/395667/translating-x-y-coordinates-to-lat-long/395680#395680.

If you don't mind the command line, GMT does have mapproject to convert lonlat to xy (or vice versa), see https://docs.generic-mapping-tools.org/6.4/mapproject.html. Unfortunately that isn't wrapped in PyGMT yet.

seisman commented 2 years ago

I'm closing the issue because I think this feature is beyond the scope of the PyGMT project.

Feel free to reopen the issue if you think more should be discussed.

weiji14 commented 2 years ago

The single lonlat to xy conversion could be considered as a feature request for mapproject to be wrapped in PyGMT. I'll reopen this issue to keep track.

espiritocz commented 1 year ago

thank you Wei Ji,

actually, can you share some material/code that would help me figure out how to best wrap the (compiled) C code to python (outside of just os.system)?

that might be helpful.

cheers!

M.

On Mon, 11 Jul 2022, 03:22 Wei Ji, @.***> wrote:

Reopened #1986 https://github.com/GenericMappingTools/pygmt/issues/1986.

— Reply to this email directly, view it on GitHub https://github.com/GenericMappingTools/pygmt/issues/1986#event-6966029584, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADYYKWT4EANOOXACDIRLLDVTOAQFANCNFSM52O4HMKQ . You are receiving this because you were mentioned.Message ID: @.***>

espiritocz commented 1 year ago

hi.

only wanted to ask whether there is a chance this year to have bindings to mapproject through pygmt?

thanks

On Tue, 19 Jul 2022, 11:48 Milan Lazecky, @.***> wrote:

thank you Wei Ji,

actually, can you share some material/code that would help me figure out how to best wrap the (compiled) C code to python (outside of just os.system)?

that might be helpful.

cheers!

M.

On Mon, 11 Jul 2022, 03:22 Wei Ji, @.***> wrote:

Reopened #1986 https://github.com/GenericMappingTools/pygmt/issues/1986 .

— Reply to this email directly, view it on GitHub https://github.com/GenericMappingTools/pygmt/issues/1986#event-6966029584, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADYYKWT4EANOOXACDIRLLDVTOAQFANCNFSM52O4HMKQ . You are receiving this because you were mentioned.Message ID: @.***>