Select to view content in your preferred language

get Coordinates in different Spatialreference

496
2
Jump to solution
09-06-2023 04:46 AM
Vakhtang_Zubiashvili
Occasional Contributor III

Hi all,

 

I am using worldelevation3D service to display X-Y-Z coordinates, but X and Y i want to show in WKID: 32638,

SpatialReference for map i have isGCSWGS1984. To get coordinates i use this code still get different WKID coordinates: 
 
 

 

let beforeLandslideUrl =
          "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";

          const sr1 = new SpatialReference({ wkid: 32638 });

      let beforeLandslideLayer = new ElevationLayer({
            url: beforeLandslideUrl,
            spatialReference: sr1
          });    

 
      view.on("click", function(event) {
        var xyztext = document.getElementById("xyzcheckbox");
        if(xyztext.checked == true){
        // Query both elevation layers for the elevation at the clicked map position
        var position = event.mapPoint;
        var queryBeforeLandslide = beforeLandslideLayer.queryElevation(position);
        // When both query promises resolve execute the following code
        promiseUtils
          .eachAlways([queryBeforeLandslide])
          .then(function(results) {
            var posBeforeLandslide = results[0].value.geometry;
            
            
            // Clear graphics from previous result (if applicable)
            //view.graphics.removeAll();
            //alert("ზღვის დონიდან: " + posBeforeLandslide.z +", " + "x: " + posBeforeLandslide.x + ", " + "y: " + posBeforeLandslide.y)
            // document.getElementById('xyzspan').innerHTML = "X: " + posBeforeLandslide.x.toFixed(2)+ "; " + "Y: " + posBeforeLandslide.y.toFixed(2)+ "; " + "Z: " + posBeforeLandslide.z.toFixed(2);
            document.getElementById('xspan').innerHTML = "X: " + posBeforeLandslide.x.toFixed(2);
            document.getElementById('yspan').innerHTML = "Y: " + posBeforeLandslide.y.toFixed(2);
            document.getElementById('zspan').innerHTML = "Z: " + posBeforeLandslide.z.toFixed(2);
          })
        }
        else
        {
            //view.graphics.removeAll();
        } 
      });

 

0 Kudos
1 Solution

Accepted Solutions
JeffreyThompson2
MVP Regular Contributor

https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-projection.html#project

You will need to call project somewhere in your code. It will be easier and probably perform better to re-project the mouse click, but if you want the map to actually display in WKID: 32638 you will need to do a forEach loop like the first example to re-project all of the graphics.

GIS Developer
City of Arlington, Texas

View solution in original post

0 Kudos
2 Replies
JeffreyThompson2
MVP Regular Contributor

https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-projection.html#project

You will need to call project somewhere in your code. It will be easier and probably perform better to re-project the mouse click, but if you want the map to actually display in WKID: 32638 you will need to do a forEach loop like the first example to re-project all of the graphics.

GIS Developer
City of Arlington, Texas
0 Kudos
Vakhtang_Zubiashvili
Occasional Contributor III

Thanks Jeffry, you gave me right direction, i simply change projection of clicked point and it works fine. Thanks

Working code:

    var beforeLandslideUrl =
          "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";

      var beforeLandslideLayer = new ElevationLayer({
            url: beforeLandslideUrl
          });    

      view.on("click", function(event) {
        var xyztext = document.getElementById("xyzcheckbox");
        
        if(xyztext.checked == true){
        // Query both elevation layers for the elevation at the clicked map position
        let sr1 = new SpatialReference({ wkid: 32638 });
        var position = event.mapPoint;

        let projectedPoints = projection.project(position, sr1);

        console.log(projectedPoints);

        var queryBeforeLandslide = beforeLandslideLayer.queryElevation(position);
        // When both query promises resolve execute the following code
        promiseUtils
          .eachAlways([queryBeforeLandslide])
          .then(function(results) {
            var posBeforeLandslide = results[0].value.geometry;
            
            document.getElementById('xspan').innerHTML = "X: " + posBeforeLandslide.x.toFixed(2);
            document.getElementById('yspan').innerHTML = "Y: " + posBeforeLandslide.y.toFixed(2);
            document.getElementById('zspan').innerHTML = "Z: " + posBeforeLandslide.z.toFixed(2);
          })
        }
        else
        {
            //view.graphics.removeAll();
        } 
      });
0 Kudos