What are the coordinates used in the Path parameter of the Polyline class?

1787
5
Jump to solution
03-09-2017 01:10 PM
robertparham
New Contributor II

I'm drawing a bunch of carrier routes from the USPS API to an ArcGIS map. I need to only show the routes that are within a certain distance from a certain point. I have the latitude and longitude for the center point.

I thought the paths used by Polyline were made up of latitude and longitude sets multiplied by 100000, and I tried using them as such but that didn't work. The paths are generated from point sets that look like this:  -9214713, 3256075. When divided by 100000 they look like longitude and latitude, but I guess they're not.

What are these coordinates used in the Path parameter of the Polyline class, and how can I convert them to lat and lng for the purpose of calculating distance?

0 Kudos
1 Solution

Accepted Solutions
ThomasSolow
Occasional Contributor III

Are you using 3.XX or 4.XX?

Assuming 3.XX: use this method: esri/geometry/webMercatorUtils | API Reference | ArcGIS API for JavaScript 3.20 

The function signature is: webMercatorUtils.xyToLngLat(x: number, y: number) -> [longitude: number, latitude: number]

So it takes an x and y (in meters) and returns an array with 2 elements, the first being the longitude and the second being the latitude.

View solution in original post

5 Replies
ThomasSolow
Occasional Contributor III

They're probably web mercator coordinates, which are in meters.  To be certain, you should check the spatial reference on the polyline and make sure it's web mercator.  You can convert between between long/lat and web mercator x/y using the webMercatorUtils module: esri/geometry/webMercatorUtils | API Reference | ArcGIS API for JavaScript 3.20 

If you're using the 4.XX API it's: webMercatorUtils | API Reference | ArcGIS API for JavaScript 4.3

Since the polylines you're testing are already using web mercator coordinates, you should probably convert the long/lat you have into web mercator XY and test everything in web mercator coordinates.

There are a few ways to approach the actual testing.  You might find the geometry engine useful for this: esri/geometry/geometryEngine | API Reference | ArcGIS API for JavaScript 3.20 (4.XX: geometryEngine | API Reference | ArcGIS API for JavaScript 4.3 )

robertparham
New Contributor II

Thank you so much for your help.

I checked the spatial reference as suggested, the spatialReference._info.wkTemplate property is:

PROJCS["WGS_1984_Web_Mercator",GEOGCS["GCS_WGS_1984_Major_Auxiliary_Sphere",DATUM["D_WGS_1984_Major_Auxiliary_Sphere",SPHEROID["WGS_1984_Major_Auxiliary_Sphere",6378137.0,0.0]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Mercator"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",${Central_Meridian}],PARAMETER["Standard_Parallel_1",0.0],UNIT["Meter",1.0]]

I don't know what that means exactly but it appears to me that your guess about it being web mercator is correct, right?

Given this info, which method on the webMercatorUtils object would be required to convert the coordinates/path/geometry to degrees (lat/lng)? I tried all of them but most returned undefined. If you can tell me which one is correct it will help in debugging.

0 Kudos
ThomasSolow
Occasional Contributor III

Are you using 3.XX or 4.XX?

Assuming 3.XX: use this method: esri/geometry/webMercatorUtils | API Reference | ArcGIS API for JavaScript 3.20 

The function signature is: webMercatorUtils.xyToLngLat(x: number, y: number) -> [longitude: number, latitude: number]

So it takes an x and y (in meters) and returns an array with 2 elements, the first being the longitude and the second being the latitude.

robertparham
New Contributor II

You da real MVP Thomas.

Thank you so much for your help. Do you have a donate button somewhere so I can buy you a beer/coffee?

0 Kudos
ThomasSolow
Occasional Contributor III

You're welcome, glad I could be of help.

0 Kudos