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

Home » Public Forums » archive » Error with MapProjection::Forward
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Error with MapProjection::Forward [message #86673 is a reply to message #86672] Wed, 27 November 2013 10:15 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

> After running my program above by correcting size and
> window to 600 by 600, I find that the image from the above l
> ink of google statics is enlarged in area and covers more
> portion of above/below, side-ways in comparison to the above
> link image.

I don't understand what this means. When I make the same changes to my
code (from your program) the map coordinates *exactly* match the image,
which is exactly what they are suppose to do. If you would like to "zoom
into" your image, you will have to trim both the image and the xrange
and yrange limits of the map coordinate object appropriately

> Is there a way I can provide the limits of lat-lon axis that I
> want to overlay on the google statics map?

A vector of X and Y projected meter values associated with the image can
be constructed like this:

dims = Image_Dimensions(googleImage, XSIZE=xsize, YSIZE=ysize)
xvec = cgScaleVector(Dindgen(xsize) + 1, xrange[0], xrange[1])
yvec = cgScaleVector(Dindgen(ysize) + 1, yrange[0], yrange[1])

If you wanted to trim 50 pixels of the left of the image and 100 pixels
off the right of the image. You might do something like this:

googleImage = googleImage[*, 50:xsize-100, *]

You will have to re-define your xrange accordingly:

xrange = [xvec[50],xvec[xsize-100]]

Here is the code I'm using.

PRO Google_Map_Plot

; Set up variables for the plot. Normally, these values would be
; passed into the program as positional and keyword parameters.
centerLat= 51.525517D ; (Max(Lats) + Min(Lats)) / 2.0 deg. N
centerLon= 12.927633D ; (Max(Lons) + Min(Lons)) / 2.0 deg. E
zoom = 16
scale = cgGoogle_MetersPerPixel(zoom)

; Gather the Google Map using the Google Static Map API.
googleStr = "http://maps.googleapis.com/maps/api/staticmap?" + $
"center=" + StrTrim(centerLat,2) + ',' + StrTrim(centerLon,2) + $
"&zoom=" + StrTrim(zoom,2) + "&size=600x600" + $
"&maptype=satellite&sensor=false&format=png32"
netObject = Obj_New('IDLnetURL')
void = netObject -> Get(URL=googleStr, FILENAME="googleimg.png")
Obj_Destroy, netObject
googleImage = Read_Image('googleimg.png')

; Set up the map projection information to be able to draw on top
; of the Google map.
map = Obj_New('cgMap', 'Mercator', ELLIPSOID='WGS 84', /OnImage)
uv = map -> Forward(centerLon, centerLat)
uv_xcenter = uv[0,0]
uv_ycenter = uv[1,0]
xrange = [uv_xcenter - (300*scale), uv_xcenter + (300*scale)]
yrange = [uv_ycenter - (300*scale), uv_ycenter + (300*scale)]

; Trim the image and xrange 50 pixels on left and 100 on right.
dims = Image_Dimensions(googleImage, XSIZE=xsize, YSIZE=ysize)
xvec = cgScaleVector(Dindgen(xsize) + 1, xrange[0], xrange[1])
yvec = cgScaleVector(Dindgen(ysize) + 1, yrange[0], yrange[1])
googleImage = googleImage[*, 50:xsize-100, *]
xrange = [xvec[50],xvec[xsize-100]]


map -> SetProperty, XRANGE=xrange, YRANGE=yrange

; Open a window and display the Google Image with a map grid and
; location of Coyote's favorite prairie dog restaurant.
cgDisplay, 700, 700, Title='Google Image with Coyote Graphics'
cgImage, googleImage[0:2,*,*], /Keep_Aspect, $
Position=[50, 50, 650, 650] / 700., OPOS=opos
map -> SetProperty, POSITION=opos
cgMap_Grid, MAP=map, /BOX_AXES, /cgGRID
cgPlotS, -105.1, 40.6, PSYM='filledstar', SYMSIZE=3.0, $
MAP=map, COLOR='red'

; Overlay the points on the map
geo_lon=[ 12.928891,12.926434,12.925875,12.922277,12.913507,12.925407, $
12.927663,12.927191,12.928041,12.926399,12.925676,12.926233, $
12.942073,12.927199,12.927197,12.927209,12.941039,12.922861, $
12.925361,12.928772,12.937340,12.927910,12.926749,12.929081, $
12.930733,12.917927,12.937282,12.940540,12.931345,12.920242, $
12.927734,12.934965,12.913434,12.926365,12.925563,12.925388, $
12.926150,12.927432,12.928548,12.925627,12.928129,12.927163, $
12.928032,12.929043,12.919992,12.931943,12.927277,12.928178, $
12.916696,12.926318]


geo_lat=[51.525643,51.528963,51.529627,51.526104,51.526895, $
51.525046,51.525569,51.525998,51.529957,51.526427,51.525457, $
51.525176,51.527107,51.525662,51.525315,51.524935,51.520126, $
51.522013,51.525613,51.526004,51.525096,51.526548,51.525709, $
51.518588,51.522657,51.525658,51.519825,51.536149,51.526332, $
51.519956,51.535018,51.531251,51.518749,51.525994,51.525979, $
51.524687,51.525668,51.521689,51.526567,51.526391,51.525455, $
51.526486,51.525986,51.525204,51.528715,51.527705,51.522675, $
51.525066,51.534141,51.524814]

PRINT, MAX(geo_lon),MIN(geo_lon),MAX(geo_lat),MIN(geo_lat)

numColors = N_Elements(geo_lon)
cgLoadCT, 33, NColors=numColors
cgPlotS, geo_lon, geo_lat, COLOR=Bindgen(numColors), $
PSYM=16, SYMSIZE=1.2,MAP_OBJECT=map

END ;*********************************************************** ******



--
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.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Rounding errors and the New Graphics image routine
Next Topic: ENVI_OPEN_FILE not found

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

Current Time: Wed Oct 08 18:35:47 PDT 2025

Total time taken to generate the page: 0.00425 seconds