# Math on projecting lat/long to a small map

**URL:** <https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609>\
**Category:** Factual Questions\
**Created:** [January 18, 2020, 6:19am UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609 "2020-01-18T06:19:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thelurkinghorror](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@thelurkinghorror](https://boards.straightdope.com/u/thelurkinghorror)\
**Post date:** [January 18, 2020, 6:19am UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/1 "2020-01-18T06:19:29Z")

</div>

I have: a specific map image covering the US, with an arbitrary size, and many latitude, longitude pairs I want to plot on that map. I want to convert them to x, y pixel pairs and plot. But the coordinates or pixels on the map don’t correspond to any real world system. All my searches mostly come up with stuff that uses the earth’s radius or that latitude is +/- 90 deg and longitude +/- 180. But I don’t want to plot the whole world. It’s a 2D projection, does the type matter? Mercator-ish. I assume I can do it with one or probably two reference points where I know both the l, l and x, y coordinates. Unfortunately I can’t get the 1, 1 coordinates with any accuracy because they’re in the ocean, so I can only approximate any 2 random places on the map.

I realize that projection requires some sacrifices, and all my points may not be exact especially on opposite ends of the map. I’m okay with some wiggle room. But the math I’m running doesn’t even put my test points in the remotely correct locations.

[This seems helpful](https://stackoverflow.com/questions/16266809/convert-from-latitude-longitude-to-x-y), but I can’t get it to work.

---

<div class="post-metadata">

**Author:** ![septimus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/septimus/32/410_2.png) [@septimus](https://boards.straightdope.com/u/septimus)\
**Post date:** [January 18, 2020, 10:03am UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/2 "2020-01-18T10:03:55Z")

</div>

UIAM Wikipedia shows [these formulae for the conversion from (lat., long.) to a Mercator map](https://wikimedia.org/api/rest_v1/media/math/render/svg/62ea14e55f1e378a2a82a2ff70bee9d2f8cabf8d). Are these the formulae you’re trying to use? Is it the constants you’re trying to set?

Post a link to the map image and someone (me?) will try to tune the suitable formulae.

---

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [January 18, 2020, 12:01pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/3 "2020-01-18T12:01:04Z")

</div>

This might help, I haven’t done it with google earth but this is a pretty standard process in GIS -

[Import Excel lat and long into Google Earth.](https://www.youtube.com/watch?v=XRD9a2jlUcY)

---

<div class="post-metadata">

**Author:** ![JKellyMap](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/jkellymap/32/15880_2.png) [@JKellyMap](https://boards.straightdope.com/u/JKellyMap)\
**Post date:** [January 18, 2020, 12:46pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/4 "2020-01-18T12:46:27Z")

</div>

Yes, it would be best to figure out what the projection of the map is (what you called the “type” — you guessed “Mercator-ish”). If you can’t, do you have to use that particular map? Can you use a map whose projection you DO know?

If you must use that map: If you have access to a GIS software — QGIS is a freeware, and the free version of ArcGIS Online has some tools — you would do what’s called **georeference** your image file (which has arbitrary pixel “location” values). You start a GIS project with a known projection you decide on (doesn’t really matter which), display a base map from the GIS files that include stuff (coastlines, roads, towns, whatever) that’s also on your image file, and then by hand you click on several (five to ten) pairs of corresponding locations common to both. Then you press a button, and the software “rubber sheets” your image file — now, it has a known projection. You can now easily upload your lat long coordinates, specifying to the GIS exactly what they represent, and they’ll be displayed in the correct locations.

---

<div class="post-metadata">

**Author:** ![JKellyMap](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/jkellymap/32/15880_2.png) [@JKellyMap](https://boards.straightdope.com/u/JKellyMap)\
**Post date:** [January 18, 2020, 1:17pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/5 "2020-01-18T13:17:59Z")

</div>

To clarify: as you “display a base map from the GIS files that include stuff (coastlines, roads, towns, whatever) that’s also on your image file,” you also display your image file. At first, your image file will display at a random location on your screen. You click on the first pair of points that represent a common location (say, a crossroads) — one on your image, the other on the known-projection base map. Your image will now be displayed closer to its proper location, but still with the wrong scale and possibly tilted. Now, click for the next pair (best to choose a common location far from the first one — very much like tightening bolts after changing a wheel). Now, the two maps should “snap into place,” more or less. But you should still do at least five more pairs, to make the resulting “rubber sheeted” version of your image more accurate. (More than ten pairs is usually useless).

By the way, your now-projected image map is a “raster” file - cells with color values (like pixels). The lat-long points you display afterwards will be a “vector” file (points, lines, or polygons - in this case, points). Any GIS can display both file types at the same time (published maps usually include layers of each), but if you were to get into more involved analysis and stuff, you’d have to convert one of the files to the others’ type.

---

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [January 18, 2020, 1:54pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/6 "2020-01-18T13:54:53Z")

</div>

Hey JKelly, how long in GIS?

I’m ancient. 31 years now. Before it was even called GIS. Simply called it Computer Mapping, or AMFM (automated mapping/Facilities management). Been with the same County Gov for 28 years now. Started with Intergraph and main frames. All ESRI now (actually saw an ESRI commercial on TV the other night, blew me away).

---

<div class="post-metadata">

**Author:** ![JKellyMap](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/jkellymap/32/15880_2.png) [@JKellyMap](https://boards.straightdope.com/u/JKellyMap)\
**Post date:** [January 18, 2020, 3:29pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/7 "2020-01-18T15:29:09Z")

</div>

> [@enipla](#):
>
> Hey JKelly, how long in GIS?
> 
> I’m ancient. 31 years now. Before it was even called GIS. Simply called it Computer Mapping, or AMFM (automated mapping/Facilities management). Been with the same County Gov for 28 years now. Started with Intergraph and main frames. All ESRI now (actually saw an ESRI commercial on TV the other night, blew me away).

Ha! My first GIS experience was with Intergraph as well — a course taught by Canadian pioneer John Radke at U. Of California in 1993. Didn’t really use it professionally until around 1999 — ArcView and a bit of satellite imagery processing, in Mexico. Wouldn’t have called myself anything close to an expert until around 2006, during doctoral studies and research.

A Doper (current? former?) named Mr. Dibble is more of an expert than I am. Probably several others are as well.

---

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [January 18, 2020, 4:00pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/8 "2020-01-18T16:00:14Z")

</div>

> [@JKellyMap](#):
>
> Ha! My first GIS experience was with Intergraph as well — a course taught by Canadian pioneer John Radke at U. Of California in 1993. Didn’t really use it professionally until around 1999 — ArcView and a bit of satellite imagery processing, in Mexico. Wouldn’t have called myself anything close to an expert until around 2006, during doctoral studies and research.
> 
> A Doper (current? former?) named Mr. Dibble is more of an expert than I am. Probably several others are as well.

Cool. Way back when, nobody understood spatial analysis. “The whosa what then?”

I wrote some training documents and taught staff just what the heck it is. Today, most people understand it as well as they understand a refrigerator gets cold (not dissing people, GIS can be pretty freaky). But that’s something at least.

I manage an SQL SDE DB for the County I work for. A lot of stuff wants to go to the cloud now though. I’m trying to figure out how to balance that out. ESRI AGOL and Portal mostly.

---

<div class="post-metadata">

**Author:** ![JKellyMap](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/jkellymap/32/15880_2.png) [@JKellyMap](https://boards.straightdope.com/u/JKellyMap)\
**Post date:** [January 18, 2020, 4:27pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/9 "2020-01-18T16:27:07Z")

</div>

Awesome. 🙂

---

<div class="post-metadata">

**Author:** ![thelurkinghorror](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@thelurkinghorror](https://boards.straightdope.com/u/thelurkinghorror)\
**Post date:** [January 18, 2020, 5:54pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/10 "2020-01-18T17:54:44Z")

</div>

> [@septimus](#):
>
> UIAM Wikipedia shows [these formulae for the conversion from (lat., long.) to a Mercator map](https://wikimedia.org/api/rest_v1/media/math/render/svg/62ea14e55f1e378a2a82a2ff70bee9d2f8cabf8d). Are these the formulae you’re trying to use? Is it the constants you’re trying to set?
> 
> Post a link to the map image and someone (me?) will try to tune the suitable formulae.

Thanks, I’m trying that and can’t get it to work but I’ll play with it. y ends up negative due the log but pixel values should be positive. How do I determine R without a scale? I guess that’s the crucial missing element, I just was thinking a reference point or two would help.

Map is generated from [this website](https://mapchart.net/usa-counties.html), you can save a copy at the bottom right. I don’t need **this** particular map but I need a map with county lines.

> [@JKellyMap](#):
>
> Yes, it would be best to figure out what the projection of the map is (what you called the “type” — you guessed “Mercator-ish”). If you can’t, do you have to use that particular map? Can you use a map whose projection you DO know?
> 
> If you must use that map: If you have access to a GIS software — QGIS is a freeware, and the free version of ArcGIS Online has some tools — you would do what’s called **georeference** your image file (which has arbitrary pixel “location” values). You start a GIS project with a known projection you decide on (doesn’t really matter which), display a base map from the GIS files that include stuff (coastlines, roads, towns, whatever) that’s also on your image file, and then by hand you click on several (five to ten) pairs of corresponding locations common to both. Then you press a button, and the software “rubber sheets” your image file — now, it has a known projection. You can now easily upload your lat long coordinates, specifying to the GIS exactly what they represent, and they’ll be displayed in the correct locations.

The final product is important, but also I’d rather avoid external software and it’s just a non-essential project I wanted to try. But if GIS is unavoidable and can get me a map or some constants I’ll try it out.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [January 18, 2020, 7:48pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/11 "2020-01-18T19:48:12Z")

</div>

OpenStreetMap displays county boundaries and can export data in various known formats.

---

<div class="post-metadata">

**Author:** ![md2000](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@md2000](https://boards.straightdope.com/u/md2000)\
**Post date:** [January 18, 2020, 9:03pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/12 "2020-01-18T21:03:06Z")

</div>

To create simple, small local maps, most geologist and similar professionals use UTM - Universal Transverse Mercator. Basically, put the 1,1 at the center of the map you want, then assume the map is a cylindrical (Mercator) projection - as if the light source for the projection were at the center of the earth.

To convert to X,Y from a globe, you need to know the projection used to convert. Mercator is like a tube wrapped around the earth, infinite to the north and south. The light that projects our imaginary transparent globe onto this tube is located at the center of the earth. Obviously, the further north or south, the more distorted. Mercator’s map was popular (except in extreme north latitudes) because any compass heading was a straight line. (Ignoring “magnetic north pole not actual north pole” issues).

For your case of the whole (continental?) USA - is this a Mercator or cylindrical projection? Are the “straight” lines on the globe (i.e.49th parallel, most obvious example) straight lines on your map, or curved? Is the lat/long grid straight lines? What is the purpose of the map - is area most important, or consistency of distance measurements on the map, or headings? If it’s just for illustrative purposes, put your 0,0 point near the geographical center of the continental USA (i.e. Kansas City) and simply use lat and long difference from there as x and y. (60 seconds to a minute, 60 minutes to a degree -easy to translate to x,y). Google Earth can give you L,L to excruciating detail.

---

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [January 18, 2020, 9:41pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/13 "2020-01-18T21:41:11Z")

</div>

R? You’re have trouble with the value of R? What is R?

If you told us what you are trying to map, it would help. What is this data from/for?

Must it be located on your current map? Or would a different basemap work? How many points are you looking at? 10, 100 or 1,000,000? What is your goal? Is it for display, or crunching data?

I’m guessing not data, since you seem to be ok if it’s sort of accurate. A thematic map then.

Excuse the interrogation, but this stuff is my job.

---

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [January 18, 2020, 10:04pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/14 "2020-01-18T22:04:21Z")

</div>

Could you post a few coordinate values that you are trying to map?

---

<div class="post-metadata">

**Author:** ![thelurkinghorror](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@thelurkinghorror](https://boards.straightdope.com/u/thelurkinghorror)\
**Post date:** [January 18, 2020, 11:19pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/15 "2020-01-18T23:19:54Z")

</div>

> [@enipla](#):
>
> R? You’re have trouble with the value of R? What is R?
> 
> If you told us what you are trying to map, it would help. What is this data from/for?
> 
> Must it be located on your current map? Or would a different basemap work? How many points are you looking at? 10, 100 or 1,000,000? What is your goal? Is it for display, or crunching data?
> 
> I’m guessing not data, since you seem to be ok if it’s sort of accurate. A thematic map then.
> 
> Excuse the interrogation, but this stuff is my job.

From the directly quoted equation, it should refer to the radius of the earth in km I think.

Thousands of points, purely for the challenge. It’s not homework or something.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [January 18, 2020, 11:39pm UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/16 "2020-01-18T23:39:43Z")

</div>

Try the “direct transformation formulae” on [this page](https://en.wikipedia.org/wiki/Transverse_Mercator_projection).

---

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [January 19, 2020, 12:39am UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/17 "2020-01-19T00:39:14Z")

</div>

> [@thelurkinghorror](#):
>
> From the directly quoted equation, it should refer to the radius of the earth in km I think.
> 
> Thousands of points, purely for the challenge. It’s not homework or something.

I was just asking for some real numbers like decimal degrees. Degrees Minutes Seconds. Something. Cut and paste a few pairs.

> [@thelurkinghorror](#):
>
> and many latitude, longitude pairs I want to plot on that map.

I don’t think this is a homework assignment. I think it’s real world but suppose I could be wrong.

---

<div class="post-metadata">

**Author:** ![Banksiaman](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/banksiaman/32/3334_2.png) [@Banksiaman](https://boards.straightdope.com/u/Banksiaman)\
**Post date:** [January 19, 2020, 12:52am UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/18 "2020-01-19T00:52:23Z")

</div>

There was mention of county boundaries. If the main goal is to colour in those counties where, let’s guess your data, ultra-high cheese purchases took place, then it would be a lot easier to get a county map of the US that you could infill in MS-Paint.

As others have pointed out, while your data is in lat-long pairs, there is no guarantee that your “specific map image covering the US, with an arbitrary size” is actually a proper projection (UTM Mercator or otherwise) where 1 degree of longitude on the west coast also measures 1 degree on the east coast.

---

<div class="post-metadata">

**Author:** ![thelurkinghorror](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@thelurkinghorror](https://boards.straightdope.com/u/thelurkinghorror)\
**Post date:** [January 19, 2020, 2:45am UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/19 "2020-01-19T02:45:08Z")

</div>

> [@DPRK](#):
>
> Try the “direct transformation formulae” on [this page](https://en.wikipedia.org/wiki/Transverse_Mercator_projection).

Thanks, sounds like k0 is something to play with.

> [@enipla](#):
>
> I was just asking for some real numbers like decimal degrees. Degrees Minutes Seconds. Something. Cut and paste a few pairs.
> 
> I don’t think this is a homework assignment. I think it’s real world but suppose I could be wrong.

I mean, NYC is roughly 40.661, -73.944. LA is 34.05, -118.25.

Not sure what you mean by “real world.”

> [@Banksiaman](#):
>
> There was mention of county boundaries. If the main goal is to colour in those counties where, let’s guess your data, ultra-high cheese purchases took place, then it would be a lot easier to get a county map of the US that you could infill in MS-Paint.
> 
> As others have pointed out, while your data is in lat-long pairs, there is no guarantee that your “specific map image covering the US, with an arbitrary size” is actually a proper projection (UTM Mercator or otherwise) where 1 degree of longitude on the west coast also measures 1 degree on the east coast.

Coloring in is plausible, but boring. There are also 3000+ counties. Look at Texas for one.

If I have to provide corrections for one coast, that’s maybe fine. UTM might be pretty good because it has smaller subsections, but there’s quite a few of those.

---

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [January 19, 2020, 2:57am UTC](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609/20 "2020-01-19T02:57:02Z")

</div>

The underlying map is immaterial. That’s simple.

There are so many unanswered questions.

The OP seems to want to map ‘pixels’ and something called an ‘R’ value on a map down to county level accuracy in the USA.

A little sample data and what the heck the goal is would really help.

Uh…

[Next page](https://boards.straightdope.com/t/math-on-projecting-lat-long-to-a-small-map/846609.md?page=2)
