Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   General Forum (http://www.chiefdelphi.com/forums/forumdisplay.php?f=16)
-   -   FIRST Team Map (http://www.chiefdelphi.com/forums/showthread.php?t=38437)

Timothy D. Ginn 01-06-2005 22:36

FIRST Team Map
 
Well, I was curious, and wanted to see what it would be like to plot the locations of FIRST teams on a map; so, this is the result:



Clicking on the image will take you to a much larger version (it's 1.7 MB and 2048x1024 pixels-- or in other words, not at all friendly for dial-up)

For those interested in some of the technical details:

The data for the map was taken from TIMS via the database available at http://www.team358.org/files/team_lookup/public/ and the image is hosted by the openFIRST project; the background image is in the public domain and can be found at numerous places on the Internet. Some of the teams didn't have enough information to lookup their geographical coordinates, so they haven't been shown.

EricH 01-06-2005 22:43

Re: FIRST Team Map
 
Could you find the coordinates for Brazilian teams, Israeli teams, and the one Mexican team?

Timothy D. Ginn 01-06-2005 22:48

Re: FIRST Team Map
 
Quote:

Originally Posted by EricH
Could you find the coordinates for Brazilian teams, Israeli teams, and the one Mexican team?

At least one of the Brazilian teams is on there. I don't think the Israeli teams managed to resolve and it looks like the Mexican team is there. I may be able to tweak the Israeli results to perhaps get them to show up.

Daniel Brim 01-06-2005 22:50

Re: FIRST Team Map
 
The dot in South America looks like it is in Ecuador or Peru rather than in Brazil. It is far west of where Brazil actually is.

EricH 01-06-2005 22:52

Re: FIRST Team Map
 
Quote:

Originally Posted by DanielBCR
The dot in South America looks like it is in Ecuador rather than in Brazil. It is far west of where Brazil actually is.

You're right, but Ecuador has one team (I think). There was a brown spot in Brazil, but I don't think it's supposed to be a team.

Timothy D. Ginn 01-06-2005 22:53

Re: FIRST Team Map
 
Quote:

Originally Posted by DanielBCR
The dot in South America looks like it is in Ecuador or Peru rather than in Brazil. It is far west of where Brazil actually is.

According to TIMS; there is a team in Ecuador; so yeah, it looks like I misidentified that dot.

Elgin Clock 01-06-2005 23:00

Re: FIRST Team Map
 
Coming soon to an Earth near you; an Australian team (or 2). Stay tuned.

spears312 01-06-2005 23:05

Re: FIRST Team Map
 
cool map. Really gives you an idea on the density of first teams in certain areas on a global scale. I never really realized how many teams there are in the north eastern part of the country. Looks like you could almost go from Maine to Atlanta without leaving the red dots (what does one of those dots equal, somewhere between a 25 and 50 mile radius?)

Timothy D. Ginn 01-06-2005 23:33

Re: FIRST Team Map
 
Quote:

Originally Posted by spears312
cool map. Really gives you an idea on the density of first teams in certain areas on a global scale. I never really realized how many teams there are in the north eastern part of the country. Looks like you could almost go from Maine to Atlanta without leaving the red dots (what does one of those dots equal, somewhere between a 25 and 50 mile radius?)

I think the dots are somewhere closer to the 300 kilometer or 200 mile cube range; but I'm not entirely sure whether I did the conversions right on that (I'm pretty new to the whole GIS thing). That's on the big map. On the small map, I believe they would be a bit bigger than that.

Edit: Just a note; that's width/height of cube (or diameter if you're treating it as a circle); not radius

Mike AA 17-06-2005 00:44

Re: FIRST Team Map
 
I was trying to access the file of the picture to look at it and it was coming down very slowly. something like .2 Kbps. Does openFIRST do something during the night that makes it slow down? I am accessing the file at 12:43am EST. The website opens correctly. But not the large file.

Just a bug I guess?

-Mike

Timothy D. Ginn 17-06-2005 07:44

Re: FIRST Team Map
 
Quote:

Originally Posted by Mike AA
I was trying to access the file of the picture to look at it and it was coming down very slowly. something like .2 Kbps. Does openFIRST do something during the night that makes it slow down? I am accessing the file at 12:43am EST. The website opens correctly. But not the large file.

Just a bug I guess?

-Mike

Actually; we don't do anything in the night on that server which would slow things down (there's automated things running on other servers, though). What it probably is, is Source Forge implementing restrictions on serving large files from the project web servers. They've been saying they'd do it for a while, but I hadn't noticed any effect before now. So, I've copied it up to the update server and http://update.openfirst.org/firstteams-map.png is where it can sit now (and I'll setup a redirect from the old location to there). Thanks for pointing that out, though; it probably would have been quite some time before I noticed.

