Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What algorithm is used for Reverse Geocoding using Geonames.org downloads?

I would use the API Geonames, but my application won't have access to the internet. So it has to run stand-alone. I see there are many files from Geonames.org to download, but I don't see any software to aid in being able to do Reverse Geocoding. I want to provide the lat/lon and have it return the country code. I'm thinking of downloading the data and put it into a MySQL database.

What algorithm is used for Reverse Geocoding so I can make use of it with the geonames.org downloads. My project is being written in PHP. Thanks!

like image 396
Edward Avatar asked Mar 12 '26 18:03

Edward


2 Answers

Geonames provides data for most countries. This data can be imported into a MySQL database. This can be searched for using lat lng.

The problem is that there is probably too much data in the files for your requirements. You can eliminate all the fields except lat,lng&country code for all the countries required and then combine them in 1 record.

MySQL query

SELECT country code FROM XX WHERE lat BETWEEN 55 AND 55.5 AND lng BETWEEN -2
AND -1.5

This will pull in data over a "Box" of 111kM. You can change the range to suit.

From the table below you can see that the 111kM "box" is only valid at the equator(0°). for other latitudes the lng range would need to be increased.

    lat                 lng
0°  110.574 km  111.320 km
15° 110.649 km  107.551 km
30° 110.852 km  96.486 km
45° 111.132 km  78.847 km
60° 111.412 km  55.800 km
75° 111.618 km  28.902 km
90° 111.694 km  0.000 km
like image 88
david strachan Avatar answered Mar 15 '26 07:03

david strachan


geonames downloads has mainly in .txt files, these can be imported via SQLYog to the mysql database

Table Structure

CREATE DATABASE geonames;
USE geonames;

CREATE TABLE geoname (
geonameid int PRIMARY KEY,
name varchar(200),
asciiname varchar(200),
alternatenames varchar(4000),
latitude decimal(10,7),
longitude decimal(10,7),
fclass char(1),
fcode varchar(10),
country varchar(2),
cc2 varchar(60),
admin1 varchar(20),
admin2 varchar(80),
admin3 varchar(20),
admin4 varchar(20),
population int,
elevation int,
gtopo30 int,
timezone varchar(40),
moddate date
) CHARACTER SET utf8; 

MYsql query to import data to this table

LOAD DATA INFILE '/path/to/your/file/geoname.txt' INTO TABLE `geoname`;

After all is set you can query this table against lat/long to get country name

Here is the link you can refer to

http://sgowtham.net/blog/2009/07/29/importing-geonames-org-data-into-mysql/

http://forum.geonames.org/gforum/posts/list/732.page

Hope this helps!

like image 38
WatsMyName Avatar answered Mar 15 '26 08:03

WatsMyName



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!