I'm currently trying to parse a shapefile (http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf) with c++. While I have no problems parsing all the data I need, there is a problem with the coordinates. I got a description file for the data, which states that the used projection is "ETRS89 (Ellipsoid: GRS80), UTM (Zone 33)".

I need all points to be in lon/lat format. I spent the whole day googling around to find a solution for this problem, but there doesn't seem to be one.

data example:

33354891.477852, 6060028.67074774
        ^               ^
       X (E)           Y (N)
  • Download QGIS 2.0 load the shapefile and set the CRS (projection) to WGS84 (latlng) and export will give you point shapefile with latitude and longitude. qgis.org/en/site/forusers/download.html – Mapperz Oct 4 '13 at 16:11
  • there must be a programmatical way. i don't want to load each shapefile manually... – Mr.Manhattan Oct 4 '13 at 16:13
  • you still need to reproject the data. C++ reproject shapefiles stackoverflow.com/questions/2139335/… – Mapperz Oct 4 '13 at 16:20
  • @Mapperz that link is for reading shapefiles, not reprojecting data. – Russell at ISC Oct 4 '13 at 16:56
  • also, i don't want to reproject the whole shapefile. it would be enough to get a formula to calculate the lon/lat from these coordinates – Mr.Manhattan Oct 4 '13 at 17:14

C++ projection library proj


We've used DLLImport to write calls into it from C# code for MapDotNet and MapsJS, works great!

You'll need to go to http://spatialreference.org/ to get proj4 strings for your source and destination projections (WGS 84 is a good choice for lat/lon)

Call pj_init_plus(initParameters) with each of your strings (returns an int*)

Then call

pj_transform(projFrom, projTo, arraySize, 1, xArray, yArray, null);

where arrays hold your coordinates (the null is for a z array which I assume you don't need).

Degrees will come out in radians, you'll need to convert to 360 degree format. Returns 0 on success, or a proj error code.

| improve this answer | |
  • hmm...isn't there just a formula to convert a point? i don't really want to use big libraries... – Mr.Manhattan Oct 4 '13 at 17:08
  • Yes, but it is different for every family of projections. – Russell at ISC Oct 4 '13 at 17:19
  • Here's the Wikipedia for UTM to degrees en.wikipedia.org/wiki/… It is not a simple formula. – Russell at ISC Oct 4 '13 at 17:21
  • Hmmm...some code i could steal, without using a whole library? i only need that one conversion... – Mr.Manhattan Oct 4 '13 at 17:30
  • 1
    It's an open-source library. You can dig through the source. – Russell at ISC Oct 4 '13 at 17:31

If you've got X/Y values in ETRS89/UTM 33 but you want ETRS89 lat/longs instead, then you will need to use the Transverse Mercator formula. However, the ellipsoid formula is ... rather complicated.


If you've got a little geodetic knowledge, then it is entirely possible to calculate lat/longs from the X/Ys yourself, but I would strongly suggest reading the EPSG Guidance on Conversions and Transformations (p.45 starts the Transverse Mercator) for a full description of all the terms involved.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.