Bcahn836 17-06-2005 08:55

Re: FIRST Team Map
 
I could be mistaken but weren't there suposed to be a few teams from china next year as well?

Timothy D. Ginn 17-06-2005 10:17

Re: FIRST Team Map
 
Quote:

Originally Posted by Bcahn836
I could be mistaken but weren't there suposed to be a few teams from china next year as well?

You may be right; I'm not sure, but they weren't in the listing of teams the last time it was built from the TIMS pages. So, I guess they hadn't registered at that point.

Mike AA 18-06-2005 02:15

Re: FIRST Team Map
 
Quote:

Originally Posted by Timothy D. Ginn
Actually; we don't do anything in the night on that server which would slow things down (there's automated things running on other servers, though). What it probably is, is Source Forge implementing restrictions on serving large files from the project web servers. They've been saying they'd do it for a while, but I hadn't noticed any effect before now. So, I've copied it up to the update server and http://update.openfirst.org/firstteams-map.png is where it can sit now (and I'll setup a redirect from the old location to there). Thanks for pointing that out, though; it probably would have been quite some time before I noticed.

Hey, it works now, cool now I get to see it :) Thanks

-Mike

DarkJedi613 18-06-2005 13:26

Re: FIRST Team Map
 
Quote:

Originally Posted by Timothy D. Ginn
The data for the map was taken from TIMS via the database available at http://www.team358.org/files/team_lookup/public/ and the image is hosted by the openFIRST project; the background image is in the public domain and can be found at numerous places on the Internet. Some of the teams didn't have enough information to lookup their geographical coordinates, so they haven't been shown.

How'd you actually overlay the dots onto the map and get the coords to do it? I was thinking about doing this last week but didn't have a chance (finals...). I was thinking about using Googles APIs (though acutally I was thinking more of one of just displaying dots but being able to view by state/country/region/etc)...so how'd you resolve into coords and then overlay those onto a map?

Also - I'm glad someone is using all the information I pulled off the TIMS system. :)

Great job! :)

Timothy D. Ginn 18-06-2005 13:49

Re: FIRST Team Map
 
Quote:

Originally Posted by DarkJedi613
How'd you actually overlay the dots onto the map and get the coords to do it? I was thinking about doing this last week but didn't have a chance (finals...). I was thinking about using Googles APIs (though acutally I was thinking more of one of just displaying dots but being able to view by state/country/region/etc)...so how'd you resolve into coords and then overlay those onto a map?

Also - I'm glad someone is using all the information I pulled off the TIMS system. :)

Great job! :)

I overlayed the dots onto the map using PHP with the GD extension. Getting the geographical coordinates I did by writing a bit of an interface to http://www.multimap.com to use it to resolve them (which would be much easier than doing it through Google, as Google doesn't have APIs for their Maps service as far as I know, and Multimap is quite simple to parse through, I can give more specific details if desired). Once you have the geographical coordinates, it's possible to convert them into pixel coordinates (some detailed instructions are at: http://www.web-max.ca/PHP/ ).

