Search code examples
javascriptproj4js

Proj4js - Can you convert a Lat/Long to UTM without a zone?


I'm trying to use Proj4js to perform some coordinate conversions but there is very little information out there on how to use it.

What I want to be able to do is convert a latitude and longitude to a UTM coordinate but I don't know what the zone is. This should be easy since the longitude dictates the zone and if you know that the zone comes out by default.

I've tried to do this in Proj4js but I get an error saying

"Uncaught TypeError: undefined is not a function"

My code loos like this:

 proj4Arr = [-105.2098, 39.7458];
 var source = ('+proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees +no_defs');
 var dest = ("+proj=utm +ellps=GRS80 +datum=nad83 +units=m +no_defs");

 console.log(proj4(source, dest, proj4Arr));

I just don't know if it's possible to do this without the zone included. I could calculate the zone first and then put it in the string if I need to but I'm trying to keep it simple.

And if anyone knows any good purely js resources on examples (not necessarily using OpenLayers 3) I'd be grateful for that as well.

Thanks!


Solution

  • I think you will have to specify the zone info for projections for proj4 projections in order to use the library. Without zone it is not a valid proj4 projection.

    Here is the question about how to identify the zone from lon/lat.

    And here are two examples: [1], [2]

    You can check out the js code by yourself.