I'm trying to convert polygon from wkid 3301 to wkid 4326. I've been using this code snippet for converting points, but I'm not sure how I would accomplish this to create a polygon object. I'm not even sure if gsvc.project() is the best solution. Any suggestions would be appreciated.

var outSR = new esri.SpatialReference({ wkid: 4326 });
mapHandler.gsvc.project([ geometry ], outSR, function(projectedPoints) {
    pt = projectedPoints[0];

I ended up solving this with the following code:

mapHandler.gsvc.project([ geometry ], outSR, function(projectedPoints) {
    var polygonJSON = {"rings": projectedPoints[0].rings, "spatialReference": {"wkid": projectedPoints[0].spatialReference.wkid}};
    var polygon = new esri.geometry.Polygon(polygonJSON);
  • Welcome to the site, and thanks for posting the solution. You should mark this answer as accepted, so that future readers will quickly now what worked. Thanks. – user3461 Apr 25 '13 at 11:53
  • 1
    Great, thanks for following up and keeping the site's Q&A format working well. – user3461 Apr 25 '13 at 13:35
  • You should be able create straight from the JSON. var polygon = new esri.geometry.Polygon(projectPoints[0]); – awesomo Apr 26 '13 at 16:48
  • Apparently the short version didn't work. Removed that from the answer. – ObviousCat May 7 '13 at 18:14

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.