comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » x/y margin from map_set to plot position and cgimage
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
x/y margin from map_set to plot position and cgimage [message #85677] Mon, 26 August 2013 10:36 Go to next message
Andy Sayer is currently offline  Andy Sayer
Messages: 127
Registered: February 2009
Senior Member
Hi all,

Suppose I have set up a part of a window to draw a map, and used xmargin and ymargin to specify the margins around this map. For example:

map_set,0,0,xmargin=[2,2],ymargin=[2,2]

Suppose I then want to draw an image (with cgimage) inside this map. Is there a way to pass the xmargin/ymargin information so the image is drawn inside the map region rather than the whole plot window? I don't see those as keywords to cgimage. If not, is there some way I can pull out the plot position which arose from my map_set call and pass this to cgimage? I can't necessarily assume that !p.multi=0, so I don't think the cgimage position keyword would help me here?

(I am switching over a lot of old code written for IDL 5/6 to use newer features and the Coyote library... so am now becoming familiar with some 'under the hood' stuff which I had not looked at in detail before. I'm now using IDL 7.1.1 and 8.2.2.)

I would not be averse to recoding to use something like the Coyote Graphics position keyword in my map_set call, but as far as I know that can't be done with map_set (and I don't want to pass the position keyword to map_set because often !p.multi will not be 0).

The longer story for what I am trying to do is that I have written code to map regularly or irregularly lat-lon gridded data from e.g. satellites. This basically makes use of polyfill to draw each point. If the grid is not regular, my code allows for a proper expression of the ground pixel size. But if the grid is regular (e.g. level 3 data), I figure I should be able to map it as an image, which could be a lot faster than using polyfill.

Thanks,

Andy
Re: x/y margin from map_set to plot position and cgimage [message #85679 is a reply to message #85677] Mon, 26 August 2013 11:20 Go to previous messageGo to next message
Andy Sayer is currently offline  Andy Sayer
Messages: 127
Registered: February 2009
Senior Member
I guess this question could be posed more generally as: how can I identify what parts of an image window lie within the portion available for drawing the map after a call to map_set, and how can I pass this to other routines such as cgimage?

Andy

On Monday, August 26, 2013 1:36:06 PM UTC-4, AMS wrote:
> Hi all,
>
>
>
> Suppose I have set up a part of a window to draw a map, and used xmargin and ymargin to specify the margins around this map. For example:
>
>
>
> map_set,0,0,xmargin=[2,2],ymargin=[2,2]
>
>
>
> Suppose I then want to draw an image (with cgimage) inside this map. Is there a way to pass the xmargin/ymargin information so the image is drawn inside the map region rather than the whole plot window? I don't see those as keywords to cgimage. If not, is there some way I can pull out the plot position which arose from my map_set call and pass this to cgimage? I can't necessarily assume that !p.multi=0, so I don't think the cgimage position keyword would help me here?
>
>
>
> (I am switching over a lot of old code written for IDL 5/6 to use newer features and the Coyote library... so am now becoming familiar with some 'under the hood' stuff which I had not looked at in detail before. I'm now using IDL 7.1.1 and 8.2.2.)
>
>
>
> I would not be averse to recoding to use something like the Coyote Graphics position keyword in my map_set call, but as far as I know that can't be done with map_set (and I don't want to pass the position keyword to map_set because often !p.multi will not be 0).
>
>
>
> The longer story for what I am trying to do is that I have written code to map regularly or irregularly lat-lon gridded data from e.g. satellites. This basically makes use of polyfill to draw each point. If the grid is not regular, my code allows for a proper expression of the ground pixel size. But if the grid is regular (e.g. level 3 data), I figure I should be able to map it as an image, which could be a lot faster than using polyfill.
>
>
>
> Thanks,
>
>
>
> Andy
Re: x/y margin from map_set to plot position and cgimage [message #85681 is a reply to message #85677] Mon, 26 August 2013 18:11 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
AMS writes:

> Suppose I have set up a part of a window to draw a map, and used xmargin and ymargin to specify the margins around this map. For example:
>
> map_set,0,0,xmargin=[2,2],ymargin=[2,2]
>
> Suppose I then want to draw an image (with cgimage) inside this map. Is there a way to pass the xmargin/ymargin information so the image is drawn inside the map region rather than the whole plot window? I don't see those as keywords to cgimage. If not, is there some way I can pull out the plot position which arose from my map_set call and pass this to cgimage? I can't necessarily assume that !p.multi=0, so I don't think the cgimage position keyword would help me here?

Coyote Graphics routines do not use margins. Margins are based on the
strangest unit ever: character size. It is impossible to explain how
margins work, and even more impossible to get anything to line up with
them. All Coyote Graphics routines are positioned with the POSITION
keyword.

> (I am switching over a lot of old code written for IDL 5/6 to use newer features and the Coyote library... so am now becoming familiar with some 'under the hood' stuff which I had not looked at in detail before. I'm now using IDL 7.1.1 and 8.2.2.)
>
> I would not be averse to recoding to use something like the Coyote Graphics position keyword in my map_set call, but as far as I know that can't be done with map_set (and I don't want to pass the position keyword to map_set because often !p.multi will not be 0).

The cgMap_Set program is an exception to the rule. I don't use cgMap_Set
much, and it is simply a wrapper for Map_Set. I do almost all my map
projection work with the Map_Proj_*** routines, which are old, but still
mostly professional. The cgMap object is a wrapper to the Map_Proj_Init
command and *does* allow you to position a map projection in a graphics
window. You can use the same position for the cgImage command. Usually,
it it done the other way around, and we create a map projection for a
map projected image. That is done something like this:

map = cgMap('Mercator', ...)
pos = [0.1, 0.1, 0.9, 0.9]
cgImage, myImage, Position=pos, OPosition=opos, /Keep_Aspect
map -> SetProperty, Position=opos
map -> Draw
cgMap_Continents, Map=map

I wouldn't use !P.Multi to position maps, probably. I think I would use
cgLayout to calculate the map positions. cgLayout is much more flexible
than !P.Multi, although it does the same job of laying out multiple
plots in a gridded display.

> The longer story for what I am trying to do is that I have written code to map regularly or irregularly lat-lon gridded data from e.g. satellites. This basically makes use of polyfill to draw each point. If the grid is not regular, my code allows for a proper expression of the ground pixel size. But if the grid is regular (e.g. level 3 data), I figure I should be able to map it as an image, which could be a lot faster than using polyfill.

Yes, I am very close to having a new cgWarpToMap program that will do
this kind of thing very simply and quickly. Maybe I'll have time to
finish it this week.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: x/y margin from map_set to plot position and cgimage [message #85682 is a reply to message #85679] Mon, 26 August 2013 18:12 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
AMS writes:

> I guess this question could be posed more generally as: how can I identify what parts of an image window lie within the portion available for drawing the map after a call to map_set, and how can I pass this to other routines such as cgimage?

I would get the position from the !X.Window and !Y.Window system
variables.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: x/y margin from map_set to plot position and cgimage [message #85684 is a reply to message #85682] Tue, 27 August 2013 05:45 Go to previous messageGo to next message
Andy Sayer is currently offline  Andy Sayer
Messages: 127
Registered: February 2009
Senior Member
Thanks for the tips, David. I'd looked at !p.position to try to find the position after my map_set call but that was set to zero, looking at !x.window/!y.window had not crossed my mind! I agree that margin is a slightly odd unit to use but it seems to be what we have in standard IDL (if you want something which you can define coordinates with respect to the fraction of the plotting device assigned assuming even divisions from !p.multi).

I found that just using the tv command got the position right without requiring any explicit positioning information, although I kind of want to swap out tv for cgimage eventually. So my first working attempt basically consists of map_set, followed by map_image and then tv. I did notice a few differences between the image and the polyfill for one projection (satellite) so need to dig into that a bit more today. I've read discussion here and on your webpage about why this (i.e. map_set, map_image) is Not A Great Way To Approach Maps but guess the lessons have not sunk in yet. ;) Perhaps I will write a 'third generation' of my mapping codes when it does...

Andy

On Monday, August 26, 2013 9:12:36 PM UTC-4, David Fanning wrote:
> AMS writes:
>
>
>
>> I guess this question could be posed more generally as: how can I identify what parts of an image window lie within the portion available for drawing the map after a call to map_set, and how can I pass this to other routines such as cgimage?
>
>
>
> I would get the position from the !X.Window and !Y.Window system
>
> variables.
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: x/y margin from map_set to plot position and cgimage [message #85685 is a reply to message #85684] Tue, 27 August 2013 05:58 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
AMS writes:

> I found that just using the tv command got the position right without requiring any explicit positioning information, although I kind of want to swap out tv for cgimage eventually

I would definitely put this in the class of "minor miracle"! :-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: x/y margin from map_set to plot position and cgimage [message #85686 is a reply to message #85685] Tue, 27 August 2013 06:21 Go to previous messageGo to next message
Andy Sayer is currently offline  Andy Sayer
Messages: 127
Registered: February 2009
Senior Member
Yes, it came as a pleasant surprise. :)

On Tuesday, August 27, 2013 8:58:21 AM UTC-4, David Fanning wrote:
> AMS writes:
>
>
>
>> I found that just using the tv command got the position right without requiring any explicit positioning information, although I kind of want to swap out tv for cgimage eventually
>
>
>
> I would definitely put this in the class of "minor miracle"! :-)
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: x/y margin from map_set to plot position and cgimage [message #85687 is a reply to message #85686] Tue, 27 August 2013 06:46 Go to previous messageGo to next message
Andy Sayer is currently offline  Andy Sayer
Messages: 127
Registered: February 2009
Senior Member
Spoke too soon: it works for X-window output, but not for ps output. Digging some more...

On Tuesday, August 27, 2013 9:21:38 AM UTC-4, AMS wrote:
> Yes, it came as a pleasant surprise. :)
>
>
>
> On Tuesday, August 27, 2013 8:58:21 AM UTC-4, David Fanning wrote:
>
>> AMS writes:
>
>>
>
>>
>
>>
>
>>> I found that just using the tv command got the position right without requiring any explicit positioning information, although I kind of want to swap out tv for cgimage eventually
>
>>
>
>>
>
>>
>
>> I would definitely put this in the class of "minor miracle"! :-)
>
>>
>
>>
>
>>
>
>> Cheers,
>
>>
>
>>
>
>>
>
>> David
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>> --
>
>>
>
>> David Fanning, Ph.D.
>
>>
>
>> Fanning Software Consulting, Inc.
>
>>
>
>> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
>>
>
>> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: x/y margin from map_set to plot position and cgimage [message #85688 is a reply to message #85687] Tue, 27 August 2013 07:18 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
AMS writes:

> Spoke too soon: it works for X-window output, but not for ps output. Digging some more...

Dig no further: cgImage.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: x/y margin from map_set to plot position and cgimage [message #85689 is a reply to message #85688] Tue, 27 August 2013 07:30 Go to previous messageGo to next message
Andy Sayer is currently offline  Andy Sayer
Messages: 127
Registered: February 2009
Senior Member
That's what I have switched to for postscript output (and using the /overplot keyword to locate my image), although I am finding that my borders are one grid cell out from where they should be (relative to e.g. coastal outlines), so I am digging into map_image to see where I have gone wrong...

On Tuesday, August 27, 2013 10:18:08 AM UTC-4, David Fanning wrote:
> AMS writes:
>
>
>
>> Spoke too soon: it works for X-window output, but not for ps output. Digging some more...
>
>
>
> Dig no further: cgImage.
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: x/y margin from map_set to plot position and cgimage [message #85690 is a reply to message #85689] Tue, 27 August 2013 07:34 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
AMS writes:

> That's what I have switched to for postscript output (and using the /overplot keyword to locate my image), although I am finding that my borders are one grid cell out from where they should be (relative to e.g. coastal outlines), so I am digging into map_image to see where I have gone wrong...

I did notice this morning that you can use the POSITION keyword with
cgMap_Set. Setting the same position for your map and your image should
align things perfectly.

cgMap_Set, Position=pos, ...
cgImage, Postion=pos, ...
cgMap_Continents, ...

Works on the graphics display and in PostScript identically. :-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: programmatically compile a procedure without a .pro extension
Next Topic: create a colorbar for negative and positive values

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:45:48 PDT 2025

Total time taken to generate the page: 0.00952 seconds