Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have an issue converting lat longs to UTM with the ArcGIS javscript API.

Lets say that I have a map, based on the UTM zone 29N, also known as WKID 32629.

I have a known set of coordinates from a GPS, in this format:

Latitude:  62.220596 
Longitude: -6.564331

The geograpic coordinates are in WKID 4326.

To convert using javascript I have been trying to use the Geometry Service's project method.

If we look at this post in the ArcGIS forum, it is about the same issue. Here, I have tried using the same code, and adjusting the wkid of the output spatialReference to 32629, and you see it returns only NaN, try in the JSfiddle to change the wkid to 4326, and you will see geographic coordinates.

Edit 1

Looking at the HTTP requests made to the server, I see this url is requested (now using the map of the Faroe Islands)

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?f=json&outSR=32629&inSR=4326&geometries={"geometryType":"esriGeometryPoint","geometries":[{"x":62.01387,"y":-6.7866,"spatialReference":{"wkid":4326}}]}&callback=dojo.io.script.jsonp_dojoIoScript2._jsonpCallback

This looks like a correct url, containing outSR, inSR, geometries, and callback. However, simulating requests to this url gives me either a 500 Internal Server Error, or this string:

dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"error":{"code":400,"message":"Unable to complete Project operation.","details":["Error projecting geometries"]}});

Any ideas?

share|improve this question

5 Answers 5

up vote 4 down vote accepted

I haven't looked at your code, but in the URL you provided, your X and Y are flipped around. For Faroe Islands, X should be -6.7866 (longitude) while Y should be 62.01387 (latitude). Here's a working URL of what you're trying to do:

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?f=json&outSR=32629&inSR=4326&geometries={"geometryType":"esriGeometryPoint","geometries":[{"x":-6.7866,"y":62.01387,"spatialReference":{"wkid":4326}}]}&callback=dojo.io.script.jsonp_dojoIoScript2._jsonpCallback

That correctly returns:

dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"geometryType":"esriGeometryPoint","geometries":[{"x":615863.053581134,"y":6877701.89119242}]});

As for 500s, I seem to get those quite frequently with sampleserver3 as well tonight. Try using sampleserver1 instead, that one seems to be more stable.

share|improve this answer

By changing the WKID in the code on JSFiddle you're asking the geometry service to project from one UTM zone to another. That doesn't really makes sense...

Try this: http://jsfiddle.net/swingley/Yab7E/

The code there takes a map click point (which is web mercator), converts it to lat, long, sends the lat, long point to the geometry service and says project it to WGS84 UTM Zone 29N.

Edit: Here's a URL generated from that fiddle that returns a point in UTM Zone 29N:

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?f=json&outSR=32629&inSR=4326&geometries={%22geometryType%22%3A%22esriGeometryPoint%22%2C%22geometries%22%3A%5B{%22x%22%3A-7.080688421874865%2C%22y%22%3A62.19107532141271%2C%22spatialReference%22%3A{%22wkid%22%3A4326}}%5D}&callback=dojo.io.script.jsonp_dojoIoScript3._jsonpCallback
share|improve this answer

I bagged the code form here and it works grand. Integrated client side, you dont actually need a call to the server. Integrated server side in a script, which I have also done, keeps it all encapsulated.

share|improve this answer

You are asking for a UTM Zone 29N coordinate for a point in Michigan.
UTM Zone 29N does not exist in Michigan, you are outside the bounds of the coordinate system.

To demonstrate, on your original example zoom out 14 times then click about a half inch under the M in "Mercator". You will get a result because you are now inside the bounds of the UTM Zone 29N coordinate system.

Or, try changing to Zone 16N, wkid 32616, which does exist in Michigan and you will see that your sample code returns a point without any problem.

As an additional note to this, ESRI really needs to fix the documentation of the error. Now that I know what the problem was, the error makes sense, but can you really figure out from that error that you are trying to project outside the bounds of the coordinate system?

share|improve this answer

10 seconds solution for this one would by to copy/paste your lat/long to http://www.hamstermap.com - you will get them instantly converted to UTM.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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