# How to convert X,Y coordiinates to Long,Lat (wkid:2039 to wkid:4326) and vice versa

415
7
01-26-2021 01:33 AM
Labels (2)
Occasional Contributor III

In WAB (Develper Edtion) 2.17 custom widget, How to convert point X,Y coordinates (Israel New Grid wkid:2039) to geographic Long,Lat (wkid:4326) and vice versa ? maybe in Coordinate.js there is some useful code for this?

Help will be greatly appreciated,

Michael

Tags (1)
1 Solution

Accepted Solutions
MVP Esteemed Contributor

Michael,

Maybe this will help. The only thing I used to figure this out is the help docs.

``````  <script>
require([
"esri/geometry/projection",
"esri/geometry/SpatialReference",
"esri/geometry/Point",
"esri/geometry/support/GeographicTransformationStep",
"esri/geometry/support/GeographicTransformation"
], function (projection, SpatialReference, Point, GeographicTransformationStep, GeographicTransformation) {
const cs2 = new SpatialReference({
wkid: 4326
});

const geoStep = new GeographicTransformationStep({
wkid: 108021
});

const geoTrans = new GeographicTransformation({
steps:[geoStep]
});

const pnt = new Point({
x: xxxxx,
y: yyyy,
spatialReference: 2039
});
const pGeom = projection.project(pnt, cs2, geoTrans);
});
});
</script>``````
7 Replies
Occasional Contributor III

@RobertScheitlin__GISP maybe you can help? Thanks

MVP Esteemed Contributor

Michael,

This is nothing specific to WAB. There are dozens of answered question about projecting coordinate in the JS API space. Here is one assuming you are still using 3D in WAB.

https://community.esri.com/t5/arcgis-api-for-javascript/example-for-projection/m-p/53909#M4778

Occasional Contributor III

Dear Robert,

I'm indeed developing 3D custom widgets for WAB 2.17

I'm sorry, but I totally don't understand your example. I just started with this era which is very new to me.

I don't need extent. I have pair of wkid:2039 x,y coordinates of some point location and I need to evaluate the geographic wkid:4326 long/lat. I know that the WAB sceneView map is wkid:4326 (actually it uses WGS_1984_Web_Mercator_Auxiliary_Sphere (3857) which is also called102100 spatial reference - I don't know exactly what all this means...), and that the transformation forward/nackward to wkid:2039 is TFWKID:108021 and that is all inputs I know.

I have not learned yet the "project/projection" subject involving with transformatons and besides getting help with my specific question, I'd like to get hints what are the links to look in order to properly learn and understand this subject which seem to me a complicated one. I appreciate your help very much.

I see that webMercatorUtils has xyToLngLat() function, but it ises wkid:3857 while I need to convert for wkid:2039 ... so I understand I am missing something important in how to do conversions...

P.S. I used some independent code (from github), but the results were not accurate, so I must use esri functions.

MVP Esteemed Contributor

Michael,

Maybe this will help. The only thing I used to figure this out is the help docs.

``````  <script>
require([
"esri/geometry/projection",
"esri/geometry/SpatialReference",
"esri/geometry/Point",
"esri/geometry/support/GeographicTransformationStep",
"esri/geometry/support/GeographicTransformation"
], function (projection, SpatialReference, Point, GeographicTransformationStep, GeographicTransformation) {
const cs2 = new SpatialReference({
wkid: 4326
});

const geoStep = new GeographicTransformationStep({
wkid: 108021
});

const geoTrans = new GeographicTransformation({
steps:[geoStep]
});

const pnt = new Point({
x: xxxxx,
y: yyyy,
spatialReference: 2039
});
const pGeom = projection.project(pnt, cs2, geoTrans);
});
});
</script>``````
Occasional Contributor III

Dear Robert,

It gives error of abot 200 meters...

If it can help, I can give you my code so it can be run and debugged.

Occasional Contributor III

I found that in new GeographicTransformationStep I need to add isInverse: true

I still don't know if it is more accurate or less accurate than what I've got with the google way (which gave approximately 10m error). I'm still checking it...

Occasional Contributor III

Thank you, Robert. It's correct (only in new GeographicTransformationStep I need to add isInverse: true)