Question

Convert Latitude/Longitude values to x,y on a map

Asked by: jloring

Hi, desperate for some help.
I need to place red dots on a map of the United States. The dots represent the locations of several companies, universities and cities on a map of the U.S. We're using Macromedia Flash to display the map and plot the dots. Obviously we can do this manually using an external file, but long story short this data is kept in a database and will change frequently and without warning.

I only have the the latitude and longitude of these universities/companies/cities. I need to convert the latitude/longitude to x,y coordinates on the map. Once I have the x,y plotting them on the map is simple.

I have a map I obtained from http://nationalatlas.gov/natlas/ so I trust it's accuracy. I know the longitude/latitude of the 4 corners of this map. I have been playing with various formulas to no avail. I'm close, but I'm not close enough.

http://www.graphiteproductions.com/mapping/flash/map.php

Much thanks.
Jennifer.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-01-16 at 17:19:51ID20853586
Tags

latitude

,

convert

,

longitude

Topic

GIS & GPS Programming

Participating Experts
6
Points
250
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Latitude and Longitude
    Greetins, I have latitude and longitude values in minutes. Does nyone have a function to convert these numbers into a more readable format ? Thanks, Robert Lancaster
  2. compare longitude & latitude
    This isn't really a VB question but I am writing the app in VB and can't seem to find the formula. I would like to take 2 different longitude/latitude coordinates and compare them to see how far apart they are. If anyone has any examples I would appreciate it.
  3. Latitude and Longitude
    Hi, I am looking to find out what is the closest point based on Latitude and Longitude. For example, lets say i have a package at Location A, and I want to find out what carrier, pickup person, can pick it up based on the closest point. I have latitude and longitude coor...
  4. Converting longitude and latitude
    I have a flat image map and a load of decimal longitude and latitude co-ordinates. What I would like is some routine that I can run using Unix (or some formula) to convert the latitude and longitude values to pixel co-ordinates so I can place little red dots on my map
  5. NAD27 to Latitude and Longitude
    I need to be able to convert NAD27 coordinates from a GIS database into Latitude and Longitude. Can anyone tell me the process? I'd rather not have to rely on an external tool or program; I'd like to know the math.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: LowfatspreadPosted on 2004-01-18 at 16:59:08ID: 10142879


1.this link  http://nationalatlas.gov/natlas/ doesn't work for me it sends me to standford.edu

2. fine this http://www.graphiteproductions.com/mapping/flash/map.php eventually shows me a map with red dots , after a very slow download,
    and i'm not going to reboot just to install a version of flash...

   what is the display attempting to do?
   as you say from the visual perspective your dots look ok (well austin) at least...

the map as it says is an equal area projection, have you taken that into account in your conversions?

what conversion formulas have you attempted to apply...

       


 

by: LowfatspreadPosted on 2004-01-18 at 17:01:23ID: 10142889

 

by: jloringPosted on 2004-01-19 at 11:00:23ID: 10148986

Sorry, the link for the National Atlas should have been:
http://nationalatlas.gov/natlas/NatlasStart.asp

 

by: jloringPosted on 2004-01-19 at 11:04:44ID: 10149033

I've seen the Mathworld site before, but I honestly don't know what to do with this stuff. I'm not a mathematician, I'm a Web developer and artist - so the trigonometry is beyond my capacity. I simply want to find a formula that let's me convert lat/long to x,y on a map of the United States. The size of the map is fixed (600x400) and the lat/long at the corners of the map are known. Given that info I should be able to devise a solution to this problem, it's just a question of coordiate translation and adjusting for curvature of the Earth, right?

 

by: LowfatspreadPosted on 2004-01-20 at 00:56:07ID: 10153433

here's Visual basic procedure to do it....

you need to specify the  maps origin latitiude and longitude (in radians)  

i got the standard parallels from the map example you have on the site...


hth


Private Sub CalcXY(Lat As Double, Lon As Double, x As Double, y As Double)
' lat you latitude you want
' lng the longitude you want
'
'note pass the lat & lon as radians
'
' radians = degrees * PI / 180
'

Dim mpi as double ' sorry can't remember how to specify pi in vb...
mpi=3.14519


' maplat map origin latitude
' maplon map origin longitude

