Select to view content in your preferred language

How to Specify Out Unit to Be in Decimal Degree in JS API

5280
34
11-29-2017 03:53 PM
BehrouzHosseini
Regular Contributor

I am using a Map service on ARcGIS Server 10.4.1 which is in this format

Spatial Reference: 102100  (3857) 
Single Fused Map Cache: false 
Initial Extent:

      XMin: -9819759.37726215
      YMin: 5128008.078704429
      XMax: -9809084.764440382
      YMax: 5132626.115644935
      Spatial Reference: 102100  (3857)

Full Extent:

      XMin: -9819004.6505
      YMin: 5125535.589900002
      XMax: -9809349.0802
      YMax: 5131992.668099999
      Spatial Reference: 102100  (3857)

 

Units: esriMeters 

Now when I query the service it returns the data in Meter format which I can not display back them on the map as new graphics. Can you please let me know how I can change the service configuration or OutUnit in ArcGIS JavaScript API to be in Decimal Degree

0 Kudos
34 Replies
RobertScheitlin__GISP
MVP Emeritus

Bengi,

   Because the map service is in WKID 102100 that means that the units will be meters. If you use a Query task then you can specify the outSpatialReference to be in 4326 which will give you decimal degrees

0 Kudos
BehrouzHosseini
Regular Contributor

Hi Robert,

Thanks for reply I change the out spatial to 4326 and as you can see from below I am getting geometry in wkid:4236 but I am getting the X and Y in Meter not in decimal degree!

  1. {OBJECTID: 1100}
  2. geometry:
    1. spatialReference:{wkid: 4326}
    2. type:"point"
    3. x:-9814834.6714
    4. y:5130507.876800001
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Bengi,


  Can you share your code on how you are changing the outSpatialReference?

0 Kudos
BehrouzHosseini
Regular Contributor

Hi Robert,

Here is the code

I am able to console log the results but not able to display them on the map

