Remember Me?

 Straight Dope Message Board Remember Me?

#1
01-18-2020, 12:19 AM
 Guest Join Date: Jun 2006 Location: Venial Sin City Posts: 14,301

## Math on projecting lat/long to a small map

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, but I can't get it to work.
#2
01-18-2020, 04:03 AM
 Guest Join Date: Dec 2009 Location: the Land of Smiles Posts: 21,530
UIAM Wikipedia shows these formulae for the conversion from (lat., long.) to a Mercator map. 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.
#3
01-18-2020, 06:01 AM
 Member Join Date: Jul 2001 Location: Colorado Rockies. Posts: 15,295
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.
__________________
I don't live in the middle of nowhere, but I can see it from here.
#4
01-18-2020, 06:46 AM
 Member Join Date: Mar 2005 Location: Wisconsin Posts: 10,450
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.

Last edited by JKellyMap; 01-18-2020 at 06:47 AM.
#5
01-18-2020, 07:17 AM
 Member Join Date: Mar 2005 Location: Wisconsin Posts: 10,450
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.
#6
01-18-2020, 07:54 AM
 Member Join Date: Jul 2001 Location: Colorado Rockies. Posts: 15,295
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).
__________________
I don't live in the middle of nowhere, but I can see it from here.
#7
01-18-2020, 09:29 AM
 Member Join Date: Mar 2005 Location: Wisconsin Posts: 10,450
Quote:
 Originally Posted by 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.

Last edited by JKellyMap; 01-18-2020 at 09:30 AM.
#8
01-18-2020, 10:00 AM
 Member Join Date: Jul 2001 Location: Colorado Rockies. Posts: 15,295
Quote:
 Originally Posted by 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.
__________________
I don't live in the middle of nowhere, but I can see it from here.
#9
01-18-2020, 10:27 AM
 Member Join Date: Mar 2005 Location: Wisconsin Posts: 10,450
Awesome.
#10
01-18-2020, 11:54 AM
 Guest Join Date: Jun 2006 Location: Venial Sin City Posts: 14,301
Quote:
 Originally Posted by septimus UIAM Wikipedia shows these formulae for the conversion from (lat., long.) to a Mercator map. 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, you can save a copy at the bottom right. I don't need this particular map but I need a map with county lines.

Quote:
 Originally Posted by 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.
#11
01-18-2020, 01:48 PM
 Guest Join Date: May 2016 Posts: 5,123
OpenStreetMap displays county boundaries and can export data in various known formats.
#12
01-18-2020, 03:03 PM
 Guest Join Date: Feb 2009 Posts: 15,651
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.
#13
01-18-2020, 03:41 PM
 Member Join Date: Jul 2001 Location: Colorado Rockies. Posts: 15,295
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.
__________________
I don't live in the middle of nowhere, but I can see it from here.
#14
01-18-2020, 04:04 PM
 Member Join Date: Jul 2001 Location: Colorado Rockies. Posts: 15,295
Could you post a few coordinate values that you are trying to map?
__________________
I don't live in the middle of nowhere, but I can see it from here.
#15
01-18-2020, 05:19 PM
 Guest Join Date: Jun 2006 Location: Venial Sin City Posts: 14,301
Quote:
 Originally Posted by 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.
#16
01-18-2020, 05:39 PM
 Guest Join Date: May 2016 Posts: 5,123
#17
01-18-2020, 06:39 PM
 Member Join Date: Jul 2001 Location: Colorado Rockies. Posts: 15,295
Quote:
 Originally Posted by 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.

Quote:
 Originally Posted by 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.
__________________
I don't live in the middle of nowhere, but I can see it from here.
#18
01-18-2020, 06:52 PM
 Guest Join Date: Apr 2012 Location: Straya Posts: 1,371
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.
#19
01-18-2020, 08:45 PM
 Guest Join Date: Jun 2006 Location: Venial Sin City Posts: 14,301
Quote:
 Originally Posted by DPRK Try the "direct transformation formulae" on this page.
Thanks, sounds like k0 is something to play with.
Quote:
 Originally Posted by 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."
Quote:
 Originally Posted by 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.
#20
01-18-2020, 08:57 PM
 Member Join Date: Jul 2001 Location: Colorado Rockies. Posts: 15,295
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...
__________________
I don't live in the middle of nowhere, but I can see it from here.
#21
01-18-2020, 09:25 PM
 Guest Join Date: Feb 2009 Posts: 15,651