Dim MapLon As Double
Dim Maplat As Double
' you said you know these ...
maplon = ????? * (MPI / 180)
maplat = ????? * (MPI / 180)


'sp1 standard parallel 1  in your map 28 30' N
'sp2 standard parallel 2  in your map 45  30' N
Dim sp1 As Double
Dim sp2 As Double

' set standard parallels converting degrees to radians
sp1 = 28.5 * (MPI / 180)
sp2 = 45.5 * (MPI / 180)


' Internal calculations
Dim N As Double
Dim C As Double
Dim p0 As Double
Dim O As Double
Dim p As Double

N = 0.5 * (Sin(sp1) + Sin(sp2))
C = (Cos(sp1) * Cos(sp1)) + 2 * N * Sin(sp1)
p0 = Sqr(C - 2 * N * Sin(Maplat)) / N
O = N * (Lon - MapLon)
p = Sqr(C - 2 * N * Sin(Lat))


x = p * Sin(Lat)
y = p0 - p * Cos(Lat)

End Sub

 

by: LowfatspreadPosted on 2004-01-20 at 01:04:24ID: 10153484

sorry this

Private Sub CalcXY(Lat As Double, Lon As Double, x As Double, y As Double)
' lat you latitude you want
' lng the longitude you want
'
'note pass the lat & lon as radians
'
' radians = degrees * PI / 180
'

' maplat map origin latitude
' maplon map origin longitude

Dim MapLon As Double
Dim Maplat As Double
' you said you know these ...

'sp1 standard parallel 1  in your map 28 30' N
'sp2 standard parallel 2  in your map 45  30' N
Dim sp1 As Double
Dim sp2 As Double

Dim mpi as double ' sorry can't remember how to specify pi in vb...
mpi=3.14519

' set standard parallels converting degrees to radians
sp1 = 28.5 * (MPI / 180)
sp2 = 45.5 * (MPI / 180)


' Internal calculations
Dim N As Double
Dim C As Double
Dim p0 As Double
Dim O As Double
Dim p As Double

N = 0.5 * (Sin(sp1) + Sin(sp2))
C = (Cos(sp1) * Cos(sp1)) + 2 * N * Sin(sp1)
p0 = Sqr(C - 2 * N * Sin(Maplat)) / N
O = N * (Lon - MapLon)
p = Sqr(C - 2 * N * Sin(lat))


x = p * Sin(o)
y = p0 - p * Cos(o)

End Sub

 

by: LowfatspreadPosted on 2004-01-20 at 10:06:47ID: 10156902

use this for PI

pi=4*atn(1)

 

by: jloringPosted on 2004-01-28 at 08:16:11ID: 10219239

Hey Lowfatspread,
Your answer is a bit over my head, but it's clearly thought out and developed. I see the core formula in there, which I'll work on in converting to PHP.
Much thanks.
Jennifer.

 

by: jloringPosted on 2004-02-08 at 15:10:39ID: 10305574

Hey everyone,
I've finally got this working using a very simple set of formulas (in PHP). The biggest battle is getting an accurate Mercator map and knowing your map's endpoints. Here's the map solution we used (you can save the output as an Adobe Illustrator file):
http://www.aquarius.geomar.de/omc/make_map.html

I created a map using the above tool with the following endpoints: N: 53, E: -66.54, S: 23, W: -125.49
This creates a nice Continental US & partial Canadian map. Remember to check the "download" box if you want to save the output as a Illustrator file!

I imported the map into Macromedia Flash MX. The map is 600 x 396 (pixels). Here's the working model on my Web site:
http://www.graphiteproductions.com/mapping/flash/map.php

Flash reads a flat text file containing the following result sets (as example):
totDots=10
&nam1=SF State
&loc1=San Francisco, CA
&posx1=33.18
&posy1=226.97
&link1=http://www.sfsu.edu/

&nam2=Wayne State
&loc2=Detroit, MI
&posx2=432.46
&posy2=162.752
&link2=http://www.wayne.edu

&nam3=University of Texas
&loc3=Austin, TX
&posx3=282.34
&posy3=314.289
&link3=http://www.utexas.edu/
...

You get the idea. You could use PHP to obtain this from a database dynamically rather than use a flat text file, if you choose.
Generating the x,y values from long/lat is, of course, the real trick.

