How to use zoomscale function in PHP mapscript

Jeff Portwine jdport at VERITIME.COM
Fri Feb 25 15:38:37 EST 2005


I've had to convert back and forth from pixels to Lat/Long and vis versa in
several spots of my mapserver application.   As long as your map extents are
in the exact same proportion as your map image, it's pretty easy to do.

In my case, my map is 600 pixels wide and 400 pixels tall, so I made sure
that my X extents were 1.5x larger than my y extents.

To convert from lat/long to pixels, you know the width of your image in
pixels, you know the latitude (X geographic value), and you know the X
extents... so you can do:

X(pixels)=ImageWidth(x) * (latitude-min latitude extents) / (max latitude
extents-min latitude extents)

reversing it, you can get latitude from pixels with:

Latitude=[(latitude max extents-latitude min extents) *
X(pixels)/ImageWidth(x)] + latitude min extents


Keep in mind, when doing the Y axis that latitude goes from bottom to top as
the latitude increases, while pixels go from top to bottom as #pixels
increases... so you have to change the formulas accordingly.

I really hope this helps more than hurts, as I write this I find it
difficult to put the math into written english and I hope I didn't make it
sound really confusing because it's actually fairly simple.    I've had a
ton of help from this list as I first started with mapserver so I hope to be
able to help out here and there =)

-Jeff



----- Original Message -----
From: "A. Sharif" <karbon1 at GMAIL.COM>
To: <MAPSERVER-USERS at LISTS.UMN.EDU>
Sent: Friday, February 25, 2005 3:11 PM
Subject: [UMN_MAPSERVER-USERS] How to use zoomscale function in PHP
mapscript


> Hello,
>
> I am trying to create a map with a dynamic point, at a determined
> zoomscale.
>
> When i use the function $oMap->zoomscale, the coordinates I have to
> pass the function are the X,Y in pixels, whereas I have Longitude,
> Latitude coordinates.
>
> Is there a way to convert the Geographic coordinates to pixel
> coordinates, or is a different function that will the geogrphic
> coordinates and display the map at a determined scale ?
>
> thank you,
>
> Abdul
>



More information about the mapserver-users mailing list