[NewBee] Convert X Y to Lat Long Programmatically (or Free)

812
6
Jump to solution
04-07-2023 01:01 PM
AbhishekSrivastava2
New Contributor II

Hello All,

Today is the first day I heard about ArcGIS so please bear with me. I am a javascript developer trying to build a hobby project. I was looking for a list of all trailheads in Washington state and found this CSV 

https://hub.arcgis.com/datasets/wa-geoservices::watrailheads-all/about

I downloaded it and it gave me exactly what I was looking for (yay!). However instead of giving me latitude and longitude it gave me arcgis X and Y values.

is there an API which will convert this to a normal lat and long which can be used by google maps?

Please bear with me. I don't have any money to buy arcgis. so please help me how can I achieve that I am trying to do.

Or perhaps is there a way I can install a "free" tool on my Mac which will import this CSV and export another one with lat/long?

Edit:: So I googled a lot and based on everything I found I wrote this python program

from arcgis.gis import GIS
from arcgis.geocoding import reverse_geocode
from arcgis.geometry import from_geo_coordinate_string
gis = GIS()
location = [-118.504999000172, 48.505501999717]
 new_location = reverse_geocode(location)
 print(new_location)

 

But the output still contains X,Y and not Lat Long.

{'address': {'Match_addr': 'East Fork Hall Creek Rd, Boyds, Washington, 99107', 'LongLabel': 'East Fork Hall Creek Rd, Boyds, WA, 99107, USA', 'ShortLabel': 'East Fork Hall Creek Rd', 'Addr_type': 'StreetName', 'Type': '', 'PlaceName': '', 'AddNum': '', 'Address': 'East Fork Hall Creek Rd', 'Block': '', 'Sector': '', 'Neighborhood': '', 'District': '', 'City': 'Boyds', 'MetroArea': '', 'Subregion': 'Ferry County', 'Region': 'Washington', 'RegionAbbr': 'WA', 'Territory': '', 'Postal': '99107', 'PostalExt': '', 'CntryName': 'United States', 'CountryCode': 'USA'}, 'location': {'x': -118.50505046182948, 'y': 48.50548769016435, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}}}
>>>

0 Kudos
1 Solution

Accepted Solutions
JoshuaSharp-Heward
Occasional Contributor III

Hi Abhishek,

I've just downloaded a csv from the open data site you linked and despite the fields being labelled x/y those are latitudes and longitudes (x=longitude, y=latitude).

JoshuaSharpHeward_0-1680907263030.png

And in the reverse geocode example you posted the results are in WGS84 (WKID4326) which is latitude and longitude. You can plug them into google maps and it will work, I've done this with the top row of the csv below

JoshuaSharpHeward_1-1680907490336.png

 

View solution in original post

6 Replies
AbhishekSrivastava2
New Contributor II

I played around with the UI and saved the map given by the government into my own folder https://services.arcgis.com/jsIt88o09Q0r1j8h/arcgis/rest/services/WATrailheads_All/FeatureServer

Now I need to somehow covert X,Y to Lat, Long and then download CSV. 

0 Kudos
JoshuaSharp-Heward
Occasional Contributor III

Hi Abhishek,

I've just downloaded a csv from the open data site you linked and despite the fields being labelled x/y those are latitudes and longitudes (x=longitude, y=latitude).

JoshuaSharpHeward_0-1680907263030.png

And in the reverse geocode example you posted the results are in WGS84 (WKID4326) which is latitude and longitude. You can plug them into google maps and it will work, I've done this with the top row of the csv below

JoshuaSharpHeward_1-1680907490336.png

 

AbhishekSrivastava2
New Contributor II

Thanks so much. I was interpreting it as X = latitude and Y and longitude and it was not working for me. Yes what you say totally makes sense. 

0 Kudos
JoshuaSharp-Heward
Occasional Contributor III

No worries, glad I could help out mate!

0 Kudos
Raul_Jimenez
Esri Contributor

Hi @AbhishekSrivastava2, regarding to this:

...Please bear with me. I don't have any money to buy arcgis. so please help me how can I achieve that I am trying to do.

Or perhaps is there a way I can install a "free" tool on my Mac which will import this CSV and export another one with lat/long?...


I just wanted to let you know that as a developer, you can also create a free account with a generous free tier (+$300/month currently) 😉, and with that soon you will be able to use the new outdoors basemap that was presented a few weeks ago which I think will fit pretty well that dataset 😁.

And remember you can use it with our Maps SDK for JS to build cool visualization like this hiking map:

hikingmap

Or any of the other open source libraries (Leaflet, MapLibre, ...)

I hope this helps!

AbhishekSrivastava2
New Contributor II

wow!!!! nice. thanks for this.