Finding Latitude and Longitude of the 4 corners of a map using mapscript.

Troy R. Johnson Troy.Johnson at SDL.USU.EDU
Mon May 2 11:18:00 EDT 2005


Giridhar,

My problem was the projection as described by Sean (Thanks!)

I'm passing the latitude and longitude of the 4 corners to the browser.
I still calculate the lat and lon of each point, from these corner points.
So that sounds like what you are already doing?

Thanks

Troy

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On
Behalf Of Giridhar Manepalli
Sent: Saturday, April 30, 2005 2:08 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] Finding Latitude and Longitude of the
4 corners of a map using mapscript.


Troy,
Did you try $map->extent after the zooming? I thought this is working
for me. Let me know how it goes.

Also, I thought we always have the image coordinates with us and not
latitude and longitude on the browser. Because, I always use the image
coordinates and convert them into latitude and longitude. How did you
manage to get latitude and longitude without knowing the image
coordinates? Knowing this,  would do a lot of good to me.

Thanks,
Giridhar

On 4/30/05, Sean Gillies <sgillies at frii.com> wrote:
> Troy,
> 
> I'm cc'ing the list on this.
> 
> First of all, you should provide a datum or ellipsoid, if known, for
> the latlong projection.  The second thing to keep in mind is that your
> projected rectangle's corner points are not necessarily the same points
> a the original rectangle.  The projected rectangle is the smallest
> rectangle that contains the transformation of the original one.
> 
> Sean
> 
> On Apr 29, 2005, at 5:50 PM, Troy R. Johnson wrote:
> 
> > Hi Sean, thanks for your information.  I followed the instructions and
> > did this after I had drawn the image and saved the file:
> >
> > $image=$map->draw();
> > $image_url=$image->saveWebImage('MS_PNG',1,1,0);
> >
> > Then I do a
> >
> > $latlong_rect = $map->extent;
> > $latlong_rect->project( ms_newprojectionobj($map->getProjection()),
> > ms_newprojectionobj("proj=latlong"));
> >
> > I then print these lat long values out, but they don't match up
> > exactly with Lat Long
> > points of fixed locations.  For example I have a shape file that
> > contains a point at
> > -111.383, 42.333.  When I pan that point to the corner 0,0 I get a
> > reported lat lon
> > of the corner printed out of -111.351, 42.344 and this is when I'm
> > zoomed way in.
> > The opposite corner lat lon points are -111.38 and 42.318.  So I'm
> > surprised that there
> > is this much error.
> >
> > Is there something else that I could be doing wrong?
> >
> >
> > The reason for me wanting the lat, lon points is so that I can
> > calculate the x,y
> > pixel coordinates of these points of interest in shape files.  I'm
> > sure the map
> > server at some point knows what these x,y coordinates are, because it
> > places those
> > points on the image it returns, but I haven't been able to find a way
> > to
> > retrieve the x,y coordinates directly, so I'm calculating them based
> > on lat, lon.
> >
> > Maybe there is an easier way to do this that I'm missing?
> >
> > Any help would be appreciated.
> >
> > Thanks
> >
> > Troy
> >
> >
> > -----Original Message-----
> > From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On
> > Behalf Of Sean Gillies
> > Sent: Tuesday, April 26, 2005 3:08 PM
> > To: MAPSERVER-USERS at LISTS.UMN.EDU
> > Subject: Re: [UMN_MAPSERVER-USERS] Finding Latitude and Longitude of
> > the
> > 4 corners of a map using mapscript.
> >
> >
> > Just make sure to get and transform your extent *after* the map is
> > drawn because msDrawMap will fudge the map extents to fit the specified
> > image size.
> >
> > cheers,
> > Sean
> >
> > On Apr 26, 2005, at 2:57 PM, James Sohr wrote:
> >
> >> Yes, you can calculate the lat long of your current extent by using
> >> the
> >> RectObj's project method. For instance:
> >>
> >>
> >>    $latlong_rect = $map->extent;
> >>    $latlong_rect->project( ms_newprojectionobj($map->getProjection),
> >> ms_newprojectionobj("proj=latlong"));
> >>
> >>
> >>
> >> Assuming $map is your map object, the latitudes and longitudes of the
> >> four
> >> corners of your map are now stored in $latlong_rect->minx,
> >> $latlong_rect-
> >>> miny, $latlong_rec->maxx, and $latlong_rect->maxy .
> >>
> >>
> --
> Sean Gillies
> sgillies at frii dot com
> http://users.frii.com/sgillies
>



More information about the mapserver-users mailing list