How do I access the data from this json?

1276
5
04-14-2020 08:53 AM
JohnAdams
New Contributor III

I am trying to access the results of the following URL in my Javascript code. The result returned is a JSON, and I'm trying to get the x and y results of that JSON.

Here is the URL:

https://jcgis.jacksongov.org/arcgis/rest/services/Utilities/Geometry/GeometryServer/project?inSR=102...

It would use GET which returns the following object:

https://jcgis.jacksongov.org/arcgis/rest/services/Utilities/Geometry/GeometryServer/project?inSR=102...

I will actually have variables for the lat, long coordinates, but let's leave that hard-coded for the moment.

I have tried all sorts of methods of trying to grab the x and y results but nothing's worked. Currently I have an ajax call like this:

var lat, long, temp;
var url = "https://jcgis.jacksongov.org/arcgis/rest/services/Utilities/Geometry/GeometryServer/project?inSR=102698&outSR=4326&geometries=%7B%0D%0A++%22geometryType%22+%3A+%22esriGeometryPoint%22%2C%0D%0A++%22geometries%22+%3A+%5B%0D%0A+++++%7B%0D%0A+++++++%22x%22+%3A+2806540.74997300%2C++++++++%22y%22+%3A+1036617.12483400%0D%0A+++++%7D%0D%0A++%5D%0D%0A%7D&transformation=&transformForward=true&vertical=false&f=pjson";
$.ajax({
   dataType: 'json',
   type: "GET",
   url: url,
   success: function(jsonobject)
   {
      temp = JSON.parse(jsonobject);
      lat = temp.geometries.x;
      long = temp.geometries.y;
   }
});

I am not sure I am using the parse correctly, but looking at examples in various places online I'm not sure how else it should be done. When I try to run the code the only result I get is "undefined."

What am I missing?

Tags (4)
0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

John,

   Is there any reason you are doing a direct AJAX request instead of doing this in the GeometryService class and it's project method (that way you do not have to manually parse the result)?

https://developers.arcgis.com/javascript/3/jsapi/geometryservice-amd.html#project 

0 Kudos
JohnAdams
New Contributor III

We're trying to convert state plane coordinates to lat-long. We're also using the 4x API. We've looked at the API but could not find anything that converts state plane to lat-long.The best thing we figured out was to use our own geometry service. If there's some other way of doing it, I'm all ears.

0 Kudos
JimBarry
Esri Regular Contributor

>>We've looked at the API but could not find anything that converts state plane to lat-long.The best thing we figured out was to use our own geometry service.

Sounds like you're trying to project individual geometries, and I'm also assuming from that above you'd rather do this client-side than call GeometryService. If so, then the  esri/geometry/projection module's project() method should work. Sample code in this doc as well:

projection | ArcGIS API for JavaScript 4.15 

You just need to know the wkid of both the "from" and the "to" coordinate systems, and if those coordinate systems are using different datums, for best accuracy, you're also going to mix in a geographic transformation.

0 Kudos
RichardBuford
New Contributor

Robert Scheitlin, GISP Could you provide code in JS API 4 where you convert from State Plane to Lat Long. using a geometry service?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Richard,

   Here is a sample that does clinetside projection.

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=client-project... 

I don't have a sample for what you are specifically looking for.

0 Kudos