Different projections serve different aims. Mercator was more for navigation, the polar latitudes are obviously distorted. (In your typical schoolroom map, Canada looks a helluva lot bigger than the USA - it's not reall that much bigger). There are conic projections for better depiction of near-polar regions, there's the orange-peel map for more accurate depiction of surface area without distortion, etc. Depends on your aim.

If all you want is to display county data, and only for the continental USA, a sort of cylindrical projection is probably sufficiently undistorted.

A degree of Longitude at 49 degrees lat. is 45.5 miles; at 25 degrees lat (bottom of Florida) a degree of longitude is 62.73 miles. A degree of lat is pretty much the same in both cases, about 69 miles. The average for longitude in this range is about 54 miles.

If you just translate lat/long to x, y and use the intermediate value for longitude ( each lat degree translates into 61 pixels, each degree of long translates into 54 pixels, scaled appropriately. You map will be slightly stretched at the top and slightly squashed at the bottom, but not more than a typical Mercator projection.

So let's say the map for is for 65W to 125W long (60 degrees), 25N to 50 N (25 degrees) (round numbers, sorry, clips off the Florida Keys. Lower right is 0,0. lets say this is 1000 pixels high, so 1 degree lat is 1000/25=40 pixels vertical.
By the same scale, if 40 pixels is 61 miles, 54 miles would be 35.41 pixels.
(Note 25º x 61 miles is 1525 miles). A rectangle 1 degree each side would look like on the map scale 61 miles high and 54 miles wide, so 40 pixels high and about 35.4 pixels wide in the map image.
your map would be 60º x 35.4 = 2,144 pixels wide.

A point A(aº b' c") , D (dº e' f") lat and long would be - translate to decimal - A = a + b/60 + c/3600 and B = (d+e/60+f/3600)

Translate these to pixel coordinates x,y - lower right is 0,0 pixels, 25º lat 65º long (and x is vertical, y is horizontal)
x= (A-25)*40
y=(B-65)*35.4

So the top left corner of the map is x=(50-25)*40 =1000, y=(125-65)*35.4 = 2124pixels somewhere in the middle of Vancouver Island.

Assuming I can still do math.
if you want the pixels to number left to right, I leave this as an exercise for the reader.

If you have a different goal in a map - undistorted area, or true distances - well that doesn't work well for significant chunks of a spherical surface. All maps are a compromise.

Last edited by md2000; 01-18-2020 at 09:26 PM.
#22
01-18-2020, 09:29 PM
 Member Join Date: Jul 2001 Location: Colorado Rockies. Posts: 15,295
Quote:
 Originally Posted by thelurkinghorror I mean, NYC is roughly 40.661, -73.944. LA is 34.05, -118.25.
OK then. Decimal degrees. Is this data in some sort of spread sheet or delimited text file a .csv?

Is there another value that you want to carry with the point that is created? That could be anything. Home value, Average rainfall. Whatever.

If you could cut and paste a few dozen value pairs even in a response to this, I should be able to import it to excel, delimit it and produce some locations on a map of the USA.

I could test it for you and see if it's possible with free software. It probably is.
__________________
I don't live in the middle of nowhere, but I can see it from here.
#23
01-18-2020, 11:41 PM
 Chicago Savant Join Date: Jan 2009 Location: Chicago Posts: 2,543
Using lat long pairs as x,y coordinates results in what's called the Plate-Carrée projection, though today many of us might also refer to it as unprojected data. For areas only a couple of degrees of latitude high, you can cheat by squeezing the resulting map to the cosine of the latitude. Before GIS was entirely available to my mapmaking efforts, I sometimes used this trick. For Chicago, for example, at 41º North, I'd squeeze the map to be 75% of horizontal but 100% vertical.

However, this is not a good practice for the entire continental US, which deserves to be displayed in a conic projection.
#24
01-19-2020, 06:40 AM
 Member Join Date: Mar 2005 Location: Wisconsin Posts: 10,450
Quote:
 Originally Posted by Mr Downtown Using lat long pairs as x,y coordinates results in what's called the Plate-Carrée projection.
Good point. (Plate-Carrée looks “squished” in my latitudes, to most eyes, without the sort of correction you outlined.)

But none of that matters, if the OP insists on using the original map of apparently unknown projection. If that’s the case, I don’t see how georeferencing — rubber-sheeting that map into one with known projection, then easily plotting the lat-long points into that — can be avoided.

Also...it was you, Mr. Downtown, to whom I was referring as our resident GIS expert, in an earlier post (I mistakenly wrote “Mr. Dibble”).

Last edited by JKellyMap; 01-19-2020 at 06:41 AM.
#25
01-19-2020, 11:06 PM
 Chicago Savant Join Date: Jan 2009 Location: Chicago Posts: 2,543
The map you're interested in is a conic projection, what's most familiar for maps of the continental US. It'll be a tricky matter of trial and error to get your lat-long points onto this one properly. You have to know the central meridian and two reference parallels just to start doing the complex math.

But these days there are lots of ways to map a list of points—especially if you already have the lat-longs. You can Google "alternatives to Fusion Tables" to be led to several of them. https://mapalist.com/ is one.

Or you can PM me the list and I'll throw them onto a very similar map of counties for you. If one already has the software installed, it's a pretty trivial task these days.
#26
01-20-2020, 01:12 PM
 Guest Join Date: Feb 2009 Posts: 15,651
As you see from all the replies - the main question is - what is important in this map?
Does it have to have exact (as exact as possible) area? Distances? Compass angles?
Or is it just for comparison or demonstration - "here is beer consumption by county" - so it just has to be recognizably shaped so people can identify regions.

https://en.wikipedia.org/wiki/List_of_map_projections
My suggestion to use suitably scaled lat.,long as x,y is the first projection on this list - equirectangular. One-degree lines are squares, which approximately matches reality near the equator.
The only alteration I have suggested was using 37.5 Lat as the baseline rather than the equator, and scale appropriately.
#27
01-20-2020, 02:38 PM
 Guest Join Date: May 2016 Posts: 5,123
To depict "beer consumption by county", you need a cartogram, not a projection.
#28
01-20-2020, 10:52 PM
 Member Join Date: Jul 2003 Posts: 8,785
You can start from this map of US counties (zoom in to the US), and search for the long/lats in the search bar. Each one you find can be added to the Map Notes, and when you zoom out you should be able to see all of them.

If you just want to plot coordinates onto a county map of the US, it's easiest to just let someone else take care of the projection for you. Why bother doing the math yourself?

Last edited by Reply; 01-20-2020 at 10:53 PM.
#29
01-22-2020, 07:59 AM
 Member Join Date: Mar 2005 Location: Wisconsin Posts: 10,450
Right. When the OP started by saying they wanted to use “this map,” did they really mean that very map — in which case, its projection would be important, and if unknown, it would have to be he referenced/rubber-sheeted to a base map with a known projection — OR did they actually mean “I want to use the DATA that is SHOWN in this particular map?”. Probably, the latter — and most replies in this thread have dealt with that. In other words, easier to make a new map with two layers: the lat-long points, and the underlying data displayed in the original map — which the OP will have to write into a table, and join (using GIS or otherwise) to an empty polygon file (easy to acquire) with the boundaries of the units used in the data (counties? States?).

Georeferencing as I described it is normally only used when the original map truly is the important document, typically Some old, historic paper map.
#30
01-22-2020, 09:43 AM
 Guest Join Date: Feb 2009 Posts: 15,651
Quote:
 Originally Posted by DPRK To depict "beer consumption by county", you need a cartogram, not a projection.
Depend whether you are emphazing quantity or geographic location.

We've seen this with, for example, voter maps. Who won which district (by color) gives a somewhat distorted picture because one metro area is a small blip which contains as many votes as several central states.

 Bookmarks

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Main     About This Message Board     Comments on Cecil's Columns/Staff Reports     The Quarantine Zone     General Questions     Great Debates     Politics & Elections     Cafe Society     The Game Room     Thread Games     In My Humble Opinion (IMHO)     Mundane Pointless Stuff I Must Share (MPSIMS)     Marketplace     The BBQ Pit

All times are GMT -5. The time now is 04:44 AM.

 -- Straight Dope v3.7.3 -- Sultantheme's Responsive vB3-blue Contact Us - Straight Dope Homepage - Archive - Top

Send questions for Cecil Adams to: cecil@straightdope.com