Here's how I derived the y coord:
function findYcoord($myLat) {
      $mapHeight = 396;
      $rfactor = 290;
      $radBtm = deg2rad(23);
      $radPixel = deg2rad($myLat);
      $sinRadBtm = sin($radBtm);
      $sinRadPixel = sin($radPixel);
      $convHtBtm = $rfactor * log((1 + $sinRadPixel)/(1 - $sinRadPixel));
      $convHtPixel = $rfactor * log((1 + $sinRadBtm)/(1 - $sinRadBtm));
      $myTotHt = abs($convHtPixel - $convHtBtm);
      $myYcoord = round($mapHeight - $myTotHt, 3);
      return $myYcoord;
}

NOTES:
You simply pass in the latitude value, which is later converted to a radian.
$mapHeight is the height, in pixels, of my map in Flash.
$rfactor is a constant variable. It corresponds to your map scale. You might have to tweak this value up or down a bit (but it worked for me at 290).
$radBtm = deg2rad(23); the value "23" is the latitude at the bottom of my map.

Getting the x value is much, much easier:
$x =round(((125.49 - $lon)*10.178), 2);

NOTES:
125.59 is the longitude at the top left corner of my map.
$lon is the longitude for the city I want to plot
10.178 is a constant that is based on the width of the map, it's calculated as follows:
longitude West - longitude East / width of map
125.49 - 66.54 = 58.95
600 / 58.95 = 10.178
Let me put it another way: every 10.178 pixels on your map equals one degree of longitude.

Here's how I plotted Detroit:
Detroit, MI<br>
Longitude: 83<br>
Latitude: 42.24<br>
<?php
$lon = 83;
$lat = 42.24;
$x =round(((125.49 - $lon)*10.178), 2);
print "x: ".$x."<br>";
print "y: ".findYcoord($lat);      
?>

Works like a champ, I swear by the results and it's far less complicated or confusing than any other solution I've seen thus far.
Thanks again to everyone.
David and Jennifer.

 

by: ark4877Posted on 2004-05-17 at 00:20:05ID: 11087388

Hi Jennifer,
               Please try this link.i hope this will solve ur problem.
http://www.dmap.co.uk/ll2tm.htm
Ark

 

by: darynsmudgePosted on 2004-05-17 at 09:55:38ID: 11090699

Jennifer,

Just curious...how did you calculate the rfactor?

daryn

 

by: jloringPosted on 2004-05-17 at 10:01:06ID: 11090741

Good question.
rfactor is an arbitrary value, I just make it up. Trial and error reveals the best results. I know, less than empirical but who said I was perfect?
J.

 

by: ftriantosPosted on 2004-06-02 at 06:19:40ID: 11211983

jloring

Thanks so much for the help. I was researching this exact implementation. If you figure out the rfactor calculation let me know. If I can figure it out I will post.

F

 

by: SixGunZPosted on 2004-06-22 at 09:09:14ID: 11370737

Has anyone figured out the rfactor constant yet?

I've been trying to for a while now - I have implemented this formulae into ASP to project map points from a GPS receiver.

Because I'm using different maps, and switching between them, I the formulae to work out the rfactor, rather than implementing it manually.

Things I've learned about the rfactor:

1.  It is based on the height of your graphic - if your graphic height changes, regardless of the lat/long boundaries, the figure will change.

2.  It is latitude dependant - the larger scale the map is (ie higher difference between top lat and bottom lat) the smaller the number becomes.  Know this as I have a region of the south of the UK and am using an rfactor of 49500 rather than an rfactor of 200 for the whole of the USA!

3.  Possibly latitude location dependant - the figure could be determined by the position of the top and bottom lats based on the vector, ie figure could change based on being closer or further from the equator (0deg lat, no distortion)

I welcome your comments please - jloring, and anyone else who has experience with this, if you are reading this and have a conclusion to this story, please let me know.

Thanks in advance,

Glenn

 

by: ftriantosPosted on 2004-06-22 at 09:17:56ID: 11370863

