[OSM-dev] OSM and OpenLayers Projections

Christopher Schmidt crschmidt at metacarta.com
Fri Aug 10 13:40:43 BST 2007


On Fri, Aug 10, 2007 at 09:56:05AM +0100, mike wrote:
> Apologies if this is the wrong list for this question, it's more of an
> openlayers thing but I think it's also mainly an OSM thing and I'm pretty
> sure it's fairly fundamental and that people here will know the answer and
> reasons behind this.
> 
> Can someone explain to me the issues with OSM and the OpenLayers.  I'm
> interested in combining layers of data, in particular a KML file.
> 
> Here's my example: http://www.bristolbeat.co.uk/phpmap/openstreetmap.html
> 
> What I'm finding is, the co-ordinates system is different.  Using the
> OpenLayers WMS base map, everything is cool, but using OSM maps (I've taken
> code here from information highway) the projection / co-ordinates are
> totally different.  In particular, my kml data is mostly points in Bristol,
> UK, but with the OSM layers it appears off the coast of Africa.  It looks
> like the latitude that is out.
> 
> Given that this kml data is standard lat lon co-ordinate values, it seems
> like the osm data must be incorrect, but surely that's my mistake?

You've commented out all the parts of the OpenStreetMap map options that
actually make the data geographically correct. That's probably a mistake
:)

OpenStreetMap tile data is projected. In order to use it in OpenLayers, 
you need to reproject all the data you are using -- OpenLayers does not
support clientside reprojection. This means you have two options:
 
 * Reproject your KML data. This means changing the coordinates from
   Lat/Lon to projected x/y coodinates in the "Google Projection":
   http://spatialreference.org/ref/user/6/
 * Use different tiles. If you don't care about the projected/not
   projected data, you could set up a different, non-projected
   datasource. If you'd like to go that route, I can even set one up for
   you -- I have an old one running under http://tilecache.org/demo.html
   , but I can set it up along with the other osgeo-hosted OSM layers
   (Google Projection, Simple Mercator projection) that we have set up.

There is, of course, the option of simply using Google Maps for your
data. I'm sure someone can provide the right incantation to make Google
load OSM data, and Google will reproject KML to match their internal
projection. 

If you'd like help with either of the first two, please reply and I can
help you understand the technical stuff you might need to know to get
set up.

Regards,
-- 
Christopher Schmidt
MetaCarta




More information about the dev mailing list