There's also a related thread from a while ago at http://www.chiefdelphi.com/forums/sh...ad.php?t=29199 which does things a different way using Perl rather than PHP and geoinfo files rather than a satellite map (it's US-only as is, though; but you could mix and match ideas from both, if you wanted). If you were to want to do things that way rather than with a satellite map the PEAR Image_GIS package might come in handy: see http://pear.php.net/package/Image_GIS for details.

It's entirely possible to go beyond what either of us have done, though. I think it might be cool to do something like: http://physos.net/~physos/worldwide/test.html (mouse over the points on the map). If you're planning to do that, though; I'd strongly suggest caching the generated map image (since it can take a while). Also, if you're going to make one of these, cache the coordinates for teams, etc. from Multimap (or whatever other one you use); otherwise you're going to end up being way too harsh on the server.

DarkJedi613 18-06-2005 16:53

Re: FIRST Team Map
 
Wow...thanks a lot...

Maybe in the next version of Team Lookup I'll have it generate coordinates and just put it in the file w/ them. :D

I hadn't really looked into Google APIs too much, though I think there is an API for their Map service now...but yeah the way you're saying would be easier.

To get the coordinates did you just feed it into the search engine from multimap then load the entire page as a string using php and search for the x-coord and y-coord or do they have a built in thing to find coordinates?

You just gave me something to play with now! Thanks. :)

The image in this thread is created w/ PHP but they you saved it, correct? As in it doesn't regenerate everytime...

Thanks a lot.

Timothy D. Ginn 18-06-2005 17:45

Re: FIRST Team Map
 
Quote:

Originally Posted by DarkJedi613
Wow...thanks a lot...

Maybe in the next version of Team Lookup I'll have it generate coordinates and just put it in the file w/ them. :D

I hadn't really looked into Google APIs too much, though I think there is an API for their Map service now...but yeah the way you're saying would be easier.

To get the coordinates did you just feed it into the search engine from multimap then load the entire page as a string using php and search for the x-coord and y-coord or do they have a built in thing to find coordinates?

You just gave me something to play with now! Thanks. :)

The image in this thread is created w/ PHP but they you saved it, correct? As in it doesn't regenerate everytime...

Thanks a lot.

I checked the Google API documentation just now and didn't see any mention of an API for Maps. Oh, and yes, I did save the images that I created with PHP; they're not regenerating every time :-)

As for how I did things

For Multimap I wrote (in PHP):

PHP Code:

/*
     *  Returns the geographic coordinates of a particular street address
     *         Return value:
     *         Array(
     *             "lon" = longitude coordinate (decimal #)
     *             "lat" = latitude coordinate (decimal #)
     *             )
     * 
     *     Defaults to no street address, city of Kingston, province of Ontario, country of Canada
     */
    
function getCoordinates($streetaddr ""$city "Kingston"$province "ON"$country "CA") {        
        
// define variable to be used to store coordinate results.
        
$result = array();        

        
// Multimap requires things be trimmed and urlencoded to best match.
        
$streetaddr urlencode(trim($streetaddr));
        
$city urlencode(trim($city));
        
$province urlencode(trim($province));
        
$country urlencode(trim($country));

        
// Try checking database to see if we've already looked this address up
        // (if we have, read it from the database, otherwise query Multimap).
        
$q mysql_query("SELECT longitude, latitude FROM geoLocations WHERE streetAddress='$streetaddr' AND city='$city' AND province='$province' AND country='$country' LIMIT 1;");

        if(
mysql_num_rows($q) == 0) {
            
// Free up the result (to save memory).
            
mysql_free_result($q);
            
            
// Connect to Multimap to retrieve coordinate information
            
$ch curl_init();
            
curl_setopt($chCURLOPT_URL,"http://www.multimap.com/map/places.cgi?client=public&lang=&advanced=&db=" $country "&cname=Great+Britain&overviewmap=&addr2=" $streetaddr "&addr3=" $city "&state=" $province "&pc=");
            
curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
$tmp curl_exec($ch);
            
curl_close($ch);
    
            
// Expand the string into an array so that we can extract longitude and latitude
            
$res explode("&"$tmp);
    
            
// Prepare result to return
            
$result = array("lon" => 0"lat" => 0);
            
$result["lon"] = str_replace("lon="""$res[3]); // longtidude
            
$result["lat"] = str_replace("lat="""$res[4]); // latitude    

            // Enter the coordinates into the database (to save having to query Multimap for them again, later)
            
$q mysql_query("INSERT INTO geoLocations (streetAddress, city, province, country, longitude, latitude) VALUES ('$streetaddr', '$city', '$province', '$country', '" $result["lon"] . "', '" $result["lat"] . "');");        
        } else {
            
// The position is in our database already, so we can look it up from there
            
$res mysql_fetch_object($q);
            
            
// Prepare result to return
            
$result = array("lon" => 0"lat" => 0);
            
$result["lon"] = $res->longitude// longtidude
            
$result["lat"] = $res->latitude// latitude
            
            // Free up the result (to save memory)
            
mysql_free_result($q);
        }
        
// Return result
        
return($result);    
    } 