THIS IS WHAT WORKED FOR ME. I IGNORED THE R FACTOR, AND MADE THE MAP VS. PIXEL CONVERSION DYNAMIC. IT IS COMMENTED FOR YOUR CONVINIENCE. HOPE THIS HELPS YOU ALL OUT. YOUR COMMENTS HELPED ME:
BY THE WAY, THIS IS WRITTEN IN COLDFUSION, BUT IS SIMILAR TO MOST OTHER LANGUAGES.
<!---
MAPVIEW.CFM (c)2004 Trios Associates Inc. Authored by Frank Triantos 6-17-04
this code takes in the parameters of a map in pixels and the latitude and longitude boundaries of said map
allowing a query to be generated that pulls all instances inside said boundaries
and then displays the hot linked position (sing a red-dot image) on top of the map image
which can be clicked to generate another page specific to that item...
----->
<cfscript>
      //enter the height and width of the map image in pixels
      pixel_height = 700;
      pixel_width = 1200;
      // this function converts a lat or long integer to seconds
      function toSeconds (input_a) {
            variables.input_asec = right(input_a, 2);
            variables.input_amin =  mid(input_a, (len(input_a) - 3) , 2) * 60;
            variables.input_adeg =  mid(input_a, (len(input_a) - 6) , 3) * 3600;
            output_a = (input_asec + input_amin + input_adeg);
            return output_a;
      }
      //enter the higher and lower absolute value of longitude and longitude
      long_small = 0590000;
      long_big = 1320000;
      lat_small = 0210000;
      lat_big = 0510000;
      //these values are then converted to seconds for use in setting the map
      //...vertical scale info determined (seconds per pixel)
      long_small_s = toSeconds(long_small);
      long_big_s = toSeconds(long_big);
      secs_width = (long_big_s - long_small_s);
      horizontal_scale = secs_width;
      //...horizontal scale info determined (sedonds per pixel)
      lat_small_s = toSeconds(lat_small);
      lat_big_s = toSeconds(lat_big);
      secs_height = (lat_big_s - lat_small_s);
      vertical_scale = (secs_height / pixel_height);
</cfscript>
<html>
<head>
      <title>Untitled</title>
</head>
<script language="javascript">
      //var precache = new Image(20, 20)
      //precache.src = "dot.jpg"
      function GoThere(loc){
            top.left.location.href="../parent.cfm?ConfigID="+loc;
      }
</script>
<body style="margin:0px;">
<!--------------------------------Query specific to database-------------------------------------------------->
<cfquery name="LetsEditor" datasource="#variables.ds#">
      SELECT intLatitude, intLongitude, configID
      FROM tblConfig WHERE configID IN (2141,4394,19193);
</cfquery>
<!---------------looping through the results of the query----------------------------------------------------->
<cfoutput query="LetsEditor">
<!----scripting section to generate the position of the item in relation to the map parameters---------------->
      <cfscript>
            //verifies that coordinates are in integer format and seperates (from right) seconds, minutes and degrees
            //...converting each to seconds
            //...beginning with x
            
            dd_x = int(intLongitude);
            dd_y = int(intLatitude);
            variables.dd_xsec = right(intLongitude, 2);
            variables.dd_xmin =  mid(intLongitude, (len(intLongitude) - 3) , 2) * 60;
            if (len(intLongitude) EQ 7){
                  variables.dd_xdeg =  mid(intLongitude, (len(intLongitude) - 6) , 3) * 3600;
            } else {
                  variables.dd_xdeg =  mid(intLongitude, (len(intLongitude) - 5) , 2) * 3600;
            }
            //...then for the y
            variables.dd_ysec = right(intLatitude, 2);
            variables.dd_ymin =  mid(intLatitude, (len(intLatitude) - 3) , 2) * 60;
            if (len(intLatitude) EQ 7){
                  variables.dd_ydeg =  mid(intLatitude, (len(intLatitude) - 6) , 3) * 3600;
            } else {
                  variables.dd_ydeg =  mid(intLatitude, (len(intLatitude) - 5) , 2) * 3600;
            }
            //then totaling the converted segments into one whole coordinate (in seconds)
            dd_x = (dd_xsec + dd_xmin + dd_xdeg);
            dd_y = (dd_ysec + dd_ymin + dd_ydeg);
            //pixel position on the map is
            //...for x the left-most (in seconds) coordinate minus the coordinate in question
            //...equals amount from left side multiplied by the quantity
            //...of total mapwidth (pixels) over total of seconds displayed on map
            //...(giving us pixels per second)  
            variables.rel_x = (((long_big_s - dd_x) * pixel_width) / secs_width);
            //for y we have to subtract the conversion from the higher converted value
            //...(which is the lower height on the map because these are negative)
            //...multiply the seconds per pixel conversion
            //...and subtract from the height of the picture in pixels
            variables.rel_y = (((lat_big_s - dd_y) * pixel_height) / secs_height);
      </cfscript>
      <!---------positioning the red dot image using the coordinates located above (scripting section)----------->
      <!---------includes a hot link to the page with more info and passes the id of the item via url------------>
      <div ID="dot#letseditor.configid#" style="position:absolute; left:#variables.rel_x#; Top:#variables.rel_y#;">
            <a href="##" onClick="GoThere(#LetsEditor.ConfigID#)">
                  <img src="dot.jpg" alt="#intLatitude#,#intLongitude#" width="10" height="10" border="0">
            </a>
      </div>
