Select to view content in your preferred language

Is there a difference between geographicToWebMercator() and geometryService.Project()

2803
5
07-26-2011 01:51 AM
YardenCochav
Deactivated User
Hi,
Is there a difference between esri.geometry.geographicToWebMercator() and geometryService.Project() functions?

Thanks
0 Kudos
5 Replies
AxelSchaefer
Emerging Contributor
HI.

"esri.geometry.geographicToWebMercator()" is an internal function in the JS-API. "geometryService.Project()" uses an GeometryService.

As far as I know, the first one came up as a helper utility with the change of ArcGIS Online from WGS84 to WebMercator.

Axel
0 Kudos
derekswingley1
Deactivated User
The geographicToWebMercator helper method only converts lat, long coordinates to web mercator while the geometry service's project method does not have this restriction. The geometry service supports re-projecting from any of the coordinate systems listed in the help: 
http://help.arcgis.com/en/arcgisserver/10.0/apis/rest/pcs.html
http://help.arcgis.com/en/arcgisserver/10.0/apis/rest/gcs.html

Also, geographicToWebMercator works on a single geometry while the geometry service can works with one or more geometries. The only downside of the geometry service is that it requires a server round trip while geographicToWebMercator is all client side.
0 Kudos
nicogis
MVP Alum
Swingley, peraphs, the sense of question is if there is difference (example: accuracy/precision, density points ect) between to project a geometry with geographicToWebMercator()  or with geometryService (from 4326 to 102100).
0 Kudos
YardenCochav
Deactivated User
Thanks for your answers. My question was intended to the last thread, if converting to web mercator via the client helper method is similar to geometry service project function, or less accurate?
0 Kudos
derekswingley1
Deactivated User
Why not test it out? Here's a modified version of the Project a Point sample that also uses geographicToWebMercator():

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; 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"/>
    <title>Project a point</title>

    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.4/js/dojo/dijit/themes/claro/claro.css">
    <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.4" type="text/javascript"></script>

    <script type="text/javascript">
      dojo.require("esri.map");
      dojo.require("esri.tasks.geometry");

      var map = null;
      var gsvc = null;
      var pt = null;

      function initialize() {
        map = new esri.Map("map");
        var layer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
        map.addLayer(layer);
        map.setExtent(new esri.geometry.Extent(-144.13, 7.98, -52.76, 68.89, new esri.SpatialReference({wkid: 4326})));
        map.infoWindow.resize(360, 120);

        gsvc = new esri.tasks.GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
        dojo.connect(map, "onClick", projectToWebMercator);
      }

      function projectToWebMercator(evt) {
        map.graphics.clear();
        
        var point = evt.mapPoint;
        var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND);
        var graphic = new esri.Graphic(point, symbol);
        var outSR = new esri.SpatialReference({ wkid: 102113});

        // convert client side
        var wm = esri.geometry.geographicToWebMercator(point);
        
        map.graphics.add(graphic);

        gsvc.project([ point ], outSR, function(projectedPoints) {
          pt = projectedPoints[0];
          // display both geometry service result and the client side result
          graphic.setInfoTemplate(new esri.InfoTemplate("Coordinates",
            "<table><tbody><tr><td>Geometry Service:</td><td>" + pt.x.toFixed(3) + ", " + pt.y.toFixed(3) +
            "</td></tr><tr><td>Client Side:</td><td>" + wm.x.toFixed(3) + ", " + wm.y.toFixed(3) + "</td></tr></tbody></table>"
          ));
          map.infoWindow
            .setTitle(graphic.getTitle())
            .setContent(graphic.getContent())
            .show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
        });
      }
      dojo.addOnLoad(initialize);
    </script>

  </head>
  <body class="claro">
    <b>Click a location on the map to Project from LatLng -> Web Mercator:</b>
    <div id="map" style="width:800px; height:800px; border:1px solid #000;"></div>
  </body>
</html>
0 Kudos