<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Lat/Long to Web Mercator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/lat-long-to-web-mercator/m-p/521492#M40883</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can someone enlighten me with the following problem?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have an x,y lat/long values and want to convert them to the equivalent web mercator coordinates in meters, what's my best approach?&amp;nbsp; I can't seem to find anything in arcpy that will take 2 lat/long and give me 2 web mercator x,y.&amp;nbsp; Thought?&amp;nbsp; Thanks in advance!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Mar 2014 15:06:37 GMT</pubDate>
    <dc:creator>TonySmith3</dc:creator>
    <dc:date>2014-03-03T15:06:37Z</dc:date>
    <item>
      <title>Lat/Long to Web Mercator</title>
      <link>https://community.esri.com/t5/python-questions/lat-long-to-web-mercator/m-p/521492#M40883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can someone enlighten me with the following problem?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have an x,y lat/long values and want to convert them to the equivalent web mercator coordinates in meters, what's my best approach?&amp;nbsp; I can't seem to find anything in arcpy that will take 2 lat/long and give me 2 web mercator x,y.&amp;nbsp; Thought?&amp;nbsp; Thanks in advance!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Mar 2014 15:06:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lat-long-to-web-mercator/m-p/521492#M40883</guid>
      <dc:creator>TonySmith3</dc:creator>
      <dc:date>2014-03-03T15:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Lat/Long to Web Mercator</title>
      <link>https://community.esri.com/t5/python-questions/lat-long-to-web-mercator/m-p/521493#M40884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't believe anything is built in that has the functionality. You can pass geometry objects and use project to change coordinate systems. Otherwise it is a fairly simple and well known formula.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a function that works, but I am not sure where it came from.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def geographic_to_web_mercator(x_lon, y_lat): &amp;nbsp;&amp;nbsp;&amp;nbsp; if abs(x_lon) &amp;lt;= 180 and abs(y_lat) &amp;lt; 90:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; num = x_lon * 0.017453292519943295 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = 6378137.0 * num &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = y_lat * 0.017453292519943295&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x_mercator = x &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y_mercator = 3189068.5 * math.log((1.0 + math.sin(a)) / (1.0 - math.sin(a))) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x_mercator, y_mercator&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Invalid coordinate values for conversion')&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Mar 2014 15:24:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lat-long-to-web-mercator/m-p/521493#M40884</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-03-03T15:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Lat/Long to Web Mercator</title>
      <link>https://community.esri.com/t5/python-questions/lat-long-to-web-mercator/m-p/521494#M40885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;will save that bit of code for later reference....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But surely the Arc way to do it is via the spatial reference of the data frame. Load the GCS data, change the df SR to web Mercator, then export the data into a new dataset, or calculate new XY field values using the coord sys of the data frame.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In python using either an update or insert cursor use the .projectAs(arcpy.SpatialReference(3857)) method on the geometry object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3857 is the WKID of the web Mercator aux sphere projection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or just use the Project tool in the tool box.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Neil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2014 05:33:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lat-long-to-web-mercator/m-p/521494#M40885</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2014-03-04T05:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Lat/Long to Web Mercator</title>
      <link>https://community.esri.com/t5/python-questions/lat-long-to-web-mercator/m-p/521495#M40886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;But surely the Arc way to do it ...&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, you are right Neil. I had forgotten about the projectAs method on geometry objects. I haven't done much testing with it and am not sure about how efficient it is, but I imagine that it would garner the same results the OP is after. At that point the only advantage to mine is that it does not require an arc license.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2014 13:09:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lat-long-to-web-mercator/m-p/521495#M40886</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-03-04T13:09:33Z</dc:date>
    </item>
  </channel>
</rss>