</cfoutput>
<!---insertion of the map image-------------------------------------------------------------------------------->
<img src="usa.gif" name="usa">
</body>
</html>
<!-----------------------------------------ENDING MAPVIEW.CFM-------------------------------------------------->

 

by: SixGunZPosted on 2004-06-22 at 14:44:06ID: 11374251

@ ftriantos:

Firstly, thank you very much for sharing your source code.  I can see the relation between difference in latbig and latsmall and pixels - a straight pixels per lat conversion.

Can we see an online demo of your work?  I would be interested in seeing this....  My ASP isnt on an internet connected server yet, as it is still in testing for accuracy - another reason for the rfactor conversion requirement.

My only comment would be how do you compensate for spherical distortion?  There is an old tutorial in PHP somewhere which uses a world map, with a spheriacally distorted map, so straight x/y to lat/lon conversions are okay, but I'm using a vector of the world, and a map that has been spherically distorted.  jlorings formulae works for me - just this dammed rfactor to decipher!!!

Lowfatspreads answer just killed my brain!!  I can see the workings, just cant put it together - lowfatspread, if you are listening, can you be more specific on the values that need to be passed (ie are the standard parallels the top lat and bottom lat?  The origin lat and lon? is that the top left lat and lon? If so, why do you need the standard parallels in there? How is x converted from just an origin lat and lon?)  I'm sure this is probably very annoying for you, but my maths is extremely weak - I do try and understand, but your understanding outweighs mine tenfold....humble, humble...........

