Client side area and length measurement

1911
2
Jump to solution
03-25-2011 12:11 AM
PauPérez_Puigcerver
New Contributor II
Anybody knows how works the new API Enhancement for measure area and length at client side? There aren't any example.

Thanks

Pau Pérez
Conselleria de Medio Ambiente, Agua, Urbanismo y Vivienda
http://cartoweb.cma.gva.es
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor
We are working on adding a sample that shows how to use these, in the meantime the following code snippets might help:

GeodesicLengths:

map.graphics.add(new esri.Graphic(geometry, graphicSymbol));
//Since the map projection is web mercator, convert to lat/lon
var geographicGeometry = geometry;

//calculate geodesic length on client
var lengths = esri.geometry.geodesicLengths([geographicGeometry], esri.Units.KILOMETERS);


Geodesic Areas:
map.graphics.add(new esri.Graphic(geometry, graphicSymbol));
var geographicGeometries = [];
//if self intersecting, simplify using geometry service
if (esri.geometry.polygonSelfIntersecting(geometry)) {
  //if self intersecting, simplify using geometry service
  geometryService.simplify([geometry], function(simplifiedGeometries) {
    dojo.forEach(simplifiedGeometries, function(simplifiedGeometry, idx) {
      geographicGeometries.push(esri.geometry.webMercatorToGeographic(simplifiedGeometry));
    });
    var areas = esri.geometry.geodesicAreas(geographicGeometries, esri.Units.ACRES);
    dojo.byId("result").innerHTML = "The area of the polygon is: " + areas[0] + " Acres";
  });
}
else {
  geographicGeometries.push(esri.geometry.webMercatorToGeographic(geometry));
  var areas = esri.geometry.geodesicAreas(geographicGeometries, esri.Units.ACRES);
  dojo.byId("result").innerHTML = "The area of the polygon is: " + areas[0] + " Acres";
}
}

View solution in original post

0 Kudos
2 Replies
KellyHutchins
Esri Frequent Contributor
We are working on adding a sample that shows how to use these, in the meantime the following code snippets might help:

GeodesicLengths:

map.graphics.add(new esri.Graphic(geometry, graphicSymbol));
//Since the map projection is web mercator, convert to lat/lon
var geographicGeometry = geometry;

//calculate geodesic length on client
var lengths = esri.geometry.geodesicLengths([geographicGeometry], esri.Units.KILOMETERS);


Geodesic Areas:
map.graphics.add(new esri.Graphic(geometry, graphicSymbol));
var geographicGeometries = [];
//if self intersecting, simplify using geometry service
if (esri.geometry.polygonSelfIntersecting(geometry)) {
  //if self intersecting, simplify using geometry service
  geometryService.simplify([geometry], function(simplifiedGeometries) {
    dojo.forEach(simplifiedGeometries, function(simplifiedGeometry, idx) {
      geographicGeometries.push(esri.geometry.webMercatorToGeographic(simplifiedGeometry));
    });
    var areas = esri.geometry.geodesicAreas(geographicGeometries, esri.Units.ACRES);
    dojo.byId("result").innerHTML = "The area of the polygon is: " + areas[0] + " Acres";
  });
}
else {
  geographicGeometries.push(esri.geometry.webMercatorToGeographic(geometry));
  var areas = esri.geometry.geodesicAreas(geographicGeometries, esri.Units.ACRES);
  dojo.byId("result").innerHTML = "The area of the polygon is: " + areas[0] + " Acres";
}
}
0 Kudos
PauPérez_Puigcerver
New Contributor II
Thanks for the response.
0 Kudos