6 Replies Latest reply on Jul 27, 2011 7:32 AM by DuncanRager

    Projecting with Geometry Service Troubles


      I'm attempting to take the center point of my map (with a spatial reference in UTM NAD 1983) and reproject it over into something else... doesn't matter which right now, because none of them seem to be working for me. The code below is what I hope to achieve, flipping from UTM to WebMercator.

      gsvc = new esri.tasks.GeometryService("http://server/ArcGIS/rest/services/Geometry/GeometryServer");
        xCenter = (map.extent.xmax - map.extent.xmin)/2;
        yCenter = (map.extent.ymax - map.extent.ymin)/2;
        utmPoint = new esri.geometry.Point(xCenter, yCenter, new esri.SpatialReference({wkid:26918}));
        webMerc = new esri.SpatialReference({wkid:3857});
        gsvc.project([ utmPoint ], webMerc, function(point){
         webPoint = point[0];

      This doesn't do anything in the web app. I checked to make sure the geometry service was up, and it is. I also tried adding an error function parameter, and it never fired. I remember reading a post somewhere about the Geometry Service taking to long to process and it couldn't return the results before the next line of code fired... does that sound like something that could be happening?

      Does anyone have a better way of converting from UTM to Web Mercator on the fly?


        • Re: Projecting with Geometry Service Troubles
          Geometry service is the way to go. Here's an example:
          <!doctype html>
          <html lang="en">
              <meta charset="utf-8">
              <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
              <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
              <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.4/js/dojo/dijit/themes/tundra/tundra.css">
                html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
                #map{ margin: 0; padding: 0; }
                #info {
                  position: absolute;
                  top: 10px; 
                  right: 10px;
                  width: 160px;
                  height: 80px;
                  z-index: 40;
                  background: #fff;
                  padding: 5px;
                  color: #000;
                  font-family: arial;
                #results { color: red; }
              <script>var dojoConfig = { parseOnLoad: true };</script>
              <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.4"></script>
                var map, resizeTimer, gsvc;
                function init() {
                  var initExtent = new esri.geometry.Extent({"xmin":13410892.167988224,"ymin":394170.65114215855,"xmax":13413646.353547676,"ymax":395793.8403501995,"spatialReference":{"wkt":"PROJCS[\"NAD_1983_StatePlane_Michigan_South_FIPS_2113_IntlFeet\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",13123359.58005249],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-84.36666666666666],PARAMETER[\"Standard_Parallel_1\",42.1],PARAMETER[\"Standard_Parallel_2\",43.66666666666666],PARAMETER[\"Latitude_Of_Origin\",41.5],UNIT[\"Foot\",0.3048]]"}});
                  map = new esri.Map("map",{extent:initExtent});
                  var basemap = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer");
                  gsvc = new esri.tasks.GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
                  dojo.connect(map, 'onClick', projectPoint); 
                  dojo.connect(map, 'onLoad', function() { 
                    dojo.connect(dijit.byId('map'), 'resize', function() {  
                      resizeTimer = setTimeout( function() {
                      }, 500);
                function projectPoint(evt) {
                  // console.log(evt.mapPoint);
                  map.graphics.add(new esri.Graphic(
                    new esri.symbol.SimpleMarkerSymbol()
                  var outSR = new esri.SpatialReference({ wkid: 102113});
                  gsvc.project([evt.mapPoint], outSR, function(result) {
                    // console.log('success: ', result);
                    dojo.byId('results').innerHTML = result[0].x.toFixed() +
                      ', ' + result[0].y.toFixed();
            <body class="tundra">
              <div data-dojo-type="dijit.layout.BorderContainer" 
                   style="width: 100%; height: 100%; margin: 0;">
                <div id="map" 
                  <div id="info">
                    <div id="instructions">Click the map to convert the click point to Web Mercator.</div>
                    <div id="results"></div>

          Don't let the well-known text in the initial extent's spatial reference throw you off, it works the same if you use a WKID.
          • Re: Projecting with Geometry Service Troubles
            I saw that sample, and it seems easy enough, but my code won't work. As far as I can tell they are the same except for the geometry a newly defined point and the wkid is different. What's the difference between my code and the sample?


            • Re: Projecting with Geometry Service Troubles
              Your code looks like it should work...have you used firebug or chrome dev tools to look at the URL being sent to your geometry service? What happens if you try to load that URL directly in your browser?
              • Re: Projecting with Geometry Service Troubles
                I stopped the script and entered the url it was pointing to in my browser... that took me to the ArcGIS Services page for the Geometry service. It lists the supported interfaces (REST and SOAP) and operations (all of them, including project.)

                I guess the one odd part (if it is even odd, I'm not sure) was when I entered the REST link, it gave me an essentially blank page (not so for the SOAP link). The attached screenshot shows what I mean.


                • Re: Projecting with Geometry Service Troubles
                  In Firebug, on the Net tab, you should see a request being made to your geometry service. If you right-click on that URL and select "Copy Location", you can paste that URL into a new tab(see attached screen shot). What happens when you load the Geometry Service URL in a new tab?
                  • Re: Projecting with Geometry Service Troubles
                    It was a working service... it turns out I was giving bad parameters. All is well now, thank you for the help.