This caches the results in the database structure:

Code:

CREATE TABLE `geoLocations` (
 `streetAddress` varchar(255) NOT NULL default '',
 `city` varchar(255) NOT NULL default 'Kingston',
 `province` char(2) NOT NULL default 'ON',
 `country` char(2) NOT NULL default 'CA',
 `latitude` decimal(10,4) NOT NULL default '0.0000',
 `longitude` decimal(10,4) NOT NULL default '0.0000'
) TYPE=MyISAM COMMENT='Stores geographical information about addresses'

You may also be interested in this (which in my implementation I put in a class called GeoLocate with the above function)...

Note: The reason it's not a simple typical equation to find distance (eg. ) is mainly that the Earth is (roughly) spherical. For those who care, it's not precisely spherical and therefore the below function is an approximation, but, it seems to me to be more than good enough for all of my purposes:

PHP Code:

/*
     * Returns the distance (in kilometers) between two geographical coordinates
     * 
     * Coordinates are given in the form:
     *         Array(
     *             "lon" = longitude coordinate (decimal #)
     *             "lat" = latitude coordinate (decimal #)
     *         )
     * 
     */
    
function getDistance($position1$position2) {

        
// See: http://jan.ucc.nau.edu/~cvm/latlon_formula.html for an explanation of this formula

        // The formula requires that everything be in radians.  Assumption: The standard coordinates are always in degrees.
        
$a1 deg2rad($position1["lat"]); 
        
$b1 deg2rad($position1["lon"]);
        
$a2 deg2rad($position2["lat"]);
        
$b2 deg2rad($position2["lon"]);
        
        
$r 6371.01// Radius of the Earth (in kilometers)
                     // From: http://ssd.jpl.nasa.gov/phys_props_earth.html

        // Return the distance between the two given points (in kilometers)
        
return acos(cos($a1)*cos($b1)*cos($a2)*cos($b2) + cos($a1)*sin($b1)*cos($a2)*sin($b2) + sin($a1)*sin($a2)) * $r;
    } 

If anyone else wants to use these; that's fine by me, but I'd very much like to hear what you use it for :-) Oh, and if you're going to create derivative works, etc. I'd like a bit of credit. After all, it's fun to play around with things; but it's definitely nice to be acknowledged for producing things that other people find helpful.

Anyway, that should be more than enough to tinker with; have fun :-)

Timothy D. Ginn 29-06-2005 19:27

Re: FIRST Team Map
 
Quote:

Originally Posted by Timothy D. Ginn
I checked the Google API documentation just now and didn't see any mention of an API for Maps. Oh, and yes, I did save the images that I created with PHP; they're not regenerating every time :-)

...

Well, as it turns out earlier today Google released a Maps API:

More information is at:
http://www.betanews.com/article/Goog...ers/1120070538

The Google Maps API itself is documented at:

http://www.google.com/apis/maps/

It's definitely something I'm going to be looking at myself, soon.


All times are GMT -5. The time now is 19:11.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi