2

There are a lot of free tools out there to convert from UTM to Lat/Long. Fine enough, but I need to go the other way; from WGS-84 to lat/long-format.

But it's more complicated than that; 'couse I need the result to be in UTM-33 (nordic) zone. This might sound like a bad idea; why would I like to "force" the zone to 33N, when the geographical point might be laying in another zone ...

Well; the thing is that I already have a database with UTM33-coordinates of every address in Norway.

Those of you that are familiar with UTM @ Northern Europe, knows that Norway spans across several zones; from 31 to 36. (Okay, maybe we only spans from 32 to 36, cause of the strange width of zone 32V, but thats another discussion).

So, back to my problem: all my addresses are already given in UTM-33 format (with negative values when out of range). How can i proceed to get my Lat/Long into UTM-33?

I need a solution in PHP, and after a lot of debugging with "gPoint", I found out it just won't work ...

(gPoint is great to convert from/to UTM, but it will always return the UTM x/y-pair in the "correct" zone block. I don't want that! I need to always get results in zone 33, regardless of what is actual correct..)

qualbeen
  • 1,534
  • 4
  • 16
  • 27
  • 1
    I don't use PHP, but it sounds like you need [PROJ4](http://sourceforge.net/projects/proj4php/) – SlightlyCuban May 30 '14 at 18:57
  • Thanx, this helped a lot! I just wrapped a few lines of Node-code to test the library, and it looks a lot better than gPoint I tried before. For demo see http://pastebin.com/1BP8cWpj. Now, I just have to wrap my solution to PHP :-) – qualbeen May 31 '14 at 19:08
  • happy that worked out! (just wish I had the PHP know-how to be of more help) – SlightlyCuban Jun 02 '14 at 14:32

1 Answers1

3

I finally found a solution though Proj4 (thanx SlightlyCuban)!

// Conversion from WGS84 to UTM33
$proj4 = new Proj4php();
$projWGS84 = new Proj4phpProj('EPSG:4326');
$projUTM33N = new Proj4phpProj('EPSG:2078');

$result = $proj4->transform($projWGS84, $projUTM33N, new proj4phpPoint($long, $lat));

It is impossible to guess correct format for transformation, and I was struggling for a while ... then I discovered a really handy webpage: http://spatialreference.org. Here I found the definition I needed (EPSG:2078 = "+proj=utm +zone=33 +ellps=intl +units=m +no_defs")

The PHP-implementation of Proj4 needs hard-coded definitions; you cannot pass by a definition ad-hoc. EPSG:2078 was originally missing from Proj4php. Yay; lucky me!

I would therefor recommend to test Proj4 via Node.js and proj4js (see my little demo at http://pastebin.com/1BP8cWpj).

To succeed, I had to fork the Proj4PHP-library, and add a definition file for EPSG:2078 ...

Community
  • 1
  • 1
qualbeen
  • 1,534
  • 4
  • 16
  • 27