How to convert an array of (X,Y) point to (Lat,Long)

1136
1
07-24-2019 02:05 PM
MuralidharMoka
New Contributor II

I have an array of projected (X,Y)  points, which I am trying to convert to array of (lat,long). 

I wrote the following method which will take  a single (X, Y ) and  give me ( Lat, Long). This works.

But I do not know how to use this to process my (X,Y) array. This should be simple, but could not get it.


function getLatLong(X,Y){

        return  (new Promise(function (resolve, reject) {
            require(["esri/tasks/GeometryService",
                    "esri/geometry/Point",
                    "esri/tasks/ProjectParameters",
                    "esri/SpatialReference"],
                function (GeometryService, Point, ProjectParameters, SpatialReference) {
                    var XCoord = parseInt(X, 10);
                    var YCoord = parseInt(Y, 10);

                    var inSR = new SpatialReference({wkid: 2274});
                    var outSR = new SpatialReference({wkid: 4326});

                    var gsvc = new GeometryService("https://mapviewtest.memphistn.gov/arcgis/rest/services/Utilities/Geometry/GeometryServer");
                    var inputpoint = new Point(XCoord, YCoord, inSR);
                    var prjParams = new ProjectParameters();
                    prjParams.geometries = [inputpoint];
                    prjParams.outSR = outSR;

                     gsvc.project(prjParams);

                     gsvc.on("project-complete",function(outputpoint){
                        resolve(outputpoint);
                    });

                    gsvc.on("error",function(err){
                        reject(err);
                    })
                });
        }));//promise
    }

Thanks

Muralidhar Moka

0 Kudos
1 Reply
KellyHutchins
Esri Frequent Contributor

ProjectParameters.geometries accepts an array of input geometries to project. So instead of providing one point as you do in your code above 

 prjParams.geometries = [inputpoint];

You can loop through all your x,y coordinates create input points and set them all to the prjParams.geometries.