I have found some more info, looking into the trig calcs (although I'm definitely no mathematician!)

1.  rfactor for USA is 290 for USA.
2.  I'm using 49500 for UK
3.  Both are in Northern Hemisphere (above equator - 0 deg lat)
4.  rfactor is higher for a more magnified area with lower distance
5.  rfactor is used in only two areas of conversion - on convHtBtm and convHtPixel

I will try and convert your CFM into ASP and give it a go anyways - it's obviously working well for you and good job on the coding - nice to see comments showing whats going on, takes the pain out of deciphering code!!  Also going back to the drawing board on the rfactor - gonna transopse the formulae and see what happens.......  keep you and all else watching this space posted!!

 

by: darynsmudgePosted on 2004-06-23 at 07:08:35ID: 11379371

All,

I have been trying to design a Flash Application that geo-references a vector graphic to enable accurate plotting of "sites of interest".  I have a working proof of concept that seems to be extremely accurate.  Sorry that it is so Flash specific but the general concept of how to do it should work for most circumstances.  I used ColdFusion to query the data base and run the calculations.  If anyone is interested, I can post the CF as well.  Here is a general description of what I did:

First you will need to import the map(vector) graphic you will be using.

Make sure that the graphic fully covers the stage.  (You may have to adjust the size of the stage and or the deminsions of the graphic to accomplish this.)

Select the lat/long intersection that will serve as your max values.  (i.e. for my map I selected 180W and 75N.

Adjust your graphic to be at 0,0 X,Y on the Flash stage at that max lat/long intersection.

Now the fun part:

Select the values for the following that you want your plot points to be between:
maxLong = (in my case 180)
minLong = (in my case 0)
maxLat = (in my case 75)
minLat = (in my case 0)

Measure the distance on the X-axis from 0 pixels to the furthest east longitude line you want to use in your plots.  (i.e. I wanted to plot points that fell between 180w and 0 degrees.  The distance in Flash from the 180w and 0, in pixels was 1138.3.) This gives us a width variable:

xwidth = (in my case 1138.3 px)

Now measure the distance between your upper most latitude line (in my case 75N) and the next latitude line you come to below it (in my case 60n).  You will do this for all your latitude lines.  Measure them from the previous to the next and also note the overall distance from the Y=0 point.  So in my case I have 5 blocks of latitude (from 75-60, 60-45, 45-30, 30-15, and 15-0).  The notation should look like this:

latGroupA:  (75N - 60N)
maxGroupLat = (in my case 75)
minGroupLat = (in my case 60)
yDistanceA = (in my case 256.3px)
yheightA = (in my case 256.3px)

latGroupB:  (60N - 45N)
maxGroupLat = (in my case 60)
minGroupLat = (in my case 45)
yDistanceB = (in my case 412.8px)
yheightB = (in my case 156.5px) or (latGroupB:yDistance - latGroupA:yDistance)

latGroupC:  (45N - 30N)
maxGroupLat = (in my case 45)
minGroupLat = (in my case 30)
yDistanceC = (in my case 532.1px)
yheightC = (in my case 119.3px)

latGroupD:  (30N - 15N)
maxGroupLat = (in my case 30)
minGroupLat = (in my case 15)
yDistanceD = (in my case 634px)
yheightD = (in my case 101.9px)

latGroupE:  (15N - 0)
maxGroupLat = (in my case 15)
minGroupLat = (in my case 0)
yDistanceE = (in my case 728.4px)
yheightE = (in my case 94.4px)

Now, you will need to figure out the pixels per degrees of both your X and Y axis.  The X-axis is fairly easy:

xwidth/(maxLong - minLong) = xFactor

in my case:  1138.3/(180 - 0) = 6.3238888 = xFactor

The Y-axis is a bit more challenging.  You have to determine a pixels per degree for each latGroup.  The equation is virtually the same:

yheight/(maxGroupLat - minGroupLat) = yFactor

So in my case:
latGroupA:
256.3/(75 - 60) = 17.086666 = yFactorA

latGroupB:
156.5/(60 - 45) = 10.433333 = yFactorB

latGroupC:
119.3/(45 - 30) = 7.9533333 = yFactorC

latGroupD:
101.9/(30 - 15) = 6.7933333 = yFactorD

latGroupE:
94.4/(15 - 0) = 6.2933333 = yFactorE

Now to find your X,Y coordiinates:
For X:
(maxLong - ABS(longToPlot)) * xFactor = xCoord

So in my case for Chicago O'Hare International Airport(41.9786, -87.9048):
(180 - ABS(-87.9048)) * 6.3238888 = 582.3998

It's a bit more complex for Y:
First look at the latitude you want to plot and figure out which latGroup it falls within.  Use that groups maxGroupLat and yFactor in the following way:
((maxGroupLat - ABS(latToPlot)) * yFactor) + previous:latGroup:yDistance = yCoord

So in my case for Chicago O'Hare International (41.9786, -87.9048):
((45 - ABS(41.9786)) * 7.9533333) + 412.8 = 436.8302

Hope this helps...

Daryn

 

 

by: ftriantosPosted on 2004-06-24 at 11:08:22ID: 11391688

back @ SixGunZ

http://public.triosinc.com/frank/

By using the mercator map that jLorings comment from 2/8 directed me to (and altering it some) I came up with a mapping procedure without the need to consider spherical distortion. That being said, it is basically only good for the continental US, and I would like to look a little more deeply at the problem. It looks like the comment posted by Daryn above might be the solution I eventually will migrate to. I posted a demo site for you to look at, using three cities that were in my database. These are the three I used to realize that it was working.

I will be continuing on this effort and will post the eventual result when I am finished. What you will see at my link is the exact code I published in the original posting above (mapview.cfm)

Frank

 

by: WattsNPosted on 2005-10-17 at 12:33:41ID: 15102346

Frank,

Any reason that you did this with seconds instead of in radians?  That should help with the sperical distortion ... I'd like to see how the code works out that way.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...