[OpenLayers-Users] Get lat/lon from pixel coordinates via a webservice?

Christopher Schmidt crschmidt at metacarta.com
Sat Aug 23 09:11:49 EDT 2008


On Sat, Aug 23, 2008 at 10:08:54AM +0200, Kaspar Fischer wrote:
> On 22.08.2008, at 23:54, Christopher Schmidt wrote:
> 
> >It's all planar math. "Zoom Levels" have no real meaning: what you  
> >care
> >about is resolution.
> 
> So the map is shown using an equirectangular projection.

Which map? You've got the image, not me: You'd have to look at the image
to decide that. It's not relevant if it's equirectangular or not as to
whether the way you interact with it in OpenLayers is in x/y space: all
maps in OpenLayers deal with setting the center in a projected space.
Whether your 'projected' space is simply treating lat/long as X/Y (as
EPSG:4326, the default OpenLayers projection, does) or your projected
space is a mercator projection (as Google does), the way you interact
with a geographic location from an image is planar -- and if you need
lat/long for some reason, you solve that problem by reprojecting. 

> >But none of this appears to be related to OpenLayers:
> 
> Why not? A beginner might think that OpenLayers provides different
> projections, where the relation between pixel- and geographic  
> coordinates
> is not necessarily affine. In which case it seems natural to me that
> there is an API to to the conversion.

Projection is conversion of a 3d Globe into a 2d plane. Once you have an
image in a specific projection, then the coordinates within the image
are 'eastings and westings' or "X and Y". 

Assuming that the map that you display inside of OpenLayers is the
same as the small map that you display inside of your 'static' image,
then the X and Y will be the same -- it's all planar -- because the
projection is the same.

If you wanted to do something different -- for example, display a
screenshot of a projected globe, and then use the globe to look up a
x/y (by a single click) and turn it a lat/long you're going to display
on another map, that would be a different problem, though still not an
OpenLayers problem. I would generally recommend proj.4, but a key step
there is that you'd need to have created the image -- and in doing so,
you'd likely figure out which projection it is and how to do all this,
because generating a geographically correct projected image takes a lot
more knowledge than generating an x/y coordinate from a click :)

All 2D maps are planar rectangles in the end. Assuming the projection is
the same between any two maps, then the map to convert between them is
just planar/rectangle math. Note that this does not mean that the
coordinates you are interacting with are always lat/long. Google hides
the 'real' coordinates under the cover, so although you interact with
the API in Lat/Lon, in reality, the projection is a mercator one, so you
need to do reprojection of your x/y back to lat/lon -- and proj.4 is the
right tool for that. (Or inside of OpenLayers, the OpenLayers.Projection
framework will work just as well.) 


> But apologies if I did misunderstand something -- you obviously have
> much more experience with OpenLayers.

Well, yes. And to be fair, I probably overreacted. I was slightly
frustrated by reading a question that said "I'd like to do something
that doesn't use OpenLayers: can you help me with that? I also asked the
Google Maps lists, but then I found this one and thought you could
help." My reaction was probably somewhat of an overreaction; I apologize
for that.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list