lat long to screen coordinates?

Jan 14, 2013 at 10:45 AM


I'm wondering how to get from latitude longitude to Screen coordinates?

There's the SphericalMercator.FromLonLat, does this equal a conversion from geo-coordinates to WGS84? or something.. :) Then theres Viewport.WorldToScreen.
We have a custom Tile Schema with a small extent and the map is based on epsg:21781.

I'm asking what steps are required to get to screen coordinates.

I also posted this question in the Proj4Net Project:

As we have a different coordinate System, does it make sense to use Proj4Net to transform and if yes, when would I use it in the transform pipe? Or is the TileSchema alone enough for all transformation Infos?


Jan 16, 2013 at 9:09 AM

Hi there,

There are two steps. 

1) Transform your source data to the map coordinate system. In your case the map is in epsg:21781. If your source data is in epsg:21781 there is no projection needed. If it is in WGS84 you will need some projection library for this, like proj4net or You could do this before you add the geometries to the layer. Or you could implement IRenderer using a projection library, so that it will be done on the fly. This last option is the more proper way which I should include in Mapsui at some point.

2) ViewPort.WorldToScreen transforms the map coordinates to screen coordinates. This is a relatively simple operation. In most cases this will work properly without customization.

We don't do any projection of tiles. So if you have a tile basemap then the Map class needs to be in that projection. You cannot combine an epsg:21781 tile layer with the various spherical mercator layers that are around.

Perhaps, in the near future, I will add a little example of an IRenderer impelementation mererly using the SphericalMercator projection included in the code.

Jan 16, 2013 at 11:52 AM
Edited Jan 16, 2013 at 12:02 PM


So basically if I have WGS84 coordinates, the following steps would be required:

WGS84 to ESPG:21781 to Screen

I don't quite understand the part with the tile projection. We have set up a Schema with an Extent, Resolutions, Axis and Origin Definition which displays correctly in all zoom levels, is this not enough? If I have done this transformation for all points, do I still have to change the map class to support this projection? What is missing if we don't implement this?

And could you give me an example how to use Proj4Net?

var lat = 46.732;
var lon = 7.618;
var geo = Proj4Net.CoordinateReferenceSystem.CS_GEO; // WGS84?
var swiss = coordinateReferenceSystemFactory.CreateFromName("epsg:21781"); var t = new Proj4Net.BasicCoordinateTransform(geo, swiss); var c = t.Transform( new Coordinate(lat, lon), new Coordinate(/*what target coordinates?*/); // then Viewport.WorldToScreen?