var graphicsLayerTraceNetworkJunctions, graphicsLayerTraceNetworkEdges;
graphicsLayerTraceNetworkJunctions = new esri.layers.GraphicsLayer();
 var rendererTraceNetworkJunctions = new esri.renderer.SimpleRenderer(agsConfig.symbolTraceNetworkJunctions);
 graphicsLayerTraceNetworkJunctions.setRenderer(rendererTraceNetworkJunctions);
 map.addLayer(graphicsLayerTraceNetworkJunctions);
 map.reorderLayer(graphicsLayerTraceNetworkJunctions, 1);
 
 graphicsLayerTraceNetworkEdges = new esri.layers.GraphicsLayer();
 var rendererTraceNetworkEdges = new esri.renderer.SimpleRenderer(agsConfig.symbolTraceNetworkEdges);
 graphicsLayerTraceNetworkEdges.setRenderer(rendererTraceNetworkEdges);
 map.addLayer(graphicsLayerTraceNetworkEdges);
 map.reorderLayer(graphicsLayerTraceNetworkEdges, 2);
 
 function solve(traceSolverType, params) {
 var gn = 'ElecGeomNet';
 esri.request({
 url: 'http://localhost/arcgis/rest/services/ENetNADPDWeb/MapServer/exts/GeometricNetworkUtility/GeometricN...' + traceSolverType,
 content: params,
 callbackParamName: "callback",
 outSR: 4326,
 load: function (result) {
 
 //result = result.geometry = webMercatorUtils.webMercatorToGeographic(geometries[0]);
 
 if (traceFlowElement == 'esriFEJunctionsAndEdges') {
 var edgesResultFeatures = result.edges;
 console.log(edgesResultFeatures);
 var edgeGraphics;
 for (var j = 0, jl = edgesResultFeatures.length; j < jl; j++) {
 var featureSet = edgesResultFeatures[j].features;
 for (var i = 0, il = featureSet.length; i < il; i++) {
 edgeGraphics = new esri.Graphic(featureSet[i])
 graphicsLayerTraceNetworkEdges.add(edgeGraphics);
 }
 }
 
 var junctionsResultFeatures = result.junctions;
 console.log(junctionsResultFeatures);
 var junctionsGraphics;
 
 for (var j = 0, jl = junctionsResultFeatures.length; j < jl; j++) {
 var featureSet = junctionsResultFeatures[j].features;
 for (var i = 0, il = featureSet.length; i < il; i++) {
 
 junctionsGraphics = new esri.Graphic(featureSet[i]);
 graphicsLayerTraceNetworkJunctions.add(junctionsGraphics);
 
 }
 }
 
 }
 }
0 Kudos
ThomasSolow
Frequent Contributor

Setting outSpatialReference somewhere might help you if you're trying to query a Feature Service.

Another option is to pull in webMercatorUtils from esri/geometry/support/webMercatorUtils and use that module to convert between Web Mercator and WGS84 Latitude/Longitude.

webMercatorUtils | API Reference | ArcGIS API for JavaScript 4.5 

I would specifically look at the "webMercatorToGeographic" function, which will convert a geometry from Web Mercator to WGS84 longitude/latitude.

0 Kudos
BehrouzHosseini
Regular Contributor

Thanks for comment Thomas,

I tried to do this in two ways

A_

load: function (result) {
 result = result.geometry = webMercatorUtils.webMercatorToGeographic(geometries[0]);
....
}

and also tried this way B_

var junctionsResultFeatures = result.junctions;
  junctionsResultFeatures = featureSet.map(function (s) {
     s.geometry = webMercatorUtils.xyToLngLat(s.geometry.x, s.geometry.y, true);
     return s;
 })

the first way ireturns

nothing! no error but also nothing on console log. The second way is really converting the geometry to decimal degree but again I am not seeing the result graphics on map

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Bengi,

   I am not familiar with a the geometric network trace task and if you are specifying the outSR correctly. But as Thomas points out you can easily convert the results of your task (assuming they are returning in WKID 102100) to WGS84 by using web mercator utils.

Lines 32 and 45:

var graphicsLayerTraceNetworkJunctions, graphicsLayerTraceNetworkEdges;
graphicsLayerTraceNetworkJunctions = new esri.layers.GraphicsLayer();
 var rendererTraceNetworkJunctions = new esri.renderer.SimpleRenderer(agsConfig.symbolTraceNetworkJunctions);
 graphicsLayerTraceNetworkJunctions.setRenderer(rendererTraceNetworkJunctions);
 map.addLayer(graphicsLayerTraceNetworkJunctions);
 map.reorderLayer(graphicsLayerTraceNetworkJunctions, 1);
 
 graphicsLayerTraceNetworkEdges = new esri.layers.GraphicsLayer();
 var rendererTraceNetworkEdges = new esri.renderer.SimpleRenderer(agsConfig.symbolTraceNetworkEdges);
 graphicsLayerTraceNetworkEdges.setRenderer(rendererTraceNetworkEdges);
 map.addLayer(graphicsLayerTraceNetworkEdges);
 map.reorderLayer(graphicsLayerTraceNetworkEdges, 2);
 
 function solve(traceSolverType, params) {
 var gn = 'ElecGeomNet';
 esri.request({
 url: 'http://localhost/arcgis/rest/services/ENetNADPDWeb/MapServer/exts/GeometricNetworkUtility/GeometricN...' + traceSolverType,
 content: params,
 callbackParamName: "callback",
 outSR: 4326,
 load: function (result) {
 
 //result = result.geometry = webMercatorUtils.webMercatorToGeographic(geometries[0]);
 
 if (traceFlowElement == 'esriFEJunctionsAndEdges') {
 var edgesResultFeatures = result.edges;
 console.log(edgesResultFeatures);
 var edgeGraphics;
 for (var j = 0, jl = edgesResultFeatures.length; j < jl; j++) {
 var featureSet = edgesResultFeatures[j].features;
 for (var i = 0, il = featureSet.length; i < il; i++) {
 edgeGraphics = new esri.Graphic(esri.geometry.webMercatorUtils.webMercatorToGeographic(featureSet[i].geometry));
 graphicsLayerTraceNetworkEdges.add(edgeGraphics);
 }
 }
 
 var junctionsResultFeatures = result.junctions;
 console.log(junctionsResultFeatures);
 var junctionsGraphics;
 
 for (var j = 0, jl = junctionsResultFeatures.length; j < jl; j++) {
 var featureSet = junctionsResultFeatures[j].features;
 for (var i = 0, il = featureSet.length; i < il; i++) {
 
 junctionsGraphics = new esri.Graphic(esri.geometry.webMercatorUtils.webMercatorToGeographic(featureSet[i].geometry));
 graphicsLayerTraceNetworkJunctions.add(junctionsGraphics);
 
 }
 }
 
 }
 }
0 Kudos
BehrouzHosseini
Regular Contributor

Thanks for this Ribert but same thing! I am not even getting the result back oon console log

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Bengi,

   Have you ever been getting any results at all from your esriRequest?

0 Kudos