![]() |
ENG/RUS Main :: RiSearch :: RiSearch Pro :: RiCoord :: RiMap :: RiSearch PHP :: RiLax :: Forum |
![]() |
RiCoordThis document describes general functionality of RiCoord library. RiCoord is a simple geocoding tool for your website. It consists of database of USA addresses with corresponding geographical coordinates. It can be used to find location of any given address or to calculate distance between two addresses. The database is based on Census TIGER/Line files. Full database for addresses geocoding takes about 500 Mb and consists of 30000000 street block coordinates. Streets intersections data takes about 400 Mb. InstallationRiCoord is standart Perl script and installation procedure is similar to any other Perl script installation:
Database for each state is stored in separate file, therefore it is possible to upload on server only database for required state and locations in other states will be calculated using ZIP code average coordinates. Compact databases for selected counties or sities can be created for registered customers. Please note, that database does not hold coordinates of individual buildings, it is based on street blocks coordinates. Therefore you will get the same coordinates for all buildings within the same street block. If script can't find given address in database, it tries to return closest possible location (usually coordinates of nearest block). In case script can't recognise street name, approximate coordinates based on ZIP-code will be returned.
Address matching is complex task with several sources of errors.
User may not know exact address, for example he may ask "500 Main St",
while exact address is "500 Main Ave", or "500 Main St NW" instead of
"500 Main St NE". Another source of errors is ZIP code. TIGER database
is updated every year, but ZIP codes are changed constantly.
There is allways possibility that ZIP code in database is incorrect.
Script will try to find approximate matches to some extent,
returning error code and list of possible matches.
Datafiles:
RiCoord module interfaceRiCoord module (file "ricoord.pm" for Perl and "ricoord.php" for PHP) consists of several functions: get_coord($addr,$zip,$state,$city) - main function. Takes four parameters:
Function returns array of hashes (in most cases array will have only one element). Hash will have such keys:
Code takes next values:
Usage: my @res = get_coord($addr,$zip,$state,$city); my $code = $res[0]->{code}; my $long = $res[0]->{long}; my $lat = $res[0]->{lat};or (for PHP version) $res = get_coord($addr,$zip,$state,$town); $code = $res[0]['code']; $long = $res[0]['long']; $lat = $res[0]['lat']; Usually you need to specify address, ZIP code and state, to get correct coordinates. However, if ZIP code is not entered, script will use city name to get list of all ZIP codes for this city and search every ZIP code. get_coord_interpolated($addr,$zip,$state,$city) - this function is similar to get_coord, it has the same input and output parameters. Datafiles for this function are stored in directory "data_hash3" and contain full geometry for every street segment, therefore they take more hard disk space then data in "data_hash" directory, where only middle point for every segment is stored. This function returns address coordinates spread along street according to house number and possible address range for this segment and shifted to some amount to the left or right side of the street. If this function does not return succesful result, get_coord can be called to get approximate coordinates. Data in "data_hash3" directory is used only by get_coord_interpolated function and can be deleted if you don't need interpolated coordinates. parse_address($addr) - parses address as required for usage with "get_coord" function, converts everithing to lower case, replaces "Street" to "st", "Avenue" to "ave" etc. Function returns two scalars: house number and street name. Usage:
my ($num, $street) = parse_address($addr);
calc_dist($long1,$lat1,$long2,$lat2) - calculates distance between two points. Returns distance in kilometers (multiply by 0.6214 to get miles). Usage: my $dist = calc_dist($long1,$lat1,$long2,$lat2); decimal2degrees($num) - converts coordinates from decimal format (used by module) into degrees. This can be usefull for output. Usage: my ($deg, $min, $sec) = decimal2degrees($num); my ($code, $state) = get_state_by_zip($zip) - returns state for given ZIP code. my ($code, $city) = get_city_by_zip($zip) - returns city name for given ZIP code. PHP version of RiCoord is practically identical to Perl version. You can place files "find.php", "ricoord.php" and "template.htm" in any directory, but don't forget to set variable "$data_dir" in "ricoord.php" to directory with datafiles. IntersectionsRiCoord is able to find coordinates of intersection of two streets. In order to find intersection you need to write names of streets divided by ampersand in address field (like "Street1 & Street2") and provide ZIP code or city name and state code. This function uses separate set of datafiles located in directory "data_hash2". |
![]() |
|
http://risearch.org | S.Tarasov, © 2000-2005 |
![]() |